|
| 1 | +/* |
| 2 | + Copyright The containerd Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package manifest |
| 18 | + |
| 19 | +import ( |
| 20 | + "errors" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/containerd/nerdctl/mod/tigron/test" |
| 24 | + |
| 25 | + "github.com/containerd/nerdctl/v2/pkg/testutil" |
| 26 | + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" |
| 27 | +) |
| 28 | + |
| 29 | +func TestManifestsRemove(t *testing.T) { |
| 30 | + testCase := nerdtest.Setup() |
| 31 | + manifestListName1 := "example.com/test-list-remove:v1" |
| 32 | + manifestListName2 := "example.com/test-list-remove:v2" |
| 33 | + manifestRef1 := testutil.GetTestImageWithoutTag("alpine") + "@" + testutil.GetTestImageManifestDigest("alpine", "linux/amd64") |
| 34 | + manifestRef2 := testutil.GetTestImageWithoutTag("alpine") + "@" + testutil.GetTestImageManifestDigest("alpine", "linux/arm64") |
| 35 | + |
| 36 | + testCase.SubTests = []*test.Case{ |
| 37 | + { |
| 38 | + Description: "remove-several-manifestlists", |
| 39 | + Setup: func(data test.Data, helpers test.Helpers) { |
| 40 | + cmd := helpers.Command("manifest", "create", manifestListName1, manifestRef1) |
| 41 | + cmd.Run(&test.Expected{ExitCode: 0}) |
| 42 | + cmd = helpers.Command("manifest", "create", manifestListName2, manifestRef2) |
| 43 | + cmd.Run(&test.Expected{ExitCode: 0}) |
| 44 | + }, |
| 45 | + Command: test.Command("manifest", "rm", manifestListName1, manifestListName2), |
| 46 | + Expected: func(data test.Data, helpers test.Helpers) *test.Expected { |
| 47 | + return &test.Expected{ |
| 48 | + ExitCode: 0, |
| 49 | + } |
| 50 | + }, |
| 51 | + }, |
| 52 | + { |
| 53 | + Description: "remove-non-existent-manifestlist", |
| 54 | + Command: test.Command("manifest", "rm", "example.com/non-existent:latest"), |
| 55 | + Expected: func(data test.Data, helpers test.Helpers) *test.Expected { |
| 56 | + return &test.Expected{ |
| 57 | + ExitCode: 1, |
| 58 | + Errors: []error{errors.New(data.Labels().Get("error"))}, |
| 59 | + } |
| 60 | + }, |
| 61 | + Data: test.WithLabels(map[string]string{ |
| 62 | + "error": "No such manifest: example.com/non-existent:latest", |
| 63 | + }), |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + testCase.Run(t) |
| 68 | +} |
0 commit comments