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

Commit f4fe567

Browse files
committed
Add tests for host runner
1 parent bf31666 commit f4fe567

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ci/integration/integration_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ func TestTCli(t *testing.T) {
9191
)
9292
}
9393

94+
func TestHostRunner(t *testing.T) {
95+
var (
96+
c tcli.HostRunner
97+
ctx = context.Background()
98+
)
99+
100+
c.Run(ctx, "echo testing").Assert(t,
101+
tcli.Success(),
102+
tcli.StderrEmpty(),
103+
tcli.StdoutMatches("testing"),
104+
)
105+
106+
wd, err := os.Getwd()
107+
assert.Success(t, "get working dir", err)
108+
109+
c.Run(ctx, "pwd").Assert(t,
110+
tcli.Success(),
111+
tcli.StderrEmpty(),
112+
tcli.StdoutMatches(wd),
113+
)
114+
}
115+
94116
func TestCoderCLI(t *testing.T) {
95117
ctx := context.Background()
96118

ci/tcli/tcli.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ func (r *ContainerRunner) Close() error {
100100
return nil
101101
}
102102

103+
// HostRunner executes command tests on the host, outside of a container
103104
type HostRunner struct{}
104105

106+
// Run executes the given command on the host
105107
func (r *HostRunner) Run(ctx context.Context, command string) *Assertable {
106108
var (
107109
args []string
@@ -114,19 +116,23 @@ func (r *HostRunner) Run(ctx context.Context, command string) *Assertable {
114116
if len(parts) > 1 {
115117
args = parts[1:]
116118
}
119+
cmd := exec.CommandContext(ctx, path, args...)
120+
117121
return &Assertable{
118-
cmd: exec.CommandContext(ctx, path, args...),
122+
cmd: cmd,
119123
tname: command,
120124
}
121125
}
122126

127+
// RunCmd executes the given command on the host
123128
func (r *HostRunner) RunCmd(cmd *exec.Cmd) *Assertable {
124129
return &Assertable{
125130
cmd: cmd,
126131
tname: strings.Join(cmd.Args, " "),
127132
}
128133
}
129134

135+
// Close is a noop for HostRunner
130136
func (r *HostRunner) Close() error {
131137
return nil
132138
}

0 commit comments

Comments
 (0)