@@ -54,6 +54,33 @@ func TestName(t *testing.T) {
54
54
}
55
55
}
56
56
57
+ func TestImageExists (t * testing.T ) {
58
+ var tests = []struct {
59
+ runtime string
60
+ name string
61
+ sha string
62
+ want bool
63
+ }{
64
+ {"docker" , "missing" , "0000000000000000000000000000000000000000000000000000000000000000" , false },
65
+ {"docker" , "image" , "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , true },
66
+ {"crio" , "missing" , "0000000000000000000000000000000000000000000000000000000000000000" , false },
67
+ {"crio" , "image" , "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , true },
68
+ }
69
+ for _ , tc := range tests {
70
+ t .Run (tc .runtime , func (t * testing.T ) {
71
+ r , err := New (Config {Type : tc .runtime , Runner : NewFakeRunner (t )})
72
+ if err != nil {
73
+ t .Fatalf ("New(%s): %v" , tc .runtime , err )
74
+ }
75
+
76
+ got := r .ImageExists (tc .name , tc .sha )
77
+ if diff := cmp .Diff (tc .want , got ); diff != "" {
78
+ t .Errorf ("ImageExists(%s) returned diff (-want +got):\n %s" , tc .runtime , diff )
79
+ }
80
+ })
81
+ }
82
+ }
83
+
57
84
func TestCGroupDriver (t * testing.T ) {
58
85
var tests = []struct {
59
86
runtime string
@@ -174,6 +201,8 @@ func (f *FakeRunner) RunCmd(cmd *exec.Cmd) (*command.RunResult, error) {
174
201
return buffer (f .which (args , root ))
175
202
case "docker" :
176
203
return buffer (f .docker (args , root ))
204
+ case "podman" :
205
+ return buffer (f .podman (args , root ))
177
206
case "crictl" , "/usr/bin/crictl" :
178
207
return buffer (f .crictl (args , root ))
179
208
case "crio" :
@@ -225,19 +254,44 @@ func (f *FakeRunner) docker(args []string, _ bool) (string, error) {
225
254
}
226
255
case "version" :
227
256
228
- if args [1 ] == "--format" && args [2 ] == "' {{.Server.Version}}' " {
257
+ if args [1 ] == "--format" && args [2 ] == "{{.Server.Version}}" {
229
258
return "18.06.2-ce" , nil
230
259
}
231
260
261
+ case "inspect" :
262
+
263
+ if args [1 ] == "--format" && args [2 ] == "{{.Id}}" {
264
+ if args [3 ] == "missing" {
265
+ return "" , & exec.ExitError {Stderr : []byte ("Error: No such object: missing" )}
266
+ }
267
+ return "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , nil
268
+ }
269
+
232
270
case "info" :
233
271
234
- if args [1 ] == "--format" && args [2 ] == "' {{.CgroupDriver}}' " {
272
+ if args [1 ] == "--format" && args [2 ] == "{{.CgroupDriver}}" {
235
273
return "cgroupfs" , nil
236
274
}
237
275
}
238
276
return "" , nil
239
277
}
240
278
279
+ // podman is a fake implementation of podman
280
+ func (f * FakeRunner ) podman (args []string , _ bool ) (string , error ) {
281
+ switch cmd := args [0 ]; cmd {
282
+ case "inspect" :
283
+
284
+ if args [1 ] == "--format" && args [2 ] == "{{.Id}}" {
285
+ if args [3 ] == "missing" {
286
+ return "" , & exec.ExitError {Stderr : []byte ("Error: error getting image \" missing\" : unable to find a name and tag match for missing in repotags: no such image" )}
287
+ }
288
+ return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , nil
289
+ }
290
+
291
+ }
292
+ return "" , nil
293
+ }
294
+
241
295
// crio is a fake implementation of crio
242
296
func (f * FakeRunner ) crio (args []string , _ bool ) (string , error ) { //nolint (result 1 (error) is always nil)
243
297
if args [0 ] == "--version" {
0 commit comments