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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 9 commits intomainfrommafredri/refactor-agentssh-config
Feb 19, 2024
Merged
Changes from1 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
PrevPrevious commit
NextNext commit
fix unhandled terminal output in test
  • Loading branch information
@mafredri
mafredri committedFeb 19, 2024
commit2cbb5971129ec1f79f206ff014ae1b0f31aed087
40 changes: 33 additions & 7 deletionsagent/agent_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -303,18 +303,14 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
require.NoError(t, err)

command := "sh"
echoEnv := func(t *testing.T, w io.Writer,r io.Reader,env string) string {
echoEnv := func(t *testing.T, w io.Writer, env string) {
if runtime.GOOS == "windows" {
_, err := fmt.Fprintf(w, "echo %%%s%%\r\n", env)
require.NoError(t, err)
} else {
_, err := fmt.Fprintf(w, "echo $%s\n", env)
require.NoError(t, err)
}
scanner := bufio.NewScanner(r)
require.True(t, scanner.Scan())
t.Logf("%s=%s", env, scanner.Text())
return scanner.Text()
}
if runtime.GOOS == "windows" {
command = "cmd.exe"
Expand All@@ -328,6 +324,22 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
err = session.Start(command)
require.NoError(t, err)

ctx := testutil.Context(t, testutil.WaitLong)

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@@ -337,8 +349,22 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
"MY_SESSION": "true", // From the session.
} {
t.Run(k, func(t *testing.T) {
out := echoEnv(t, stdin, stdout, k)
require.Contains(t, strings.TrimSpace(out), partialV)
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
}
}
}
s := testutil.RequireRecvCtx(ctx, t, out)
t.Logf("%s=%s", k, s)
s = strings.TrimSpace(s)
require.Contains(t, s, partialV)
})
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp