Skip to content

Commit dbf3752

Browse files
committed
manifest: add unit tests for nerdctl manifest annotate command
add unit tests for nerdctl manifest annotate command Signed-off-by: ChengyuZhu6 <[email protected]>
1 parent 8a29d0a commit dbf3752

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 TestManifestAnnotateErrors(t *testing.T) {
30+
testCase := nerdtest.Setup()
31+
manifestListName := "test-list:v1"
32+
manifestName := "example.com/alpine:latest"
33+
invalidName := "invalid/name/with/special@chars"
34+
testCase.SubTests = []*test.Case{
35+
{
36+
Description: "too-few-arguments",
37+
Command: test.Command("manifest", "annotate", manifestListName),
38+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
39+
return &test.Expected{
40+
ExitCode: 1,
41+
}
42+
},
43+
},
44+
{
45+
Description: "invalid-list-name",
46+
Command: test.Command("manifest", "annotate", invalidName, manifestName),
47+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
48+
return &test.Expected{
49+
ExitCode: 1,
50+
Errors: []error{errors.New(data.Labels().Get("error"))},
51+
}
52+
},
53+
Data: test.WithLabels(map[string]string{
54+
"error": "invalid reference format",
55+
}),
56+
},
57+
{
58+
Description: "invalid-manifest-reference",
59+
Command: test.Command("manifest", "annotate", manifestListName, invalidName),
60+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
61+
return &test.Expected{
62+
ExitCode: 1,
63+
Errors: []error{errors.New(data.Labels().Get("error"))},
64+
}
65+
},
66+
Data: test.WithLabels(map[string]string{
67+
"error": "invalid reference format",
68+
}),
69+
},
70+
}
71+
72+
testCase.Run(t)
73+
}
74+
75+
func TestManifestAnnotate(t *testing.T) {
76+
testCase := nerdtest.Setup()
77+
manifestListName := "example.com/test-list-annotate:v1"
78+
manifestRef := testutil.GetTestImageWithoutTag("alpine") + "@" + testutil.GetTestImageManifestDigest("alpine", "linux/amd64")
79+
80+
testCase.SubTests = []*test.Case{
81+
{
82+
Description: "annotate-non-existent-manifest",
83+
Setup: func(data test.Data, helpers test.Helpers) {
84+
cmd := helpers.Command("manifest", "create", manifestListName, manifestRef)
85+
cmd.Run(&test.Expected{ExitCode: 0})
86+
},
87+
Command: test.Command("manifest", "annotate", manifestListName, "example.com/fake:0.0"),
88+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
89+
return &test.Expected{
90+
ExitCode: 1,
91+
Errors: []error{errors.New(data.Labels().Get("error"))},
92+
}
93+
},
94+
Data: test.WithLabels(map[string]string{
95+
"error": "manifest for image example.com/fake:0.0 does not exist",
96+
}),
97+
},
98+
{
99+
Description: "annotate-success",
100+
Setup: func(data test.Data, helpers test.Helpers) {
101+
cmd := helpers.Command("manifest", "create", manifestListName+"-success", manifestRef)
102+
cmd.Run(&test.Expected{ExitCode: 0})
103+
},
104+
Command: test.Command("manifest", "annotate",
105+
manifestListName+"-success",
106+
manifestRef,
107+
"--os", "freebsd",
108+
"--arch", "arm",
109+
"--os-version", "1",
110+
"--os-features", "feature1",
111+
"--variant", "v7"),
112+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
113+
return &test.Expected{
114+
ExitCode: 0,
115+
}
116+
},
117+
},
118+
}
119+
120+
testCase.Run(t)
121+
}

0 commit comments

Comments
 (0)