@@ -23,6 +23,7 @@ import (
23
23
"testing"
24
24
25
25
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
26
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
26
27
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
27
28
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
28
29
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
@@ -32,7 +33,7 @@ import (
32
33
func TestNoTestDependencies (t * testing.T ) {
33
34
runCtx := & runcontext.RunContext {}
34
35
35
- deps , err := NewTester (runCtx ).TestDependencies ()
36
+ deps , err := NewTester (runCtx , true ).TestDependencies ()
36
37
37
38
testutil .CheckErrorAndDeepEqual (t , false , err , 0 , len (deps ))
38
39
}
@@ -53,7 +54,7 @@ func TestTestDependencies(t *testing.T) {
53
54
},
54
55
}
55
56
56
- deps , err := NewTester (runCtx ).TestDependencies ()
57
+ deps , err := NewTester (runCtx , true ).TestDependencies ()
57
58
58
59
expectedDeps := tmpDir .Paths ("tests/test1.yaml" , "tests/test2.yaml" , "test3.yaml" )
59
60
testutil .CheckErrorAndDeepEqual (t , false , err , expectedDeps , deps )
@@ -68,7 +69,7 @@ func TestWrongPattern(t *testing.T) {
68
69
},
69
70
}
70
71
71
- tester := NewTester (runCtx )
72
+ tester := NewTester (runCtx , true )
72
73
73
74
_ , err := tester .TestDependencies ()
74
75
testutil .CheckError (t , true , err )
@@ -80,19 +81,18 @@ func TestWrongPattern(t *testing.T) {
80
81
func TestNoTest (t * testing.T ) {
81
82
runCtx := & runcontext.RunContext {}
82
83
83
- err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , nil )
84
+ err := NewTester (runCtx , true ).Test (context .Background (), ioutil .Discard , nil )
84
85
85
86
testutil .CheckError (t , false , err )
86
87
}
87
88
88
89
func TestTestSuccess (t * testing.T ) {
89
90
testutil .Run (t , "" , func (t * testutil.T ) {
90
- tmpDir := t .NewTempDir ()
91
- tmpDir .Touch ("tests/test1.yaml" , "tests/test2.yaml" , "test3.yaml" )
91
+ tmpDir := t .NewTempDir ().Touch ("tests/test1.yaml" , "tests/test2.yaml" , "test3.yaml" )
92
92
93
93
t .Override (& util .DefaultExecCommand , testutil .
94
- CmdRun ("container-structure-test test -v warn --image TAG --config " + tmpDir .Path ("tests/test1.yaml" )+ " --config " + tmpDir .Path ("tests/test2.yaml" )).
95
- AndRun ("container-structure-test test -v warn --image TAG --config " + tmpDir .Path ("test3.yaml" )))
94
+ CmdRun ("container-structure-test test -v warn --image image:tag --config " + tmpDir .Path ("tests/test1.yaml" )+ " --config " + tmpDir .Path ("tests/test2.yaml" )).
95
+ AndRun ("container-structure-test test -v warn --image image:tag --config " + tmpDir .Path ("test3.yaml" )))
96
96
97
97
runCtx := & runcontext.RunContext {
98
98
WorkingDir : tmpDir .Root (),
@@ -111,26 +111,80 @@ func TestTestSuccess(t *testing.T) {
111
111
},
112
112
}
113
113
114
- err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , []build.Artifact {{
114
+ imagesAreLocal := true
115
+ err := NewTester (runCtx , imagesAreLocal ).Test (context .Background (), ioutil .Discard , []build.Artifact {{
115
116
ImageName : "image" ,
116
- Tag : "TAG " ,
117
+ Tag : "image:tag " ,
117
118
}})
118
119
119
120
t .CheckNoError (err )
120
121
})
121
122
}
122
123
124
+ func TestTestSuccessRemoteImage (t * testing.T ) {
125
+ testutil .Run (t , "" , func (t * testutil.T ) {
126
+ t .NewTempDir ().Touch ("test.yaml" ).Chdir ()
127
+ t .Override (& util .DefaultExecCommand , testutil .CmdRun ("container-structure-test test -v warn --image image:tag --config test.yaml" ))
128
+ t .Override (& docker .NewAPIClient , func (* runcontext.RunContext ) (docker.LocalDaemon , error ) {
129
+ return docker .NewLocalDaemon (& testutil.FakeAPIClient {}, nil , false , nil ), nil
130
+ })
131
+
132
+ runCtx := & runcontext.RunContext {
133
+ Cfg : latest.Pipeline {
134
+ Test : []* latest.TestCase {{
135
+ ImageName : "image" ,
136
+ StructureTests : []string {"test.yaml" },
137
+ }},
138
+ },
139
+ }
140
+
141
+ imagesAreLocal := false
142
+ err := NewTester (runCtx , imagesAreLocal ).Test (context .Background (), ioutil .Discard , []build.Artifact {{
143
+ ImageName : "image" ,
144
+ Tag : "image:tag" ,
145
+ }})
146
+
147
+ t .CheckNoError (err )
148
+ })
149
+ }
150
+
151
+ func TestTestFailureRemoteImage (t * testing.T ) {
152
+ testutil .Run (t , "" , func (t * testutil.T ) {
153
+ t .NewTempDir ().Touch ("test.yaml" ).Chdir ()
154
+ t .Override (& util .DefaultExecCommand , testutil .CmdRun ("container-structure-test test -v warn --image image:tag --config test.yaml" ))
155
+ t .Override (& docker .NewAPIClient , func (* runcontext.RunContext ) (docker.LocalDaemon , error ) {
156
+ return docker .NewLocalDaemon (& testutil.FakeAPIClient {ErrImagePull : true }, nil , false , nil ), nil
157
+ })
158
+
159
+ runCtx := & runcontext.RunContext {
160
+ Cfg : latest.Pipeline {
161
+ Test : []* latest.TestCase {{
162
+ ImageName : "image" ,
163
+ StructureTests : []string {"test.yaml" },
164
+ }},
165
+ },
166
+ }
167
+
168
+ imagesAreLocal := false
169
+ err := NewTester (runCtx , imagesAreLocal ).Test (context .Background (), ioutil .Discard , []build.Artifact {{
170
+ ImageName : "image" ,
171
+ Tag : "image:tag" ,
172
+ }})
173
+
174
+ t .CheckErrorContains (`unable to docker pull image "image:tag"` , err )
175
+ })
176
+ }
177
+
123
178
func TestTestFailure (t * testing.T ) {
124
179
testutil .Run (t , "" , func (t * testutil.T ) {
125
- tmpDir := t .NewTempDir ().Touch ("test.yaml" )
180
+ t .NewTempDir ().Touch ("test.yaml" ). Chdir ( )
126
181
127
182
t .Override (& util .DefaultExecCommand , testutil .CmdRunErr (
128
- "container-structure-test test -v warn --image broken-image --config " + tmpDir . Path ( " test.yaml") ,
183
+ "container-structure-test test -v warn --image broken-image --config test.yaml" ,
129
184
errors .New ("FAIL" ),
130
185
))
131
186
132
187
runCtx := & runcontext.RunContext {
133
- WorkingDir : tmpDir .Root (),
134
188
Cfg : latest.Pipeline {
135
189
Test : []* latest.TestCase {
136
190
{
@@ -141,7 +195,7 @@ func TestTestFailure(t *testing.T) {
141
195
},
142
196
}
143
197
144
- err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , []build.Artifact {{}})
198
+ err := NewTester (runCtx , true ).Test (context .Background (), ioutil .Discard , []build.Artifact {{}})
145
199
t .CheckError (true , err )
146
200
})
147
201
}
0 commit comments