(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestLoad(t *testing.T) { |
| 12 | runtime, cleanup := testNewRuntime(t) |
| 13 | defer cleanup() |
| 14 | ctx := context.Background() |
| 15 | loadOptions := &LoadOptions{} |
| 16 | loadOptions.Writer = os.Stdout |
| 17 | |
| 18 | for _, test := range []struct { |
| 19 | input string |
| 20 | expectError bool |
| 21 | numImages int |
| 22 | names []string |
| 23 | }{ |
| 24 | // DOCKER ARCHIVE |
| 25 | {"testdata/docker-name-only.tar.xz", false, 1, []string{"localhost/pretty-empty:latest"}}, |
| 26 | {"testdata/docker-registry-name.tar.xz", false, 1, []string{"example.com/empty:latest"}}, |
| 27 | {"testdata/docker-two-names.tar.xz", false, 1, []string{"localhost/pretty-empty:latest", "example.com/empty:latest"}}, |
| 28 | {"testdata/docker-two-images.tar.xz", false, 2, []string{"example.com/empty:latest", "example.com/empty/but:different"}}, |
| 29 | {"testdata/docker-unnamed.tar.xz", false, 1, []string{"sha256:ec9293436c2e66da44edb9efb8d41f6b13baf62283ebe846468bc992d76d7951"}}, |
| 30 | {"testdata/buildkit-docker.tar", false, 1, []string{"github.com/buildkit/archive:docker"}}, |
| 31 | |
| 32 | // OCI ARCHIVE |
| 33 | {"testdata/oci-name-only.tar.gz", false, 1, []string{"localhost/pretty-empty:latest"}}, |
| 34 | {"testdata/oci-non-docker-name.tar.gz", true, 0, nil}, |
| 35 | {"testdata/oci-registry-name.tar.gz", false, 1, []string{"example.com/empty:latest"}}, |
| 36 | {"testdata/oci-unnamed.tar.gz", false, 1, []string{"sha256:5c8aca8137ac47e84c69ae93ce650ce967917cc001ba7aad5494073fac75b8b6"}}, |
| 37 | {"testdata/buildkit-oci.tar", false, 1, []string{"github.com/buildkit/archive:oci"}}, |
| 38 | } { |
| 39 | loadedImages, err := runtime.Load(ctx, test.input, loadOptions) |
| 40 | if test.expectError { |
| 41 | require.Error(t, err, test.input) |
| 42 | continue |
| 43 | } |
| 44 | require.NoError(t, err, test.input) |
| 45 | require.Equal(t, test.names, loadedImages, test.input) |
| 46 | |
| 47 | // Make sure that all returned names exist as images in the |
| 48 | // local containers storage. |
| 49 | ids := []string{} // later used for image removal |
| 50 | names := [][]string{} |
| 51 | for _, name := range loadedImages { |
| 52 | image, resolvedName, err := runtime.LookupImage(name, nil) |
| 53 | require.NoError(t, err, test.input) |
| 54 | require.Equal(t, name, resolvedName, test.input) |
| 55 | ids = append(ids, image.ID()) |
| 56 | names = append(names, image.Names()) |
| 57 | } |
| 58 | |
| 59 | // Now remove the image. |
| 60 | rmReports, rmErrors := runtime.RemoveImages(ctx, ids, &RemoveImagesOptions{Force: true}) |
| 61 | require.Len(t, rmErrors, 0) |
| 62 | require.Len(t, rmReports, test.numImages) |
| 63 | |
| 64 | // Now inspect the removal reports. |
| 65 | for i, report := range rmReports { |
| 66 | require.Equal(t, ids[i], report.ID, test.input) |
| 67 | require.Equal(t, names[i], report.Untagged, test.input) |
| 68 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…