(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestPush(t *testing.T) { |
| 14 | runtime, cleanup := testNewRuntime(t) |
| 15 | defer cleanup() |
| 16 | ctx := context.Background() |
| 17 | |
| 18 | // Prefetch alpine. |
| 19 | pullOptions := &PullOptions{} |
| 20 | pullOptions.Writer = os.Stdout |
| 21 | _, err := runtime.Pull(ctx, "docker.io/library/alpine:latest", config.PullPolicyAlways, pullOptions) |
| 22 | require.NoError(t, err) |
| 23 | |
| 24 | pushOptions := &PushOptions{} |
| 25 | pushOptions.Writer = os.Stdout |
| 26 | |
| 27 | workdir, err := ioutil.TempDir("", "libimagepush") |
| 28 | require.NoError(t, err) |
| 29 | defer os.RemoveAll(workdir) |
| 30 | |
| 31 | for _, test := range []struct { |
| 32 | source string |
| 33 | destination string |
| 34 | expectError bool |
| 35 | }{ |
| 36 | {"alpine", "dir:" + workdir + "/dir", false}, |
| 37 | {"alpine", "oci:" + workdir + "/oci", false}, |
| 38 | {"alpine", "oci-archive:" + workdir + "/oci-archive", false}, |
| 39 | {"alpine", "docker-archive:" + workdir + "/docker-archive", false}, |
| 40 | {"alpine", "containers-storage:localhost/another:alpine", false}, |
| 41 | } { |
| 42 | _, err := runtime.Push(ctx, test.source, test.destination, pushOptions) |
| 43 | if test.expectError { |
| 44 | require.Error(t, err, "%v", test) |
| 45 | continue |
| 46 | } |
| 47 | require.NoError(t, err, "%v", test) |
| 48 | pulledImages, err := runtime.Pull(ctx, test.destination, config.PullPolicyAlways, pullOptions) |
| 49 | require.NoError(t, err, "%v", test) |
| 50 | require.Len(t, pulledImages, 1, "%v", test) |
| 51 | } |
| 52 | |
| 53 | // Now there should only be two images: alpine in Docker format and |
| 54 | // alpine in OCI format. |
| 55 | listedImages, err := runtime.ListImages(ctx, nil, nil) |
| 56 | require.NoError(t, err, "error listing images") |
| 57 | require.Len(t, listedImages, 2, "there should only be two images (alpine in Docke/OCI)") |
| 58 | |
| 59 | // And now remove all of them. |
| 60 | rmReports, rmErrors := runtime.RemoveImages(ctx, nil, nil) |
| 61 | require.Len(t, rmErrors, 0) |
| 62 | require.Len(t, rmReports, 2) |
| 63 | |
| 64 | for i, image := range listedImages { |
| 65 | require.Equal(t, image.ID(), rmReports[i].ID) |
| 66 | require.True(t, rmReports[i].Removed) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestPushOtherPlatform(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…