@@ -153,24 +153,11 @@ func TestVMDirPrefixSeparatesSiblingNames(t *testing.T) {
153153}
154154
155155func TestReadUntilWaitsForTheFullPrompt (t * testing.T ) {
156- client , monitor := net .Pipe ()
157- go func () {
158- for _ , chunk := range []string {" set_pass" , "word vnc (qemu)\r \n " , "Error: No VNC display is present\r \n " , "(qemu) " } {
159- _ , _ = monitor .Write ([]byte (chunk ))
160- }
161- _ = monitor .Close ()
162- }()
163- out , ok := readUntil (client , hmpPrompt )
156+ out , ok := hmpTranscript (" set_pass" , "word vnc (qemu)\r \n " , "Error: No VNC display is present\r \n " , "(qemu) " )
164157 if ! ok || ! hmpReplied (out ) {
165158 t .Fatalf ("readUntil = (%q, %v), want the rejection after the echoed prompt-shaped password" , out , ok )
166159 }
167-
168- client , monitor = net .Pipe ()
169- go func () {
170- _ , _ = monitor .Write ([]byte (" set_password vnc abcd\r \n " ))
171- _ = monitor .Close ()
172- }()
173- if out , ok := readUntil (client , hmpPrompt ); ok {
160+ if out , ok := hmpTranscript (" set_password vnc abcd\r \n " ); ok {
174161 t .Errorf ("readUntil = (%q, true), want false when the monitor closes before the prompt" , out )
175162 }
176163}
@@ -190,3 +177,14 @@ func TestHMPRepliedFlagsAnyMessage(t *testing.T) {
190177 }
191178 }
192179}
180+
181+ func hmpTranscript (chunks ... string ) (string , bool ) {
182+ client , monitor := net .Pipe ()
183+ go func () {
184+ for _ , chunk := range chunks {
185+ _ , _ = monitor .Write ([]byte (chunk ))
186+ }
187+ _ = monitor .Close ()
188+ }()
189+ return readUntil (client , hmpPrompt )
190+ }
0 commit comments