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

Initial setup for integration tests #80

Merged
merged 19 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for host runner
  • Loading branch information
cmoog committed Jul 28, 2020
commit f4fe567b28e03adc7a0ce932634d090ec0ee61cd
22 changes: 22 additions & 0 deletions ci/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ func TestTCli(t *testing.T) {
)
}

func TestHostRunner(t *testing.T) {
var (
c tcli.HostRunner
ctx = context.Background()
)

c.Run(ctx, "echo testing").Assert(t,
tcli.Success(),
tcli.StderrEmpty(),
tcli.StdoutMatches("testing"),
)

wd, err := os.Getwd()
assert.Success(t, "get working dir", err)

c.Run(ctx, "pwd").Assert(t,
tcli.Success(),
tcli.StderrEmpty(),
tcli.StdoutMatches(wd),
)
}

func TestCoderCLI(t *testing.T) {
ctx := context.Background()

Expand Down
8 changes: 7 additions & 1 deletion ci/tcli/tcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ func (r *ContainerRunner) Close() error {
return nil
}

// HostRunner executes command tests on the host, outside of a container
type HostRunner struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you foresee us using HostRunner in the coder-cli tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at the moment, but I do think it has a place in tcli as an escape hatch.


// Run executes the given command on the host
func (r *HostRunner) Run(ctx context.Context, command string) *Assertable {
var (
args []string
Expand All @@ -114,19 +116,23 @@ func (r *HostRunner) Run(ctx context.Context, command string) *Assertable {
if len(parts) > 1 {
args = parts[1:]
}
cmd := exec.CommandContext(ctx, path, args...)

return &Assertable{
cmd: exec.CommandContext(ctx, path, args...),
cmd: cmd,
tname: command,
}
}

// RunCmd executes the given command on the host
func (r *HostRunner) RunCmd(cmd *exec.Cmd) *Assertable {
return &Assertable{
cmd: cmd,
tname: strings.Join(cmd.Args, " "),
}
}

// Close is a noop for HostRunner
func (r *HostRunner) Close() error {
return nil
}
Expand Down