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

Commit f21d224

Browse files
committed
Abstract integration test container creation
1 parent 0e031d9 commit f21d224

File tree

7 files changed

+198
-203
lines changed

7 files changed

+198
-203
lines changed

ci/integration/devurls_test.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,23 @@ package integration
33
import (
44
"context"
55
"testing"
6-
"time"
76

87
"cdr.dev/coder-cli/ci/tcli"
9-
"cdr.dev/slog/sloggers/slogtest/assert"
108
)
119

1210
func TestDevURLCLI(t *testing.T) {
1311
t.Parallel()
14-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
15-
defer cancel()
16-
17-
c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
18-
Image: "codercom/enterprise-dev",
19-
Name: "coder-cli-devurl-tests",
20-
BindMounts: map[string]string{
21-
binpath: "/bin/coder",
22-
},
12+
run(t, "coder-cli-devurl-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
13+
c.Run(ctx, "which coder").Assert(t,
14+
tcli.Success(),
15+
tcli.StdoutMatches("/usr/sbin/coder"),
16+
tcli.StderrEmpty(),
17+
)
18+
19+
c.Run(ctx, "coder urls ls").Assert(t,
20+
tcli.Error(),
21+
)
2322
})
24-
assert.Success(t, "new run container", err)
25-
defer c.Close()
26-
27-
c.Run(ctx, "which coder").Assert(t,
28-
tcli.Success(),
29-
tcli.StdoutMatches("/usr/sbin/coder"),
30-
tcli.StderrEmpty(),
31-
)
32-
33-
c.Run(ctx, "coder urls ls").Assert(t,
34-
tcli.Error(),
35-
)
3623

3724
// The following cannot be enabled nor verified until either the
3825
// integration testing dogfood target has environments created, or

ci/integration/integration_test.go

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,78 @@ import (
1010
"cdr.dev/slog/sloggers/slogtest/assert"
1111
)
1212

13+
func run(t *testing.T, container string, execute func(t *testing.T, ctx context.Context, runner *tcli.ContainerRunner)) {
14+
t.Run(container, func(t *testing.T) {
15+
t.Parallel()
16+
17+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
18+
defer cancel()
19+
20+
c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
21+
Image: "codercom/enterprise-dev",
22+
Name: container,
23+
BindMounts: map[string]string{
24+
binpath: "/bin/coder",
25+
},
26+
})
27+
assert.Success(t, "new run container", err)
28+
defer c.Close()
29+
30+
execute(t, ctx, c)
31+
})
32+
}
33+
1334
func TestCoderCLI(t *testing.T) {
1435
t.Parallel()
15-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
16-
defer cancel()
17-
18-
c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
19-
Image: "codercom/enterprise-dev",
20-
Name: "coder-cli-tests",
21-
BindMounts: map[string]string{
22-
binpath: "/bin/coder",
23-
},
36+
run(t, "test-coder-cli", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
37+
c.Run(ctx, "which coder").Assert(t,
38+
tcli.Success(),
39+
tcli.StdoutMatches("/usr/sbin/coder"),
40+
tcli.StderrEmpty(),
41+
)
42+
43+
c.Run(ctx, "coder --version").Assert(t,
44+
tcli.StderrEmpty(),
45+
tcli.Success(),
46+
tcli.StdoutMatches("linux"),
47+
)
48+
49+
c.Run(ctx, "coder --help").Assert(t,
50+
tcli.Success(),
51+
tcli.StdoutMatches("Available Commands"),
52+
)
53+
54+
headlessLogin(ctx, t, c)
55+
56+
c.Run(ctx, "coder envs").Assert(t,
57+
tcli.Success(),
58+
)
59+
60+
c.Run(ctx, "coder envs ls").Assert(t,
61+
tcli.Success(),
62+
)
63+
64+
c.Run(ctx, "coder urls").Assert(t,
65+
tcli.Success(),
66+
)
67+
68+
c.Run(ctx, "coder sync").Assert(t,
69+
tcli.Error(),
70+
)
71+
72+
c.Run(ctx, "coder sh").Assert(t,
73+
tcli.Error(),
74+
)
75+
76+
c.Run(ctx, "coder logout").Assert(t,
77+
tcli.Success(),
78+
)
79+
80+
c.Run(ctx, "coder envs ls").Assert(t,
81+
tcli.Error(),
82+
)
2483
})
25-
assert.Success(t, "new run container", err)
26-
defer c.Close()
27-
28-
c.Run(ctx, "which coder").Assert(t,
29-
tcli.Success(),
30-
tcli.StdoutMatches("/usr/sbin/coder"),
31-
tcli.StderrEmpty(),
32-
)
33-
34-
c.Run(ctx, "coder --version").Assert(t,
35-
tcli.StderrEmpty(),
36-
tcli.Success(),
37-
tcli.StdoutMatches("linux"),
38-
)
39-
40-
c.Run(ctx, "coder --help").Assert(t,
41-
tcli.Success(),
42-
tcli.StdoutMatches("Available Commands"),
43-
)
44-
45-
headlessLogin(ctx, t, c)
46-
47-
c.Run(ctx, "coder envs").Assert(t,
48-
tcli.Success(),
49-
)
50-
51-
c.Run(ctx, "coder envs ls").Assert(t,
52-
tcli.Success(),
53-
)
54-
55-
c.Run(ctx, "coder urls").Assert(t,
56-
tcli.Success(),
57-
)
58-
59-
c.Run(ctx, "coder sync").Assert(t,
60-
tcli.Error(),
61-
)
62-
63-
c.Run(ctx, "coder sh").Assert(t,
64-
tcli.Error(),
65-
)
66-
67-
c.Run(ctx, "coder logout").Assert(t,
68-
tcli.Success(),
69-
)
70-
71-
c.Run(ctx, "coder envs ls").Assert(t,
72-
tcli.Error(),
73-
)
84+
7485
}
7586

