Skip to content

Commit 1a0e7e9

Browse files
committed
checkpoint: add unit test for checkpoint ls
add unit test for checkpoint ls. Signed-off-by: ChengyuZhu6 <[email protected]>
1 parent 063a07e commit 1a0e7e9

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//go:build linux
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package checkpoint
20+
21+
import (
22+
"errors"
23+
"testing"
24+
25+
"github.com/containerd/nerdctl/mod/tigron/expect"
26+
"github.com/containerd/nerdctl/mod/tigron/require"
27+
"github.com/containerd/nerdctl/mod/tigron/test"
28+
29+
"github.com/containerd/nerdctl/v2/pkg/testutil"
30+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
31+
)
32+
33+
func TestCheckpointListErrors(t *testing.T) {
34+
testCase := nerdtest.Setup()
35+
36+
testCase.Require = require.All(
37+
require.Not(nerdtest.Rootless),
38+
// Docker version 28.x has a known regression that breaks Checkpoint/Restore functionality.
39+
// The issue is tracked in the moby/moby project as https://github.com/moby/moby/issues/50750.
40+
require.Not(nerdtest.Docker),
41+
)
42+
43+
testCase.SubTests = []*test.Case{
44+
{
45+
Description: "too-few-arguments",
46+
Command: test.Command("checkpoint", "list"),
47+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
48+
return &test.Expected{ExitCode: 1}
49+
},
50+
},
51+
{
52+
Description: "too-many-arguments",
53+
Command: test.Command("checkpoint", "list", "too", "many", "arguments"),
54+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
55+
return &test.Expected{ExitCode: 1}
56+
},
57+
},
58+
{
59+
Description: "invalid-container-id",
60+
Command: test.Command("checkpoint", "list", "no-such-container"),
61+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
62+
return &test.Expected{
63+
ExitCode: 1,
64+
Errors: []error{errors.New("error list checkpoint for container: no-such-container")},
65+
}
66+
},
67+
},
68+
}
69+
70+
testCase.Run(t)
71+
}
72+
73+
func TestCheckpointList(t *testing.T) {
74+
const checkpointName = "checkpoint-list"
75+
76+
testCase := nerdtest.Setup()
77+
testCase.Require = require.All(
78+
require.Not(nerdtest.Rootless),
79+
// Docker version 28.x has a known regression that breaks Checkpoint/Restore functionality.
80+
// The issue is tracked in the moby/moby project as https://github.com/moby/moby/issues/50750.
81+
require.Not(nerdtest.Docker),
82+
)
83+
84+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
85+
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
86+
helpers.Ensure("checkpoint", "create", data.Identifier(), checkpointName)
87+
}
88+
89+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
90+
helpers.Anyhow("rm", "-f", data.Identifier())
91+
helpers.Anyhow("rmi", "-f", testutil.CommonImage)
92+
}
93+
94+
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
95+
return helpers.Command("checkpoint", "list", data.Identifier())
96+
}
97+
98+
testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected {
99+
return &test.Expected{
100+
ExitCode: 0,
101+
// First line is header, second should include the checkpoint name
102+
Output: expect.Contains("CHECKPOINT NAME\n" + checkpointName + "\n"),
103+
}
104+
}
105+
106+
testCase.Run(t)
107+
}

0 commit comments

Comments
 (0)