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

Commit7bd2ed0

Browse files
committed
fix unhandled terminal output in test
1 parentd3d880b commit7bd2ed0

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

‎agent/agent_test.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,14 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
312312
require.NoError(t,err)
313313

314314
command:="sh"
315-
echoEnv:=func(t*testing.T,w io.Writer,r io.Reader,envstring)string {
315+
echoEnv:=func(t*testing.T,w io.Writer,envstring) {
316316
ifruntime.GOOS=="windows" {
317317
_,err:=fmt.Fprintf(w,"echo %%%s%%\r\n",env)
318318
require.NoError(t,err)
319319
}else {
320320
_,err:=fmt.Fprintf(w,"echo $%s\n",env)
321321
require.NoError(t,err)
322322
}
323-
scanner:=bufio.NewScanner(r)
324-
require.True(t,scanner.Scan())
325-
t.Logf("%s=%s",env,scanner.Text())
326-
returnscanner.Text()
327323
}
328324
ifruntime.GOOS=="windows" {
329325
command="cmd.exe"
@@ -337,6 +333,22 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
337333
err=session.Start(command)
338334
require.NoError(t,err)
339335

336+
ctx:=testutil.Context(t,testutil.WaitLong)
337+
338+
s:=bufio.NewScanner(stdout)
339+
out:=make(chanstring)
340+
testutil.Go(t,func() {
341+
fors.Scan() {
342+
select {
343+
caseout<-s.Text():
344+
case<-ctx.Done():
345+
return
346+
}
347+
}
348+
})
349+
350+
// Until we have gotten the first result, the shell may spit out some data.
351+
first:=true
340352
//nolint:paralleltest // These tests need to run sequentially.
341353
fork,partialV:=rangemap[string]string{
342354
"CODER":"true",// From the agent.
@@ -347,8 +359,21 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
347359
"PATH":scriptBinDir+string(filepath.ListSeparator),
348360
} {
349361
t.Run(k,func(t*testing.T) {
350-
out:=echoEnv(t,stdin,stdout,k)
351-
require.Contains(t,strings.TrimSpace(out),partialV)
362+
echoEnv(t,stdin,k)
363+
iffirst {
364+
for {
365+
s:=testutil.RequireRecvCtx(ctx,t,out)
366+
t.Logf("%s=%s",k,s)
367+
s=strings.TrimSpace(s)
368+
ifstrings.Contains(s,partialV) {
369+
first=false
370+
return
371+
}
372+
}
373+
}
374+
s:=testutil.RequireRecvCtx(ctx,t,out)
375+
t.Logf("%s=%s",k,s)
376+
require.Contains(t,s,partialV)
352377
})
353378
}
354379
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp