MCPcopy Create free account
hub / github.com/containers/common / TestSave

Function TestSave

libimage/save_test.go:14–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestSave(t *testing.T) {
15 runtime, cleanup := testNewRuntime(t)
16 defer cleanup()
17 ctx := context.Background()
18
19 // Prefetch alpine, busybox.
20 pullOptions := &PullOptions{}
21 pullOptions.Writer = os.Stdout
22 _, err := runtime.Pull(ctx, "docker.io/library/alpine:latest", config.PullPolicyAlways, pullOptions)
23 require.NoError(t, err)
24 _, err = runtime.Pull(ctx, "docker.io/library/busybox:latest", config.PullPolicyAlways, pullOptions)
25 require.NoError(t, err)
26
27 // Save the two images into a multi-image archive. This way, we can
28 // reload the images for each test.
29 saveOptions := &SaveOptions{}
30 saveOptions.Writer = os.Stdout
31 imageCache, err := ioutil.TempFile("", "saveimagecache")
32 require.NoError(t, err)
33 imageCache.Close()
34 defer os.Remove(imageCache.Name())
35 err = runtime.Save(ctx, []string{"alpine", "busybox"}, "docker-archive", imageCache.Name(), saveOptions)
36 require.NoError(t, err)
37
38 loadOptions := &LoadOptions{}
39 loadOptions.Writer = os.Stdout
40
41 // The table tests are smoke tests to exercise the different code
42 // paths. More detailed tests follow below.
43 for _, test := range []struct {
44 names []string
45 tags []string
46 format string
47 isDir bool
48 expectError bool
49 }{
50 // No `names`
51 {nil, nil, "", false, true},
52 {[]string{}, nil, "", false, true},
53 // Invalid/unsupported format
54 {[]string{"something"}, nil, "", false, true},
55 {[]string{"something"}, nil, "else", false, true},
56 // oci
57 {[]string{"busybox"}, nil, "oci-dir", true, false},
58 {[]string{"busybox"}, nil, "oci-archive", false, false},
59 // oci-archive doesn't support multi-image archives
60 {[]string{"busybox", "alpine"}, nil, "oci-archive", false, true},
61 // docker
62 {[]string{"busybox"}, nil, "docker-archive", false, false},
63 {[]string{"busybox"}, []string{"localhost/tag:1", "quay.io/repo/image:tag"}, "docker-archive", false, false},
64 {[]string{"busybox"}, nil, "docker-dir", true, false},
65 {[]string{"busybox", "alpine"}, nil, "docker-archive", false, false},
66 // additional tags and multi-images conflict
67 {[]string{"busybox", "alpine"}, []string{"tag"}, "docker-archive", false, true},
68 } {
69 // First clean up all images and load the cache.
70 _, rmErrors := runtime.RemoveImages(ctx, nil, nil)
71 require.Nil(t, rmErrors)

Callers

nothing calls this directly

Calls 11

testNewRuntimeFunction · 0.85
PullMethod · 0.80
CloseMethod · 0.80
SaveMethod · 0.80
RemoveImagesMethod · 0.80
LoadMethod · 0.80
ListImagesMethod · 0.80
RemoveMethod · 0.65
LenMethod · 0.65
cleanupFunction · 0.50
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…