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

Function TestPull

libimage/pull_test.go:15–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestPull(t *testing.T) {
16 runtime, cleanup := testNewRuntime(t)
17 defer cleanup()
18 ctx := context.Background()
19 pullOptions := &PullOptions{}
20 pullOptions.Writer = os.Stdout
21
22 // Make sure that parsing errors of the daemon transport are returned
23 // and that we do not fallthrough attempting to pull the specified
24 // string as an image from a registry.
25 _, err := runtime.Pull(ctx, "docker-daemon:alpine", config.PullPolicyAlways, pullOptions)
26 require.Error(t, err, "return parsing error from daemon transport")
27
28 for _, test := range []struct {
29 input string
30 expectError bool
31 numImages int
32 names []string
33 }{
34 // DOCKER ARCHIVE
35 {"docker-archive:testdata/docker-name-only.tar.xz", false, 1, []string{"localhost/pretty-empty:latest"}},
36 {"docker-archive:testdata/docker-registry-name.tar.xz", false, 1, []string{"example.com/empty:latest"}},
37 {"docker-archive:testdata/docker-two-names.tar.xz", false, 2, []string{"example.com/empty:latest", "localhost/pretty-empty:latest"}},
38 {"docker-archive:testdata/docker-two-images.tar.xz", true, 0, nil}, // LOAD must be used here
39 {"docker-archive:testdata/docker-unnamed.tar.xz", false, 1, []string{"ec9293436c2e66da44edb9efb8d41f6b13baf62283ebe846468bc992d76d7951"}},
40
41 // OCI ARCHIVE
42 {"oci-archive:testdata/oci-name-only.tar.gz", false, 1, []string{"localhost/pretty-empty:latest"}},
43 {"oci-archive:testdata/oci-non-docker-name.tar.gz", true, 0, nil},
44 {"oci-archive:testdata/oci-registry-name.tar.gz", false, 1, []string{"example.com/empty:latest"}},
45 {"oci-archive:testdata/oci-unnamed.tar.gz", false, 1, []string{"5c8aca8137ac47e84c69ae93ce650ce967917cc001ba7aad5494073fac75b8b6"}},
46
47 // REGISTRY
48 {"alpine", false, 1, []string{"docker.io/library/alpine:latest"}},
49 {"docker://alpine", false, 1, []string{"docker.io/library/alpine:latest"}},
50 {"docker.io/library/alpine", false, 1, []string{"docker.io/library/alpine:latest"}},
51 {"docker://docker.io/library/alpine", false, 1, []string{"docker.io/library/alpine:latest"}},
52 {"quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00", false, 1, []string{"quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00"}},
53 {"quay.io/libpod/alpine:pleaseignorethistag@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00", false, 1, []string{"quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00"}},
54
55 // DIR
56 {"dir:testdata/scratch-dir-5pec!@L", false, 1, []string{"61e17f84d763cc086d43c67dcf4cdbd69f9224c74e961c53b589b70499eac443"}},
57 } {
58 pulledImages, err := runtime.Pull(ctx, test.input, config.PullPolicyAlways, pullOptions)
59 if test.expectError {
60 require.Error(t, err, test.input)
61 continue
62 }
63 require.NoError(t, err, test.input)
64 require.Len(t, pulledImages, test.numImages)
65
66 // Now lookup an image with the expected name and compare IDs.
67 image, resolvedName, err := runtime.LookupImage(test.names[0], nil)
68 require.NoError(t, err, test.input)
69 require.Equal(t, test.names[0], resolvedName, fmt.Sprintf("%v", image.Names()))
70 require.Equal(t, pulledImages[0].ID(), image.ID(), test.input)
71
72 // Now remove the image.

Callers

nothing calls this directly

Calls 9

testNewRuntimeFunction · 0.85
PullMethod · 0.80
LookupImageMethod · 0.80
NamesMethod · 0.80
RemoveImagesMethod · 0.80
LenMethod · 0.65
cleanupFunction · 0.50
ErrorMethod · 0.45
IDMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…