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

Commit 84f51ad

Browse files
committed
Use smaller image for integration tests
1 parent 2494de0 commit 84f51ad

File tree

8 files changed

+64
-22
lines changed

8 files changed

+64
-22
lines changed

.github/workflows/integration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ jobs:
2222
- uses: actions/setup-go@v2
2323
with:
2424
go-version: '^1.14'
25-
- name: go test
26-
run: go test -v ./ci/integration/...
25+
- name: integration tests
26+
run: ./ci/steps/integration.sh

ci/integration/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM ubuntu:20.04
2+
3+
RUN apt-get update && apt-get install -y jq curl

ci/integration/devurls_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func TestDevURLCLI(t *testing.T) {
1212
run(t, "coder-cli-devurl-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
1313
c.Run(ctx, "which coder").Assert(t,
1414
tcli.Success(),
15-
tcli.StdoutMatches("/usr/sbin/coder"),
1615
tcli.StderrEmpty(),
1716
)
1817

ci/integration/envs_test.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,44 @@ import (
44
"context"
55
"fmt"
66
"math"
7+
"net/url"
78
"regexp"
89
"testing"
10+
"time"
911

1012
"cdr.dev/coder-cli/ci/tcli"
1113
"cdr.dev/coder-cli/coder-sdk"
14+
"cdr.dev/slog"
15+
"cdr.dev/slog/sloggers/slogtest"
1216
"cdr.dev/slog/sloggers/slogtest/assert"
1317
"github.com/google/go-cmp/cmp"
1418
)
1519

20+
func cleanupClient(t *testing.T, ctx context.Context) *coder.Client {
21+
creds := login(ctx, t)
22+
23+
u, err := url.Parse(creds.url)
24+
assert.Success(t, "parse base url", err)
25+
26+
return &coder.Client{BaseURL: u, Token: creds.token}
27+
}
28+
29+
func cleanupEnv(t *testing.T, client *coder.Client, envID string) func() {
30+
return func() {
31+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
32+
defer cancel()
33+
34+
slogtest.Info(t, "cleanuping up environment", slog.F("env_id", envID))
35+
_ = client.DeleteEnvironment(ctx, envID)
36+
}
37+
}
38+
1639
func TestEnvsCLI(t *testing.T) {
1740
t.Parallel()
1841

1942
run(t, "coder-cli-env-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
2043
headlessLogin(ctx, t, c)
44+
client := cleanupClient(t, ctx)
2145

2246
// Minimum args not received.
2347
c.Run(ctx, "coder envs create").Assert(t,
@@ -50,13 +74,6 @@ func TestEnvsCLI(t *testing.T) {
5074
tcli.Success(),
5175
)
5276

53-
t.Cleanup(func() {
54-
run(t, "coder-envs-edit-cleanup", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
55-
headlessLogin(ctx, t, c)
56-
c.Run(ctx, fmt.Sprintf("coder envs rm %s --force", name)).Assert(t)
57-
})
58-
})
59-
6077
c.Run(ctx, "coder envs ls").Assert(t,
6178
tcli.Success(),
6279
tcli.StdoutMatches(regexp.QuoteMeta(name)),
@@ -67,6 +84,10 @@ func TestEnvsCLI(t *testing.T) {
6784
tcli.Success(),
6885
tcli.StdoutJSONUnmarshal(&env),
6986
)
87+
88+
// attempt to cleanup the environment even if tests fail
89+
t.Cleanup(cleanupEnv(t, client, env.ID))
90+
7091
assert.Equal(t, "environment cpu was correctly set", cpu, float64(env.CPUCores), floatComparer)
7192

7293
c.Run(ctx, fmt.Sprintf("coder envs watch-build %s", name)).Assert(t,
@@ -80,24 +101,27 @@ func TestEnvsCLI(t *testing.T) {
80101

81102
run(t, "coder-cli-env-edit-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
82103
headlessLogin(ctx, t, c)
104+
client := cleanupClient(t, ctx)
83105

84106
name := randString(10)
85107
c.Run(ctx, fmt.Sprintf("coder envs create %s --image ubuntu --follow", name)).Assert(t,
86108
tcli.Success(),
87109
)
88-
t.Cleanup(func() {
89-
run(t, "coder-envs-edit-cleanup", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
90-
headlessLogin(ctx, t, c)
91-
c.Run(ctx, fmt.Sprintf("coder envs rm %s --force", name)).Assert(t)
92-
})
93-
})
110+
111+
var env coder.Environment
112+
c.Run(ctx, fmt.Sprintf(`coder envs ls -o json | jq '.[] | select(.name == "%s")'`, name)).Assert(t,
113+
tcli.Success(),
114+
tcli.StdoutJSONUnmarshal(&env),
115+
)
116+
117+
// attempt to cleanup the environment even if tests fail
118+
t.Cleanup(cleanupEnv(t, client, env.ID))
94119

95120
cpu := 2.1
96121
c.Run(ctx, fmt.Sprintf(`coder envs edit %s --cpu %f --follow`, name, cpu)).Assert(t,
97122
tcli.Success(),
98123
)
99124

100-
var env coder.Environment
101125
c.Run(ctx, fmt.Sprintf(`coder envs ls -o json | jq '.[] | select(.name == "%s")'`, name)).Assert(t,
102126
tcli.Success(),
103127
tcli.StdoutJSONUnmarshal(&env),

ci/integration/integration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func run(t *testing.T, container string, execute func(t *testing.T, ctx context.
1818
defer cancel()
1919

2020
c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
21-
Image: "codercom/enterprise-dev",
21+
Image: "coder-cli-integration:latest",
2222
Name: container,
2323
BindMounts: map[string]string{
2424
binpath: "/bin/coder",
@@ -36,7 +36,6 @@ func TestCoderCLI(t *testing.T) {
3636
run(t, "test-coder-cli", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
3737
c.Run(ctx, "which coder").Assert(t,
3838
tcli.Success(),
39-
tcli.StdoutMatches("/usr/sbin/coder"),
4039
tcli.StderrEmpty(),
4140
)
4241

ci/integration/setup_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ func build(path string) error {
5151
// write session tokens to the given container runner
5252
func headlessLogin(ctx context.Context, t *testing.T, runner *tcli.ContainerRunner) {
5353
creds := login(ctx, t)
54-
cmd := exec.CommandContext(ctx, "sh", "-c", "mkdir -p ~/.config/coder && cat > ~/.config/coder/session")
54+
cmd := exec.CommandContext(ctx, "sh", "-c", "mkdir -p $HOME/.config/coder && cat > $HOME/.config/coder/session")
5555

5656
// !IMPORTANT: be careful that this does not appear in logs
5757
cmd.Stdin = strings.NewReader(creds.token)
5858
runner.RunCmd(cmd).Assert(t,
5959
tcli.Success(),
6060
)
61-
runner.Run(ctx, fmt.Sprintf("echo -ne %s > ~/.config/coder/url", creds.url)).Assert(t,
61+
62+
cmd = exec.CommandContext(ctx, "sh", "-c", "cat > $HOME/.config/coder/url")
63+
cmd.Stdin = strings.NewReader(creds.url)
64+
runner.RunCmd(cmd).Assert(t,
6265
tcli.Success(),
6366
)
6467
}

ci/integration/users_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func TestUsers(t *testing.T) {
1414
run(t, "users-cli-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
1515
c.Run(ctx, "which coder").Assert(t,
1616
tcli.Success(),
17-
tcli.StdoutMatches("/usr/sbin/coder"),
1817
tcli.StderrEmpty(),
1918
)
2019

ci/steps/integration.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
log() {
6+
echo "--- $@"
7+
}
8+
9+
cd "$(git rev-parse --show-toplevel)"
10+
11+
log "building integration test image"
12+
docker build -f ./ci/integration/Dockerfile -t coder-cli-integration:latest .
13+
14+
log "starting integration tests"
15+
go test ./ci/integration -count=1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy