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
Adds working bind mount
  • Loading branch information
cmoog committed Jul 28, 2020
commit 025e1bdfc1e512997560264b5648eea69cdb61cc
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
ci/bin
cmd/coder/coder
ci/integration/bin
30 changes: 30 additions & 0 deletions ci/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package integration

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
Expand All @@ -11,12 +14,33 @@ import (
"cdr.dev/slog/sloggers/slogtest/assert"
)

func build(t *testing.T, path string) {
cmd := exec.Command(
"sh", "-c",
fmt.Sprintf("cd ../../ && go build -o %s ./cmd/coder", path),
)
cmd.Env = append(os.Environ(), "GOOS=linux", "CGO_ENABLED=0")

out, err := cmd.CombinedOutput()
t.Logf("%s", string(out))
assert.Success(t, "build go binary", err)
}

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

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

binpath := filepath.Join(cwd, "bin", "coder")
build(t, binpath)

container, err := tcli.NewRunContainer(ctx, &tcli.ContainerConfig{
Image: "ubuntu:latest",
Name: "test-container",
BindMounts: map[string]string{
binpath: "/bin/coder",
},
})

assert.Success(t, "new run container", err)
Expand All @@ -43,4 +67,10 @@ func TestTCli(t *testing.T) {
tcli.StderrEmpty(),
tcli.StdoutMatches("testing"),
)

container.Run(ctx, "which coder").Assert(t,
tcli.Success(),
tcli.StdoutMatches("/bin/coder"),
tcli.StderrEmpty(),
)
}
10 changes: 5 additions & 5 deletions ci/tcli/tcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ type RunContainer struct {
}

type ContainerConfig struct {
Name string
Image string
Mounts map[string]string
Name string
Image string
BindMounts map[string]string
}

func mountArgs(m map[string]string) (args []string) {
for src, dest := range m {
args = append(args, "--mount", fmt.Sprintf("source=%s,target=%s", src, dest))
args = append(args, "--mount", fmt.Sprintf("type=bind,source=%s,target=%s", src, dest))
}
return args
}
Expand All @@ -50,7 +50,7 @@ func NewRunContainer(ctx context.Context, config *ContainerConfig) (*RunContaine
"--name", config.Name,
"-it", "-d",
}
args = append(args, mountArgs(config.Mounts)...)
args = append(args, mountArgs(config.BindMounts)...)
args = append(args, config.Image)

cmd := exec.CommandContext(ctx, "docker", args...)
Expand Down