Skip to content

refactor(agent/agentssh): move envs to agent and add agentssh config struct #12204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
another attempt to fix window stest
  • Loading branch information
mafredri committed Feb 19, 2024
commit dd66b457d1e3bcee8d931921ac45246fabcd58c8
40 changes: 15 additions & 25 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -324,22 +325,15 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
err = session.Start(command)
require.NoError(t, err)

// Context is fine here since we're not doing a parallel subtest.
ctx := testutil.Context(t, testutil.WaitLong)
go func() {
<-ctx.Done()
_ = session.Close()
}()

s := bufio.NewScanner(stdout)
out := make(chan string)
testutil.Go(t, func() {
for s.Scan() {
select {
case out <- s.Text():
case <-ctx.Done():
return
}
}
})

// Until we have gotten the first result, the shell may spit out some data.
first := true
//nolint:paralleltest // These tests need to run sequentially.
for k, partialV := range map[string]string{
"CODER": "true", // From the agent.
Expand All @@ -350,21 +344,17 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
} {
t.Run(k, func(t *testing.T) {
echoEnv(t, stdin, k)
if first {
for {
s := testutil.RequireRecvCtx(ctx, t, out)
t.Logf("%s=%s", k, s)
s = strings.TrimSpace(s)
if strings.Contains(s, partialV) {
first = false
return
}
// Windows is unreliable, so keep scanning until we find a match.
for s.Scan() {
got := strings.TrimSpace(s.Text())
t.Logf("%s=%s", k, got)
if strings.Contains(got, partialV) {
break
}
}
s := testutil.RequireRecvCtx(ctx, t, out)
t.Logf("%s=%s", k, s)
s = strings.TrimSpace(s)
require.Contains(t, s, partialV)
if err := s.Err(); !errors.Is(err, io.EOF) {
require.NoError(t, err)
}
})
}
}
Expand Down