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

Commit e787ca7

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

File tree

8 files changed

+53
-20
lines changed

8 files changed

+53
-20
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: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"math"
7+
"net/url"
78
"regexp"
89
"testing"
910

@@ -13,11 +14,21 @@ import (
1314
"github.com/google/go-cmp/cmp"
1415
)
1516

17+
func cleanupClient(t *testing.T, ctx context.Context) *coder.Client {
18+
creds := login(ctx, t)
19+
20+
u, err := url.Parse(creds.url)
21+
assert.Success(t, "parse base url", err)
22+
23+
return &coder.Client{BaseURL: u, Token: creds.token}
24+
}
25+
1626
func TestEnvsCLI(t *testing.T) {
1727
t.Parallel()
1828

1929
run(t, "coder-cli-env-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
2030
headlessLogin(ctx, t, c)
31+
client := cleanupClient(t, ctx)
2132

2233
// Minimum args not received.
2334
c.Run(ctx, "coder envs create").Assert(t,
@@ -50,13 +61,6 @@ func TestEnvsCLI(t *testing.T) {
5061
tcli.Success(),
5162
)
5263

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-
6064
c.Run(ctx, "coder envs ls").Assert(t,
6165
tcli.Success(),
6266
tcli.StdoutMatches(regexp.QuoteMeta(name)),
@@ -67,8 +71,14 @@ func TestEnvsCLI(t *testing.T) {
6771
tcli.Success(),
6872
tcli.StdoutJSONUnmarshal(&env),
6973
)
74+
75+
// attempt to cleanup the environment even if tests fail
76+
t.Cleanup(func() {
77+
_ = client.DeleteEnvironment(ctx, env.ID)
78+
})
7079
assert.Equal(t, "environment cpu was correctly set", cpu, float64(env.CPUCores), floatComparer)
7180

81+
7282
c.Run(ctx, fmt.Sprintf("coder envs watch-build %s", name)).Assert(t,
7383
tcli.Success(),
7484
)
@@ -80,24 +90,29 @@ func TestEnvsCLI(t *testing.T) {
8090

8191
run(t, "coder-cli-env-edit-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
8292
headlessLogin(ctx, t, c)
93+
client := cleanupClient(t, ctx)
8394

8495
name := randString(10)
8596
c.Run(ctx, fmt.Sprintf("coder envs create %s --image ubuntu --follow", name)).Assert(t,
8697
tcli.Success(),
8798
)
99+
100+
var env coder.Environment
101+
c.Run(ctx, fmt.Sprintf(`coder envs ls -o json | jq '.[] | select(.name == "%s")'`, name)).Assert(t,
102+
tcli.Success(),
103+
tcli.StdoutJSONUnmarshal(&env),
104+
)
105+
106+
// attempt to cleanup the environment even if tests fail
88107
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-
})
108+
_ = client.DeleteEnvironment(ctx, env.ID)
93109
})
94110

95111
cpu := 2.1
96112
c.Run(ctx, fmt.Sprintf(`coder envs edit %s --cpu %f --follow`, name, cpu)).Assert(t,
97113
tcli.Success(),
98114
)
99115

100-
var env coder.Environment
101116
c.Run(ctx, fmt.Sprintf(`coder envs ls -o json | jq '.[] | select(.name == "%s")'`, name)).Assert(t,
102117
tcli.Success(),
103118
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)