Skip to content

Commit bc0739d

Browse files
authored
Merge pull request containerd#3612 from apostasie/series-10
Rewrite container_top tests
2 parents ace5548 + 4760ee9 commit bc0739d

File tree

4 files changed

+92
-97
lines changed

4 files changed

+92
-97
lines changed

cmd/nerdctl/container/container_commit_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ func TestCommit(t *testing.T) {
3636
helpers.Anyhow("rmi", "-f", data.Identifier())
3737
},
3838
Setup: func(data test.Data, helpers test.Helpers) {
39-
// FIXME: short of pulling first, docker will fail to start the container.
40-
// Debugging shows container exited immediately. Nothing in the container logs. Not much in journalctl.
41-
// It is not clear what is happening.
42-
if nerdtest.IsDocker() {
43-
helpers.Ensure("pull", testutil.CommonImage)
44-
}
4539
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
46-
nerdtest.EnsureContainerStarted(helpers, data.Identifier())
4740
helpers.Ensure("exec", data.Identifier(), "sh", "-euxc", `echo hello-test-commit > /foo`)
4841
},
4942
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 container
18+
19+
import (
20+
"runtime"
21+
"testing"
22+
23+
"github.com/containerd/nerdctl/v2/pkg/testutil"
24+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
25+
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
26+
)
27+
28+
func TestTop(t *testing.T) {
29+
testCase := nerdtest.Setup()
30+
31+
//more details https://github.com/containerd/nerdctl/pull/223#issuecomment-851395178
32+
if runtime.GOOS == "linux" {
33+
testCase.Require = nerdtest.CgroupsAccessible
34+
}
35+
36+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
37+
// FIXME: busybox 1.36 on windows still appears to not support sleep inf. Unclear why.
38+
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "10")
39+
data.Set("cID", data.Identifier())
40+
}
41+
42+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
43+
helpers.Anyhow("rm", "-f", data.Identifier())
44+
}
45+
46+
testCase.SubTests = []*test.Case{
47+
{
48+
Description: "with o pid,user,cmd",
49+
// Docker does not support top -o
50+
Require: test.Not(nerdtest.Docker),
51+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
52+
return helpers.Command("top", data.Get("cID"), "-o", "pid,user,cmd")
53+
},
54+
55+
Expected: test.Expects(0, nil, nil),
56+
},
57+
{
58+
Description: "simple",
59+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
60+
return helpers.Command("top", data.Get("cID"))
61+
},
62+
63+
Expected: test.Expects(0, nil, nil),
64+
},
65+
}
66+
67+
testCase.Run(t)
68+
}
69+
70+
func TestTopHyperVContainer(t *testing.T) {
71+
72+
testCase := nerdtest.Setup()
73+
74+
testCase.Require = nerdtest.HyperV
75+
76+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
77+
// FIXME: busybox 1.36 on windows still appears to not support sleep inf. Unclear why.
78+
helpers.Ensure("run", "--isolation", "hyperv", "-d", "--name", data.Identifier("container"), testutil.CommonImage, "sleep", "10")
79+
}
80+
81+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
82+
helpers.Anyhow("rm", "-f", data.Identifier("container"))
83+
}
84+
85+
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
86+
return helpers.Command("top", data.Identifier("container"))
87+
}
88+
89+
testCase.Expected = test.Expects(0, nil, nil)
90+
91+
testCase.Run(t)
92+
}

cmd/nerdctl/container/container_top_unix_test.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

cmd/nerdctl/container/container_top_windows_test.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)