Skip to content

Commit 50b2ebc

Browse files
committed
test: refactor container_remove_windows_test.go to use Tigron
Signed-off-by: Joonsoo Won <wonjs0116@gmail.com>
1 parent 5e12bc2 commit 50b2ebc

1 file changed

Lines changed: 39 additions & 20 deletions

File tree

cmd/nerdctl/container/container_remove_windows_test.go

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,53 @@ import (
2121

2222
"gotest.tools/v3/assert"
2323

24+
"github.com/containerd/nerdctl/mod/tigron/expect"
25+
"github.com/containerd/nerdctl/mod/tigron/test"
26+
2427
"github.com/containerd/nerdctl/v2/pkg/testutil"
28+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
2529
)
2630

2731
func TestRemoveHyperVContainer(t *testing.T) {
28-
base := testutil.NewBase(t)
29-
tID := testutil.Identifier(t)
32+
testCase := nerdtest.Setup()
33+
34+
testCase.Require = nerdtest.HyperV
35+
36+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
37+
helpers.Ensure("run", "-d", "--isolation", "hyperv", "--name", testutil.Identifier(t), testutil.CommonImage, "sleep", nerdtest.Infinity)
38+
nerdtest.EnsureContainerStarted(helpers, testutil.Identifier(t))
3039

31-
if !testutil.HyperVSupported() {
32-
t.Skip("HyperV is not enabled, skipping test")
40+
inspect := nerdtest.InspectContainer(helpers, testutil.Identifier(t))
41+
//check with HCS if the container is ineed a VM
42+
isHypervContainer, err := testutil.HyperVContainer(inspect)
43+
assert.NilError(t, err)
44+
assert.Assert(t, isHypervContainer, true)
3345
}
3446

35-
// ignore error
36-
base.Cmd("rm", tID, "-f").AssertOK()
37-
38-
base.Cmd("run", "-d", "--isolation", "hyperv", "--name", tID, testutil.NginxAlpineImage).AssertOK()
39-
defer base.Cmd("rm", tID, "-f").AssertOK()
40-
41-
base.EnsureContainerStarted(tID)
42-
inspect := base.InspectContainer(tID)
43-
//check with HCS if the container is ineed a VM
44-
isHypervContainer, err := testutil.HyperVContainer(inspect)
45-
if err != nil {
46-
t.Fatalf("unable to list HCS containers: %s", err)
47+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
48+
helpers.Anyhow("rm", "-f", testutil.Identifier(t))
4749
}
4850

49-
assert.Assert(t, isHypervContainer, true)
50-
base.Cmd("rm", tID).AssertFail()
51+
testCase.SubTests = []*test.Case{
52+
{
53+
Description: "should fail to remove when still running",
54+
NoParallel: true,
55+
Command: test.Command("rm", testutil.Identifier(t)),
56+
Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil),
57+
},
58+
{
59+
Description: "should kill the container",
60+
NoParallel: true,
61+
Command: test.Command("kill", testutil.Identifier(t)),
62+
Expected: test.Expects(expect.ExitCodeSuccess, nil, nil),
63+
},
64+
{
65+
Description: "should remove the container when terminated",
66+
NoParallel: true,
67+
Command: test.Command("rm", testutil.Identifier(t)),
68+
Expected: test.Expects(expect.ExitCodeSuccess, nil, nil),
69+
},
70+
}
5171

52-
base.Cmd("kill", tID).AssertOK()
53-
base.Cmd("rm", tID).AssertOK()
72+
testCase.Run(t)
5473
}

0 commit comments

Comments
 (0)