Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit e6c79f5

Browse files
committed
Add verbose logging to integration tests
1 parent 9d358a6 commit e6c79f5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.github/workflows/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
with:
2424
go-version: '^1.14'
2525
- name: go test
26-
run: go test ./ci/integration/...
26+
run: go test -v ./ci/integration/...

ci/integration/integration_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func init() {
4444
}
4545

4646
func TestTCli(t *testing.T) {
47+
t.Parallel()
4748
ctx := context.Background()
4849

4950
container, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
@@ -92,6 +93,7 @@ func TestTCli(t *testing.T) {
9293
}
9394

9495
func TestHostRunner(t *testing.T) {
96+
t.Parallel()
9597
var (
9698
c tcli.HostRunner
9799
ctx = context.Background()
@@ -114,6 +116,7 @@ func TestHostRunner(t *testing.T) {
114116
}
115117

116118
func TestCoderCLI(t *testing.T) {
119+
t.Parallel()
117120
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
118121
defer cancel()
119122

@@ -141,7 +144,11 @@ func TestCoderCLI(t *testing.T) {
141144
)
142145

143146
creds := login(ctx, t)
144-
c.Run(ctx, fmt.Sprintf("mkdir -p ~/.config/coder && echo -ne %s > ~/.config/coder/session", creds.token)).Assert(t,
147+
cmd := exec.CommandContext(ctx, "mkdir -p ~/.config/coder && cat > ~/.config/coder/session")
148+
149+
// !IMPORTANT: be careful that this does not appear in logs
150+
cmd.Stdin = strings.NewReader(creds.token)
151+
c.RunCmd(cmd).Assert(t,
145152
tcli.Success(),
146153
)
147154
c.Run(ctx, fmt.Sprintf("echo -ne %s > ~/.config/coder/url", creds.url)).Assert(t,

ci/tcli/tcli.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"testing"
1212
"time"
1313

14+
"cdr.dev/slog"
15+
"cdr.dev/slog/sloggers/slogtest"
1416
"cdr.dev/slog/sloggers/slogtest/assert"
1517
"golang.org/x/xerrors"
1618
)
@@ -197,6 +199,14 @@ func (a Assertable) Assert(t *testing.T, option ...Assertion) {
197199
cmdResult.Stdout = stdout.Bytes()
198200
cmdResult.Stderr = stderr.Bytes()
199201

202+
slogtest.Info(t, "command output",
203+
slog.F("command", a.cmd),
204+
slog.F("stdout", string(cmdResult.Stdout)),
205+
slog.F("stderr", string(cmdResult.Stderr)),
206+
slog.F("exit-code", cmdResult.ExitCode),
207+
slog.F("duration", cmdResult.Duration),
208+
)
209+
200210
for ix, o := range option {
201211
name := fmt.Sprintf("assertion_#%v", ix)
202212
if named, ok := o.(Named); ok {

0 commit comments

Comments
 (0)