Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2cbb597

Browse files
committed
fix unhandled terminal output in test
1 parent112a0d0 commit2cbb597

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

‎agent/agent_test.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,14 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
303303
require.NoError(t,err)
304304

305305
command:="sh"
306-
echoEnv:=func(t*testing.T,w io.Writer,r io.Reader,envstring)string {
306+
echoEnv:=func(t*testing.T,w io.Writer,envstring) {
307307
ifruntime.GOOS=="windows" {
308308
_,err:=fmt.Fprintf(w,"echo %%%s%%\r\n",env)
309309
require.NoError(t,err)
310310
}else {
311311
_,err:=fmt.Fprintf(w,"echo $%s\n",env)
312312
require.NoError(t,err)
313313
}
314-
scanner:=bufio.NewScanner(r)
315-
require.True(t,scanner.Scan())
316-
t.Logf("%s=%s",env,scanner.Text())
317-
returnscanner.Text()
318314
}
319315
ifruntime.GOOS=="windows" {
320316
command="cmd.exe"
@@ -328,6 +324,22 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
328324
err=session.Start(command)
329325
require.NoError(t,err)
330326

327+
ctx:=testutil.Context(t,testutil.WaitLong)
328+
329+
s:=bufio.NewScanner(stdout)
330+
out:=make(chanstring)
331+
testutil.Go(t,func() {
332+
fors.Scan() {
333+
select {
334+
caseout<-s.Text():
335+
case<-ctx.Done():
336+
return
337+
}
338+
}
339+
})
340+
341+
// Until we have gotten the first result, the shell may spit out some data.
342+
first:=true
331343
//nolint:paralleltest // These tests need to run sequentially.
332344
fork,partialV:=rangemap[string]string{
333345
"CODER":"true",// From the agent.
@@ -337,8 +349,22 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
337349
"MY_SESSION":"true",// From the session.
338350
} {
339351
t.Run(k,func(t*testing.T) {
340-
out:=echoEnv(t,stdin,stdout,k)
341-
require.Contains(t,strings.TrimSpace(out),partialV)
352+
echoEnv(t,stdin,k)
353+
iffirst {
354+
for {
355+
s:=testutil.RequireRecvCtx(ctx,t,out)
356+
t.Logf("%s=%s",k,s)
357+
s=strings.TrimSpace(s)
358+
ifstrings.Contains(s,partialV) {
359+
first=false
360+
return
361+
}
362+
}
363+
}
364+
s:=testutil.RequireRecvCtx(ctx,t,out)
365+
t.Logf("%s=%s",k,s)
366+
s=strings.TrimSpace(s)
367+
require.Contains(t,s,partialV)
342368
})
343369
}
344370
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp