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

Commit c451d16

Browse files
committed
Move tcli tests to tcli package
1 parent b5b93d4 commit c451d16

File tree

2 files changed

+75
-72
lines changed

2 files changed

+75
-72
lines changed

ci/integration/integration_test.go

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -43,78 +43,6 @@ func init() {
4343
}
4444
}
4545

46-
func TestTCli(t *testing.T) {
47-
t.Parallel()
48-
ctx := context.Background()
49-
50-
container, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
51-
Image: "ubuntu:latest",
52-
Name: "test-container",
53-
BindMounts: map[string]string{
54-
binpath: "/bin/coder",
55-
},
56-
})
57-
assert.Success(t, "new run container", err)
58-
defer container.Close()
59-
60-
container.Run(ctx, "echo testing").Assert(t,
61-
tcli.Success(),
62-
tcli.StderrEmpty(),
63-
tcli.StdoutMatches("esting"),
64-
)
65-
66-
container.Run(ctx, "sleep 1.5 && echo 1>&2 stderr-message").Assert(t,
67-
tcli.Success(),
68-
tcli.StdoutEmpty(),
69-
tcli.StderrMatches("message"),
70-
tcli.DurationGreaterThan(time.Second),
71-
)
72-
73-
cmd := exec.CommandContext(ctx, "cat")
74-
cmd.Stdin = strings.NewReader("testing")
75-
76-
container.RunCmd(cmd).Assert(t,
77-
tcli.Success(),
78-
tcli.StderrEmpty(),
79-
tcli.StdoutMatches("testing"),
80-
)
81-
82-
container.Run(ctx, "which coder").Assert(t,
83-
tcli.Success(),
84-
tcli.StdoutMatches("/bin/coder"),
85-
tcli.StderrEmpty(),
86-
)
87-
88-
container.Run(ctx, "coder version").Assert(t,
89-
tcli.StderrEmpty(),
90-
tcli.Success(),
91-
tcli.StdoutMatches("linux"),
92-
)
93-
}
94-
95-
func TestHostRunner(t *testing.T) {
96-
t.Parallel()
97-
var (
98-
c tcli.HostRunner
99-
ctx = context.Background()
100-
)
101-
102-
c.Run(ctx, "echo testing").Assert(t,
103-
tcli.Success(),
104-
tcli.StderrEmpty(),
105-
tcli.StdoutMatches("testing"),
106-
)
107-
108-
wd, err := os.Getwd()
109-
assert.Success(t, "get working dir", err)
110-
111-
c.Run(ctx, "pwd").Assert(t,
112-
tcli.Success(),
113-
tcli.StderrEmpty(),
114-
tcli.StdoutMatches(wd),
115-
)
116-
}
117-
11846
func TestCoderCLI(t *testing.T) {
11947
t.Parallel()
12048
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
@@ -130,6 +58,12 @@ func TestCoderCLI(t *testing.T) {
13058
assert.Success(t, "new run container", err)
13159
defer c.Close()
13260

61+
c.Run(ctx, "which coder").Assert(t,
62+
tcli.Success(),
63+
tcli.StdoutMatches("/usr/sbin/coder"),
64+
tcli.StderrEmpty(),
65+
)
66+
13367
c.Run(ctx, "coder version").Assert(t,
13468
tcli.StderrEmpty(),
13569
tcli.Success(),

ci/tcli/tcli_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package tcli_test
2+
3+
import (
4+
"context"
5+
"os"
6+
"os/exec"
7+
"strings"
8+
"testing"
9+
"time"
10+
11+
"cdr.dev/coder-cli/ci/tcli"
12+
"cdr.dev/slog/sloggers/slogtest/assert"
13+
)
14+
15+
func TestTCli(t *testing.T) {
16+
t.Parallel()
17+
ctx := context.Background()
18+
19+
container, err := tcli.NewContainerRunner(ctx, &tcli.ContainerConfig{
20+
Image: "ubuntu:latest",
21+
Name: "test-container",
22+
})
23+
assert.Success(t, "new run container", err)
24+
defer container.Close()
25+
26+
container.Run(ctx, "echo testing").Assert(t,
27+
tcli.Success(),
28+
tcli.StderrEmpty(),
29+
tcli.StdoutMatches("esting"),
30+
)
31+
32+
container.Run(ctx, "sleep 1.5 && echo 1>&2 stderr-message").Assert(t,
33+
tcli.Success(),
34+
tcli.StdoutEmpty(),
35+
tcli.StderrMatches("message"),
36+
tcli.DurationGreaterThan(time.Second),
37+
)
38+
39+
cmd := exec.CommandContext(ctx, "cat")
40+
cmd.Stdin = strings.NewReader("testing")
41+
42+
container.RunCmd(cmd).Assert(t,
43+
tcli.Success(),
44+
tcli.StderrEmpty(),
45+
tcli.StdoutMatches("testing"),
46+
)
47+
}
48+
func TestHostRunner(t *testing.T) {
49+
t.Parallel()
50+
var (
51+
c tcli.HostRunner
52+
ctx = context.Background()
53+
)
54+
55+
c.Run(ctx, "echo testing").Assert(t,
56+
tcli.Success(),
57+
tcli.StderrEmpty(),
58+
tcli.StdoutMatches("testing"),
59+
)
60+
61+
wd, err := os.Getwd()
62+
assert.Success(t, "get working dir", err)
63+
64+
c.Run(ctx, "pwd").Assert(t,
65+
tcli.Success(),
66+
tcli.StderrEmpty(),
67+
tcli.StdoutMatches(wd),
68+
)
69+
}

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