-
Notifications
You must be signed in to change notification settings - Fork 13
/
image_test.go
117 lines (109 loc) · 2.84 KB
/
image_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package meli
import (
"context"
"io/ioutil"
"strings"
"testing"
)
func TestPullDockerImage(t *testing.T) {
tt := []struct {
dc *DockerContainer
expectedErr error
}{
{&DockerContainer{ComposeService: ComposeService{Image: "busybox"}, LogMedium: ioutil.Discard}, nil},
}
var ctx = context.Background()
cli := &mockDockerClient{}
for _, v := range tt {
err := PullDockerImage(ctx, cli, v.dc)
if err != nil {
t.Errorf("\nCalled PullDockerImage(%#+v) \ngot %s \nwanted %#+v", v.dc, err, v.expectedErr)
}
}
}
func TestBuildDockerImage(t *testing.T) {
tt := []struct {
dc *DockerContainer
expected string
expectedErr error
}{
{
&DockerContainer{
ServiceName: "myservicename",
DockerComposeFile: "docker-compose.yml",
ComposeService: ComposeService{
Build: Buildstruct{Dockerfile: "testdata/Dockerfile"}},
LogMedium: ioutil.Discard},
"meli_myservicename",
nil},
{
&DockerContainer{
ServiceName: "myservicename",
DockerComposeFile: "docker-compose.yml",
ComposeService: ComposeService{
Build: Buildstruct{Dockerfile: "testdata/Dockerfile"}},
LogMedium: ioutil.Discard,
Rebuild: true,
},
"meli_myservicename",
nil},
{
&DockerContainer{
ServiceName: "myservicename",
DockerComposeFile: "testdata/docker-compose.yml",
ComposeService: ComposeService{
Build: Buildstruct{
Dockerfile: "nestedDockerfile",
Context: "nestedDir/level1/level2/"}},
LogMedium: ioutil.Discard,
Rebuild: true,
},
"meli_myservicename",
nil},
}
var ctx = context.Background()
cli := &mockDockerClient{}
LoadAuth()
for _, v := range tt {
actual, err := BuildDockerImage(ctx, cli, v.dc)
if err != nil {
t.Errorf("\nCalled BuildDockerImage(%#+v) \ngot %s \nwanted %#+v", v.dc, err, v.expectedErr)
}
if actual != v.expected {
t.Errorf("\nCalled BuildDockerImage(%#+v) \ngot %s \nwanted %#+v", v.dc, actual, v.expected)
}
}
}
func BenchmarkPullDockerImage(b *testing.B) {
var ctx = context.Background()
cli := &mockDockerClient{}
dc := &DockerContainer{ComposeService: ComposeService{Image: "busybox"}, LogMedium: ioutil.Discard}
LoadAuth()
for n := 0; n < b.N; n++ {
_ = PullDockerImage(ctx, cli, dc)
}
}
func BenchmarkBuildDockerImage(b *testing.B) {
var ctx = context.Background()
cli := &mockDockerClient{}
dc := &DockerContainer{
ServiceName: "myservicename",
DockerComposeFile: "docker-compose.yml",
ComposeService: ComposeService{
Build: Buildstruct{Dockerfile: "testdata/Dockerfile"}},
LogMedium: ioutil.Discard,
Rebuild: true,
}
LoadAuth()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = BuildDockerImage(ctx, cli, dc)
}
}
func BenchmarkPoolReadFrom(b *testing.B) {
r := strings.NewReader("hello")
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = poolReadFrom(r)
}
}