7687
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))

ci/integration/secrets_test.go

Lines changed: 66 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,77 @@ import (
55
"fmt"
66
"regexp"
77
"testing"
8-
"time"
98

109
"cdr.dev/coder-cli/ci/tcli"
11-
"cdr.dev/slog/sloggers/slogtest/assert"
1210
)
1311

1412
func TestSecrets(t *testing.T) {
1513
t.Parallel()
16-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
17-
defer cancel()
18-
19-
c, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
20-
Image: "codercom/enterprise-dev",
21-
Name: "secrets-cli-tests",
22-
BindMounts: map[string]string{
23-
binpath: "/bin/coder",
24-
},
14+
run(t, "secrets-cli-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
15+
headlessLogin(ctx, t, c)
16+
17+
c.Run(ctx, "coder secrets ls").Assert(t,
18+
tcli.Success(),
19+
)
20+
21+
name, value := randString(8), randString(8)
22+
23+
c.Run(ctx, "coder secrets create").Assert(t,
24+
tcli.Error(),
25+
)
26+
27+
// this tests the "Value:" prompt fallback
28+
c.Run(ctx, fmt.Sprintf("echo %s | coder secrets create %s --from-prompt", value, name)).Assert(t,
29+
tcli.Success(),
30+
tcli.StderrEmpty(),
31+
)
32+
33+
c.Run(ctx, "coder secrets ls").Assert(t,
34+
tcli.Success(),
35+
tcli.StderrEmpty(),
36+
tcli.StdoutMatches("Value"),
37+
tcli.StdoutMatches(regexp.QuoteMeta(name)),
38+
)
39+
40+
c.Run(ctx, "coder secrets view "+name).Assert(t,
41+
tcli.Success(),
42+
tcli.StderrEmpty(),
43+
tcli.StdoutMatches(regexp.QuoteMeta(value)),
44+
)
45+
46+
c.Run(ctx, "coder secrets rm").Assert(t,
47+
tcli.Error(),
48+
)
49+
c.Run(ctx, "coder secrets rm "+name).Assert(t,
50+
tcli.Success(),
51+
)
52+
c.Run(ctx, "coder secrets view "+name).Assert(t,
53+
tcli.Error(),
54+
tcli.StdoutEmpty(),
55+
)
56+
57+
name, value = randString(8), randString(8)
58+
59+
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-literal %s", name, value)).Assert(t,
60+
tcli.Success(),
61+
tcli.StderrEmpty(),
62+
)
63+
64+
c.Run(ctx, "coder secrets view "+name).Assert(t,
65+
tcli.Success(),
66+
tcli.StdoutMatches(regexp.QuoteMeta(value)),
67+
)
68+
69+
name, value = randString(8), randString(8)
70+
c.Run(ctx, fmt.Sprintf("echo %s > ~/secret.json", value)).Assert(t,
71+
tcli.Success(),
72+
)
73+
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-file ~/secret.json", name)).Assert(t,
74+
tcli.Success(),
75+
)
76+
c.Run(ctx, "coder secrets view "+name).Assert(t,
77+
tcli.Success(),
78+
tcli.StdoutMatches(regexp.QuoteMeta(value)),
79+
)
2580
})
26-
assert.Success(t, "new run container", err)
27-
defer c.Close()
28-
29-
headlessLogin(ctx, t, c)
30-
31-
c.Run(ctx, "coder secrets ls").Assert(t,
32-
tcli.Success(),
33-
)
34-
35-
name, value := randString(8), randString(8)
36-
37-
c.Run(ctx, "coder secrets create").Assert(t,
38-
tcli.Error(),
39-
)
40-
41-
// this tests the "Value:" prompt fallback
42-
c.Run(ctx, fmt.Sprintf("echo %s | coder secrets create %s --from-prompt", value, name)).Assert(t,
43-
tcli.Success(),
44-
tcli.StderrEmpty(),
45-
)
46-
47-
c.Run(ctx, "coder secrets ls").Assert(t,
48-
tcli.Success(),
49-
tcli.StderrEmpty(),
50-
tcli.StdoutMatches("Value"),
51-
tcli.StdoutMatches(regexp.QuoteMeta(name)),
52-
)
53-
54-
c.Run(ctx, "coder secrets view "+name).Assert(t,
55-
tcli.Success(),
56-
tcli.StderrEmpty(),
57-
tcli.StdoutMatches(regexp.QuoteMeta(value)),
58-
)
59-
60-
c.Run(ctx, "coder secrets rm").Assert(t,
61-
tcli.Error(),
62-
)
63-
c.Run(ctx, "coder secrets rm "+name).Assert(t,
64-
tcli.Success(),
65-
)
66-
c.Run(ctx, "coder secrets view "+name).Assert(t,
67-
tcli.Error(),
68-
tcli.StdoutEmpty(),
69-
)
70-
71-
name, value = randString(8), randString(8)
72-
73-
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-literal %s", name, value)).Assert(t,
74-
tcli.Success(),
75-
tcli.StderrEmpty(),
76-
)
77-
78-
c.Run(ctx, "coder secrets view "+name).Assert(t,
79-
tcli.Success(),
80-
tcli.StdoutMatches(regexp.QuoteMeta(value)),
81-
)
82-
83-
name, value = randString(8), randString(8)
84-
c.Run(ctx, fmt.Sprintf("echo %s > ~/secret.json", value)).Assert(t,
85-
tcli.Success(),
86-
)
87-
c.Run(ctx, fmt.Sprintf("coder secrets create %s --from-file ~/secret.json", name)).Assert(t,
88-
tcli.Success(),
89-
)
90-
//
91-
c.Run(ctx, "coder secrets view "+name).Assert(t,
92-
tcli.Success(),
93-
tcli.StdoutMatches(regexp.QuoteMeta(value)),
94-
)
9581
}

ci/integration/ssh_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"cdr.dev/coder-cli/ci/tcli"
8+
)
9+
10+
func TestSSH(t *testing.T) {
11+
t.Parallel()
12+
run(t, "ssh-coder-cli-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
13+
headlessLogin(ctx, t, c)
14+
c.Run(ctx, "coder config-ssh").Assert(t,
15+
tcli.Success(),
16+
)
17+
})
18+
}

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