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

Initial setup for integration tests #80

Merged
merged 19 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
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
Next Next commit
Add verbose logging to integration tests
  • Loading branch information
cmoog committed Jul 29, 2020
commit e6c79f5ca755d2c79cae81716f5b05bea9b022ca
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
with:
go-version: '^1.14'
- name: go test
run: go test ./ci/integration/...
run: go test -v ./ci/integration/...
9 changes: 8 additions & 1 deletion ci/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func init() {
}

func TestTCli(t *testing.T) {
t.Parallel()
ctx := context.Background()

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

func TestHostRunner(t *testing.T) {
t.Parallel()
var (
c tcli.HostRunner
ctx = context.Background()
Expand All @@ -114,6 +116,7 @@ func TestHostRunner(t *testing.T) {
}

func TestCoderCLI(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
defer cancel()

Expand Down Expand Up @@ -141,7 +144,11 @@ func TestCoderCLI(t *testing.T) {
)

creds := login(ctx, t)
c.Run(ctx, fmt.Sprintf("mkdir -p ~/.config/coder && echo -ne %s > ~/.config/coder/session", creds.token)).Assert(t,
cmd := exec.CommandContext(ctx, "mkdir -p ~/.config/coder && cat > ~/.config/coder/session")

// !IMPORTANT: be careful that this does not appear in logs
cmd.Stdin = strings.NewReader(creds.token)
c.RunCmd(cmd).Assert(t,
tcli.Success(),
)
c.Run(ctx, fmt.Sprintf("echo -ne %s > ~/.config/coder/url", creds.url)).Assert(t,
Expand Down
10 changes: 10 additions & 0 deletions ci/tcli/tcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"testing"
"time"

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

slogtest.Info(t, "command output",
slog.F("command", a.cmd),
slog.F("stdout", string(cmdResult.Stdout)),
slog.F("stderr", string(cmdResult.Stderr)),
slog.F("exit-code", cmdResult.ExitCode),
slog.F("duration", cmdResult.Duration),
)

for ix, o := range option {
name := fmt.Sprintf("assertion_#%v", ix)
if named, ok := o.(Named); ok {
Expand Down