-
Notifications
You must be signed in to change notification settings - Fork 24
/
docker_test.go
74 lines (59 loc) · 1.55 KB
/
docker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package docker_test
import (
"bytes"
"regexp"
"testing"
"golang.org/x/net/context"
"github.com/remind101/conveyor/builder"
"github.com/remind101/conveyor/builder/docker"
"github.com/stretchr/testify/assert"
)
// This is just a highlevel sanity test.
func TestBuilder_Build(t *testing.T) {
b := newDockerBuilder(t)
ctx := context.Background()
w := new(bytes.Buffer)
_, err := b.Build(ctx, w, builder.BuildOptions{
Repository: "remind101/acme-inc",
Branch: "master",
Sha: "827fecd2d36ebeaa2fd05aa8ef3eed1e56a8cd57",
})
assert.NoError(t, err)
if !regexp.MustCompile(`Successfully built`).MatchString(w.String()) {
t.Log(w.String())
t.Fatal("Expected image to be built")
}
}
func TestBuilder_Build_Cancel(t *testing.T) {
b := newDockerBuilder(t)
ctx, cancel := context.WithCancel(context.Background())
w := new(bytes.Buffer)
errCh := make(chan error)
go func() {
_, err := b.Build(ctx, w, builder.BuildOptions{
Repository: "remind101/acme-inc",
Branch: "master",
Sha: "827fecd2d36ebeaa2fd05aa8ef3eed1e56a8cd57",
})
errCh <- err
}()
// Cancel the build and wait for it to tear down the container.
cancel()
err := <-errCh
if _, ok := err.(*builder.BuildCanceledError); !ok {
t.Fatal("Expected build to be canceled")
}
}
func newDockerBuilder(t *testing.T) *docker.Builder {
checkDocker(t)
b, err := docker.NewBuilderFromEnv()
if err != nil {
t.Fatal(err)
}
return b
}
func checkDocker(t testing.TB) {
if testing.Short() {
t.Skip("Skipping docker tests because they take a long time")
}
}