forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_test.go
102 lines (92 loc) · 2.67 KB
/
container_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
package testcontainers
import (
"testing"
"github.com/pkg/errors"
)
func Test_ContainerValidation(t *testing.T) {
type ContainerValidationTestCase struct {
Name string
ExpectedError error
ContainerRequest ContainerRequest
}
testTable := []ContainerValidationTestCase{
ContainerValidationTestCase{
Name: "cannot set both context and image",
ExpectedError: errors.New("you cannot specify both an Image and Context in a ContainerRequest"),
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
Context: ".",
},
Image: "redis:latest",
},
},
ContainerValidationTestCase{
Name: "can set image without context",
ExpectedError: nil,
ContainerRequest: ContainerRequest{
Image: "redis:latest",
},
},
ContainerValidationTestCase{
Name: "can set context without image",
ExpectedError: nil,
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
Context: ".",
},
},
},
}
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
err := testCase.ContainerRequest.Validate()
if err == nil && testCase.ExpectedError == nil {
return
} else if err == nil && testCase.ExpectedError != nil {
t.Errorf("did not receive expected error: %s", testCase.ExpectedError.Error())
} else if err != nil && testCase.ExpectedError == nil {
t.Errorf("received unexpected error: %s", err.Error())
} else if err.Error() != testCase.ExpectedError.Error() {
t.Errorf("errors mismatch: %s != %s", err.Error(), testCase.ExpectedError.Error())
}
})
}
}
func Test_GetDockerfile(t *testing.T) {
type TestCase struct {
name string
ExpectedDockerfileName string
ContainerRequest ContainerRequest
}
testTable := []TestCase{
TestCase{
name: "defaults to \"Dockerfile\" 1",
ExpectedDockerfileName: "Dockerfile",
ContainerRequest: ContainerRequest{},
},
TestCase{
name: "defaults to \"Dockerfile\" 2",
ExpectedDockerfileName: "Dockerfile",
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{},
},
},
TestCase{
name: "will override name",
ExpectedDockerfileName: "CustomDockerfile",
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
Dockerfile: "CustomDockerfile",
},
},
},
}
for _, testCase := range testTable {
t.Run(testCase.name, func(t *testing.T) {
n := testCase.ContainerRequest.GetDockerfile()
if n != testCase.ExpectedDockerfileName {
t.Fatalf("expected Dockerfile name: %s, received: %s", testCase.ExpectedDockerfileName, n)
}
})
}
}