@@ -2,195 +2,130 @@ package dockergen
2
2
3
3
import (
4
4
"testing"
5
+
6
+ "github.com/stretchr/testify/assert"
5
7
)
6
8
7
9
func TestSplitDockerImageRepository (t * testing.T ) {
8
10
registry , repository , tag := splitDockerImage ("ubuntu" )
9
11
10
- if registry != "" {
11
- t .Fail ()
12
- }
13
- if repository != "ubuntu" {
14
- t .Fail ()
15
- }
16
- if tag != "" {
17
- t .Fail ()
18
- }
12
+ assert .Equal (t , "" , registry )
13
+ assert .Equal (t , "ubuntu" , repository )
14
+ assert .Equal (t , "" , tag )
19
15
20
16
dockerImage := DockerImage {
21
17
Registry : registry ,
22
18
Repository : repository ,
23
19
Tag : tag ,
24
20
}
25
- if "ubuntu" != dockerImage .String () {
26
- t .Fail ()
27
- }
21
+ assert .Equal (t , "ubuntu" , dockerImage .String ())
28
22
}
29
23
30
24
func TestSplitDockerImageWithRegistry (t * testing.T ) {
31
25
registry , repository , tag := splitDockerImage ("custom.registry/ubuntu" )
32
26
33
- if registry != "custom.registry" {
34
- t .Fail ()
35
- }
36
- if repository != "ubuntu" {
37
- t .Fail ()
38
- }
39
- if tag != "" {
40
- t .Fail ()
41
- }
27
+ assert .Equal (t , "custom.registry" , registry )
28
+ assert .Equal (t , "ubuntu" , repository )
29
+ assert .Equal (t , "" , tag )
30
+
42
31
dockerImage := DockerImage {
43
32
Registry : registry ,
44
33
Repository : repository ,
45
34
Tag : tag ,
46
35
}
47
- if "custom.registry/ubuntu" != dockerImage .String () {
48
- t .Fail ()
49
- }
50
-
36
+ assert .Equal (t , "custom.registry/ubuntu" , dockerImage .String ())
51
37
}
52
38
53
39
func TestSplitDockerImageWithRegistryAndTag (t * testing.T ) {
54
40
registry , repository , tag := splitDockerImage ("custom.registry/ubuntu:12.04" )
55
41
56
- if registry != "custom.registry" {
57
- t .Fail ()
58
- }
59
- if repository != "ubuntu" {
60
- t .Fail ()
61
- }
62
- if tag != "12.04" {
63
- t .Fail ()
64
- }
42
+ assert .Equal (t , "custom.registry" , registry )
43
+ assert .Equal (t , "ubuntu" , repository )
44
+ assert .Equal (t , "12.04" , tag )
45
+
65
46
dockerImage := DockerImage {
66
47
Registry : registry ,
67
48
Repository : repository ,
68
49
Tag : tag ,
69
50
}
70
- if "custom.registry/ubuntu:12.04" != dockerImage .String () {
71
- t .Fail ()
72
- }
73
-
51
+ assert .Equal (t , "custom.registry/ubuntu:12.04" , dockerImage .String ())
74
52
}
75
53
76
54
func TestSplitDockerImageWithRepositoryAndTag (t * testing.T ) {
77
55
registry , repository , tag := splitDockerImage ("ubuntu:12.04" )
78
56
79
- if registry != "" {
80
- t .Fail ()
81
- }
82
-
83
- if repository != "ubuntu" {
84
- t .Fail ()
85
- }
57
+ assert .Equal (t , "" , registry )
58
+ assert .Equal (t , "ubuntu" , repository )
59
+ assert .Equal (t , "12.04" , tag )
86
60
87
- if tag != "12.04" {
88
- t .Fail ()
89
- }
90
61
dockerImage := DockerImage {
91
62
Registry : registry ,
92
63
Repository : repository ,
93
64
Tag : tag ,
94
65
}
95
- if "ubuntu:12.04" != dockerImage .String () {
96
- t .Fail ()
97
- }
66
+ assert .Equal (t , "ubuntu:12.04" , dockerImage .String ())
98
67
}
99
68
100
69
func TestSplitDockerImageWithPrivateRegistryPath (t * testing.T ) {
101
70
registry , repository , tag := splitDockerImage ("localhost:8888/ubuntu/foo:12.04" )
102
71
103
- if registry != "localhost:8888" {
104
- t .Fail ()
105
- }
106
-
107
- if repository != "ubuntu/foo" {
108
- t .Fail ()
109
- }
72
+ assert .Equal (t , "localhost:8888" , registry )
73
+ assert .Equal (t , "ubuntu/foo" , repository )
74
+ assert .Equal (t , "12.04" , tag )
110
75
111
- if tag != "12.04" {
112
- t .Fail ()
113
- }
114
76
dockerImage := DockerImage {
115
77
Registry : registry ,
116
78
Repository : repository ,
117
79
Tag : tag ,
118
80
}
119
- if "localhost:8888/ubuntu/foo:12.04" != dockerImage .String () {
120
- t .Fail ()
121
- }
81
+ assert .Equal (t , "localhost:8888/ubuntu/foo:12.04" , dockerImage .String ())
122
82
}
123
83
func TestSplitDockerImageWithLocalRepositoryAndTag (t * testing.T ) {
124
84
registry , repository , tag := splitDockerImage ("localhost:8888/ubuntu:12.04" )
125
85
126
- if registry != "localhost:8888" {
127
- t . Fatalf ( "registry does not match: expected %s got %s" , "localhost:8888 " , registry )
128
- }
86
+ assert . Equal ( t , "localhost:8888" , registry )
87
+ assert . Equal ( t , "ubuntu " , repository )
88
+ assert . Equal ( t , "12.04" , tag )
129
89
130
- if repository != "ubuntu" {
131
- t .Fatalf ("repository does not match: expected %s got %s" , "ubuntu" , repository )
132
- }
133
-
134
- if tag != "12.04" {
135
- t .Fatalf ("tag does not match: expected %s got %s" , "12.04" , tag )
136
- }
137
90
dockerImage := DockerImage {
138
91
Registry : registry ,
139
92
Repository : repository ,
140
93
Tag : tag ,
141
94
}
142
- if "localhost:8888/ubuntu:12.04" != dockerImage .String () {
143
- t .Fail ()
144
- }
145
-
95
+ assert .Equal (t , "localhost:8888/ubuntu:12.04" , dockerImage .String ())
146
96
}
147
97
148
98
func TestParseHostUnix (t * testing.T ) {
149
99
proto , addr , err := parseHost ("unix:///var/run/docker.sock" )
150
- if err != nil {
151
- t .Fatalf ("%s" , err )
152
- }
153
- if proto != "unix" || addr != "/var/run/docker.sock" {
154
- t .Fatal ("failed to parse unix:///var/run/docker.sock" )
155
- }
100
+ assert .NoError (t , err )
101
+ assert .Equal (t , "unix" , proto , "failed to parse unix:///var/run/docker.sock" )
102
+ assert .Equal (t , "/var/run/docker.sock" , addr , "failed to parse unix:///var/run/docker.sock" )
156
103
}
157
104
158
105
func TestParseHostUnixDefault (t * testing.T ) {
159
106
proto , addr , err := parseHost ("" )
160
- if err != nil {
161
- t .Fatalf ("%s" , err )
162
- }
163
- if proto != "unix" || addr != "/var/run/docker.sock" {
164
- t .Fatal ("failed to parse ''" )
165
- }
107
+ assert .NoError (t , err )
108
+ assert .Equal (t , "unix" , proto , "failed to parse ''" )
109
+ assert .Equal (t , "/var/run/docker.sock" , addr , "failed to parse ''" )
166
110
}
167
111
168
112
func TestParseHostUnixDefaultNoPath (t * testing.T ) {
169
113
proto , addr , err := parseHost ("unix://" )
170
- if err != nil {
171
- t .Fatalf ("%s" , err )
172
- }
173
- if proto != "unix" || addr != "/var/run/docker.sock" {
174
- t .Fatal ("failed to parse unix://" )
175
- }
114
+ assert .NoError (t , err )
115
+ assert .Equal (t , "unix" , proto , "failed to parse unix://" )
116
+ assert .Equal (t , "/var/run/docker.sock" , addr , "failed to parse unix://" )
176
117
}
177
118
178
119
func TestParseHostTCP (t * testing.T ) {
179
120
proto , addr , err := parseHost ("tcp://127.0.0.1:4243" )
180
- if err != nil {
181
- t .Fatalf ("%s" , err )
182
- }
183
- if proto != "tcp" || addr != "127.0.0.1:4243" {
184
- t .Fatal ("failed to parse tcp://127.0.0.1:4243" )
185
- }
121
+ assert .NoError (t , err )
122
+ assert .Equal (t , "tcp" , proto , "failed to parse tcp://127.0.0.1:4243" )
123
+ assert .Equal (t , "127.0.0.1:4243" , addr , "failed to parse tcp://127.0.0.1:4243" )
186
124
}
187
125
188
126
func TestParseHostTCPDefault (t * testing.T ) {
189
127
proto , addr , err := parseHost ("tcp://:4243" )
190
- if err != nil {
191
- t .Fatalf ("%s" , err )
192
- }
193
- if proto != "tcp" || addr != "127.0.0.1:4243" {
194
- t .Fatal ("failed to parse unix:///var/run/docker.sock" )
195
- }
128
+ assert .NoError (t , err )
129
+ assert .Equal (t , "tcp" , proto , "failed to parse tcp://:4243" )
130
+ assert .Equal (t , "127.0.0.1:4243" , addr , "failed to parse tcp://:4243" )
196
131
}
0 commit comments