Skip to content

Commit dfe1d2a

Browse files
clarify output limits and proxy test
1 parent 3d8d5a1 commit dfe1d2a

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

checks/cli.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
)
1818

1919
const (
20-
cliCommandTimeout = 5 * time.Minute
21-
maxCLIOutputBytes = 1024 * 1024
22-
commandWaitDelay = 2 * time.Second
20+
cliCommandTimeout = 5 * time.Minute
21+
maxCLIOutputBytesPerStream = 1024 * 1024
22+
commandWaitDelay = 2 * time.Second
2323
)
2424

2525
var errCLIOutputLimitExceeded = errors.New("CLI command output limit exceeded")
@@ -63,14 +63,14 @@ func (b *boundedBuffer) Truncated() bool {
6363
}
6464

6565
func runCLICommand(command api.CLIStepCLICommand, variables map[string]string) (result api.CLICommandResult) {
66-
return runCLICommandWithLimits(command, variables, cliCommandTimeout, maxCLIOutputBytes)
66+
return runCLICommandWithLimits(command, variables, cliCommandTimeout, maxCLIOutputBytesPerStream)
6767
}
6868

6969
func runCLICommandWithLimits(
7070
command api.CLIStepCLICommand,
7171
variables map[string]string,
7272
timeout time.Duration,
73-
maxOutputBytes int,
73+
maxOutputBytesPerStream int,
7474
) (result api.CLICommandResult) {
7575
finalCommand := InterpolateVariables(command.Command, variables)
7676
result.FinalCommand = finalCommand
@@ -94,8 +94,8 @@ func runCLICommandWithLimits(
9494
cancelForOutputLimit := func() {
9595
cancelCommand(errCLIOutputLimitExceeded)
9696
}
97-
stdout := newBoundedBuffer(maxOutputBytes, cancelForOutputLimit)
98-
stderr := newBoundedBuffer(maxOutputBytes, cancelForOutputLimit)
97+
stdout := newBoundedBuffer(maxOutputBytesPerStream, cancelForOutputLimit)
98+
stderr := newBoundedBuffer(maxOutputBytesPerStream, cancelForOutputLimit)
9999
cmd.Stdout = stdout
100100
cmd.Stderr = stderr
101101
err := cmd.Run()
@@ -112,7 +112,7 @@ func runCLICommandWithLimits(
112112

113113
switch {
114114
case errors.Is(context.Cause(ctx), errCLIOutputLimitExceeded):
115-
result.Err = fmt.Sprintf("command output exceeded the %d-byte limit", maxOutputBytes)
115+
result.Err = fmt.Sprintf("command output exceeded the %d-byte per-stream limit", maxOutputBytesPerStream)
116116
result.ExitCode = -2
117117
case errors.Is(context.Cause(ctx), context.DeadlineExceeded):
118118
result.Err = fmt.Sprintf("command timed out after %s", timeout)

checks/cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func TestRunCLICommandCapsOutput(t *testing.T) {
5757
)
5858
elapsed := time.Since(start)
5959

60-
if !strings.Contains(result.Err, "command output exceeded") {
61-
t.Fatalf("command error = %q, want output limit error", result.Err)
60+
if !strings.Contains(result.Err, "per-stream limit") {
61+
t.Fatalf("command error = %q, want per-stream output limit error", result.Err)
6262
}
6363
if result.ExitCode >= 0 {
6464
t.Fatalf("exit code = %d, want internal failure", result.ExitCode)

version/version_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,33 @@ import (
1111
)
1212

1313
func TestGetLatestVersionRespectsGoProxyOff(t *testing.T) {
14+
if runtime.GOOS == "windows" {
15+
t.Skip("test uses a POSIX executable script")
16+
}
17+
18+
dir := t.TempDir()
19+
fakeGo := filepath.Join(dir, "go")
20+
script := `#!/bin/sh
21+
if [ "$GOPROXY" != "off" ]; then
22+
echo "unexpected GOPROXY: $GOPROXY" >&2
23+
exit 1
24+
fi
25+
printf '{"Version":"v1.2.3"}'
26+
`
27+
if err := os.WriteFile(fakeGo, []byte(script), 0o755); err != nil {
28+
t.Fatalf("create fake go command: %v", err)
29+
}
30+
t.Setenv("PATH", dir)
1431
t.Setenv("GOPROXY", "off")
1532
t.Setenv("GOPRIVATE", "")
1633
t.Setenv("GONOPROXY", "none")
1734

18-
if _, err := getLatestVersionWithTimeout(time.Second); err == nil {
19-
t.Fatal("expected GOPROXY=off to prevent the version lookup")
35+
latest, err := getLatestVersionWithTimeout(time.Second)
36+
if err != nil {
37+
t.Fatalf("get latest version: %v", err)
38+
}
39+
if latest != "v1.2.3" {
40+
t.Fatalf("latest version = %q, want v1.2.3", latest)
2041
}
2142
}
2243

0 commit comments

Comments
 (0)