Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b611f5

Browse files
committed
improve error handling in TestServer/EphemeralDeployment
1 parent cc733ab commit 9b611f5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cli/server_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,16 @@ func TestServer(t *testing.T) {
201201
go func() {
202202
errCh <- inv.WithContext(ctx).Run()
203203
}()
204-
pty.ExpectMatch("Using an ephemeral deployment directory")
204+
matchCh1 := make(chan string, 1)
205+
go func() {
206+
matchCh1 <- pty.ExpectMatchContext(ctx, "Using an ephemeral deployment directory")
207+
}()
208+
select {
209+
case err := <-errCh:
210+
require.NoError(t, err)
211+
case <-matchCh1:
212+
// OK!
213+
}
205214
rootDirLine := pty.ReadLine(ctx)
206215
rootDir := strings.TrimPrefix(rootDirLine, "Using an ephemeral deployment directory")
207216
rootDir = strings.TrimSpace(rootDir)
@@ -210,7 +219,16 @@ func TestServer(t *testing.T) {
210219
require.NotEmpty(t, rootDir)
211220
require.DirExists(t, rootDir)
212221

213-
pty.ExpectMatchContext(ctx, "View the Web UI")
222+
matchCh2 := make(chan string, 1)
223+
go func() {
224+
matchCh2 <- pty.ExpectMatchContext(ctx, "View the Web UI")
225+
}()
226+
select {
227+
case err := <-errCh:
228+
require.NoError(t, err)
229+
case <-matchCh2:
230+
// OK!
231+
}
214232

215233
cancelFunc()
216234
<-errCh

0 commit comments

Comments
 (0)