Skip to content

Commit 5ce1e4b

Browse files
committed
Fix parallelism for docker
Signed-off-by: apostasie <[email protected]>
1 parent 19fa3d9 commit 5ce1e4b

File tree

3 files changed

+156
-143
lines changed

3 files changed

+156
-143
lines changed

cmd/nerdctl/network/network_prune_linux_test.go

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,50 @@ import (
2727
func TestNetworkPrune(t *testing.T) {
2828
nerdtest.Setup()
2929

30-
testGroup := &test.Group{
31-
{
32-
Description: "Prune does not collect started container network",
33-
Require: nerdtest.Private,
34-
Setup: func(data test.Data, helpers test.Helpers) {
35-
helpers.Ensure("network", "create", data.Identifier())
36-
helpers.Ensure("run", "-d", "--net", data.Identifier(), "--name", data.Identifier(), testutil.NginxAlpineImage)
37-
},
38-
Cleanup: func(data test.Data, helpers test.Helpers) {
39-
helpers.Anyhow("rm", "-f", data.Identifier())
40-
helpers.Anyhow("network", "rm", data.Identifier())
41-
},
42-
Command: test.RunCommand("network", "prune", "-f"),
43-
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
44-
return &test.Expected{
45-
Output: test.DoesNotContain(data.Identifier()),
46-
}
47-
},
48-
},
49-
{
50-
Description: "Prune does collect stopped container network",
51-
Require: nerdtest.Private,
52-
Setup: func(data test.Data, helpers test.Helpers) {
53-
helpers.Ensure("network", "create", data.Identifier())
54-
helpers.Ensure("run", "-d", "--net", data.Identifier(), "--name", data.Identifier(), testutil.NginxAlpineImage)
55-
helpers.Ensure("stop", data.Identifier())
56-
},
57-
Cleanup: func(data test.Data, helpers test.Helpers) {
58-
helpers.Anyhow("rm", "-f", data.Identifier())
59-
helpers.Anyhow("network", "rm", data.Identifier())
30+
testCase := &test.Case{
31+
Description: "TestNetworkPrune",
32+
Require: nerdtest.Private,
33+
34+
SubTests: []*test.Case{
35+
{
36+
Description: "Prune does not collect started container network",
37+
NoParallel: true,
38+
Setup: func(data test.Data, helpers test.Helpers) {
39+
helpers.Ensure("network", "create", data.Identifier())
40+
helpers.Ensure("run", "-d", "--net", data.Identifier(), "--name", data.Identifier(), testutil.NginxAlpineImage)
41+
},
42+
Cleanup: func(data test.Data, helpers test.Helpers) {
43+
helpers.Anyhow("rm", "-f", data.Identifier())
44+
helpers.Anyhow("network", "rm", data.Identifier())
45+
},
46+
Command: test.RunCommand("network", "prune", "-f"),
47+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
48+
return &test.Expected{
49+
Output: test.DoesNotContain(data.Identifier()),
50+
}
51+
},
6052
},
61-
Command: test.RunCommand("network", "prune", "-f"),
62-
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
63-
return &test.Expected{
64-
Output: test.Contains(data.Identifier()),
65-
}
53+
{
54+
Description: "Prune does collect stopped container network",
55+
NoParallel: true,
56+
Setup: func(data test.Data, helpers test.Helpers) {
57+
helpers.Ensure("network", "create", data.Identifier())
58+
helpers.Ensure("run", "-d", "--net", data.Identifier(), "--name", data.Identifier(), testutil.NginxAlpineImage)
59+
helpers.Ensure("stop", data.Identifier())
60+
},
61+
Cleanup: func(data test.Data, helpers test.Helpers) {
62+
helpers.Anyhow("rm", "-f", data.Identifier())
63+
helpers.Anyhow("network", "rm", data.Identifier())
64+
},
65+
Command: test.RunCommand("network", "prune", "-f"),
66+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
67+
return &test.Expected{
68+
Output: test.Contains(data.Identifier()),
69+
}
70+
},
6671
},
6772
},
6873
}
6974

70-
testGroup.Run(t)
75+
testCase.Run(t)
7176
}

cmd/nerdctl/system/system_prune_linux_test.go

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -32,75 +32,79 @@ import (
3232
func TestSystemPrune(t *testing.T) {
3333
nerdtest.Setup()
3434

35-
testGroup := &test.Group{
36-
{
37-
Description: "volume prune all success",
38-
// Private because of prune evidently
39-
Require: nerdtest.Private,
40-
Setup: func(data test.Data, helpers test.Helpers) {
41-
helpers.Ensure("network", "create", data.Identifier())
42-
helpers.Ensure("volume", "create", data.Identifier())
43-
anonIdentifier := helpers.Capture("volume", "create")
44-
helpers.Ensure("run", "-v", fmt.Sprintf("%s:/volume", data.Identifier()),
45-
"--net", data.Identifier(), "--name", data.Identifier(), testutil.CommonImage)
35+
testCase := &test.Case{
36+
Description: "TestSystemPrune",
37+
NoParallel: true,
38+
SubTests: []*test.Case{
39+
{
40+
Description: "volume prune all success",
41+
// Private because of prune evidently
42+
Require: nerdtest.Private,
43+
Setup: func(data test.Data, helpers test.Helpers) {
44+
helpers.Ensure("network", "create", data.Identifier())
45+
helpers.Ensure("volume", "create", data.Identifier())
46+
anonIdentifier := helpers.Capture("volume", "create")
47+
helpers.Ensure("run", "-v", fmt.Sprintf("%s:/volume", data.Identifier()),
48+
"--net", data.Identifier(), "--name", data.Identifier(), testutil.CommonImage)
4649

47-
data.Set("anonIdentifier", anonIdentifier)
50+
data.Set("anonIdentifier", anonIdentifier)
51+
},
52+
Cleanup: func(data test.Data, helpers test.Helpers) {
53+
helpers.Anyhow("network", "rm", data.Identifier())
54+
helpers.Anyhow("volume", "rm", data.Identifier())
55+
helpers.Anyhow("volume", "rm", data.Get("anonIdentifier"))
56+
helpers.Anyhow("rm", "-f", data.Identifier())
57+
},
58+
Command: test.RunCommand("system", "prune", "-f", "--volumes", "--all"),
59+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
60+
return &test.Expected{
61+
ExitCode: 0,
62+
Output: func(stdout string, info string, t *testing.T) {
63+
volumes := helpers.Capture("volume", "ls")
64+
networks := helpers.Capture("network", "ls")
65+
images := helpers.Capture("images")
66+
containers := helpers.Capture("ps", "-a")
67+
assert.Assert(t, strings.Contains(volumes, data.Identifier()), volumes)
68+
assert.Assert(t, !strings.Contains(volumes, data.Get("anonIdentifier")), volumes)
69+
assert.Assert(t, !strings.Contains(containers, data.Identifier()), containers)
70+
assert.Assert(t, !strings.Contains(networks, data.Identifier()), networks)
71+
assert.Assert(t, !strings.Contains(images, testutil.CommonImage), images)
72+
},
73+
}
74+
},
4875
},
49-
Cleanup: func(data test.Data, helpers test.Helpers) {
50-
helpers.Anyhow("network", "rm", data.Identifier())
51-
helpers.Anyhow("volume", "rm", data.Identifier())
52-
helpers.Anyhow("volume", "rm", data.Get("anonIdentifier"))
53-
helpers.Anyhow("rm", "-f", data.Identifier())
54-
},
55-
Command: test.RunCommand("system", "prune", "-f", "--volumes", "--all"),
56-
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
57-
return &test.Expected{
58-
ExitCode: 0,
59-
Output: func(stdout string, info string, t *testing.T) {
60-
volumes := helpers.Capture("volume", "ls")
61-
networks := helpers.Capture("network", "ls")
62-
images := helpers.Capture("images")
63-
containers := helpers.Capture("ps", "-a")
64-
assert.Assert(t, strings.Contains(volumes, data.Identifier()), volumes)
65-
assert.Assert(t, !strings.Contains(volumes, data.Get("anonIdentifier")), volumes)
66-
assert.Assert(t, !strings.Contains(containers, data.Identifier()), containers)
67-
assert.Assert(t, !strings.Contains(networks, data.Identifier()), networks)
68-
assert.Assert(t, !strings.Contains(images, testutil.CommonImage), images)
69-
},
70-
}
71-
},
72-
},
73-
{
74-
Description: "buildkit",
75-
// FIXME: using a dedicated namespace does not work with rootful (because of buildkitd)
76-
NoParallel: true,
77-
// buildkitd is not available with docker
78-
Require: test.Require(nerdtest.Build, test.Not(nerdtest.Docker)),
79-
// FIXME: this test will happily say "green" even if the command actually fails to do its duty
80-
// if there is nothing in the build cache.
81-
// Ensure with setup here that we DO build something first
82-
Setup: func(data test.Data, helpers test.Helpers) {
83-
helpers.Ensure("system", "prune", "-f", "--volumes", "--all")
84-
},
85-
Command: func(data test.Data, helpers test.Helpers) test.Command {
86-
buildctlBinary, err := buildkitutil.BuildctlBinary()
87-
if err != nil {
88-
t.Fatal(err)
89-
}
76+
{
77+
Description: "buildkit",
78+
// FIXME: using a dedicated namespace does not work with rootful (because of buildkitd)
79+
NoParallel: true,
80+
// buildkitd is not available with docker
81+
Require: test.Require(nerdtest.Build, test.Not(nerdtest.Docker)),
82+
// FIXME: this test will happily say "green" even if the command actually fails to do its duty
83+
// if there is nothing in the build cache.
84+
// Ensure with setup here that we DO build something first
85+
Setup: func(data test.Data, helpers test.Helpers) {
86+
helpers.Ensure("system", "prune", "-f", "--volumes", "--all")
87+
},
88+
Command: func(data test.Data, helpers test.Helpers) test.Command {
89+
buildctlBinary, err := buildkitutil.BuildctlBinary()
90+
if err != nil {
91+
t.Fatal(err)
92+
}
9093

91-
host, err := buildkitutil.GetBuildkitHost(testutil.Namespace)
92-
if err != nil {
93-
t.Fatal(err)
94-
}
94+
host, err := buildkitutil.GetBuildkitHost(testutil.Namespace)
95+
if err != nil {
96+
t.Fatal(err)
97+
}
9598

96-
buildctlArgs := buildkitutil.BuildctlBaseArgs(host)
97-
buildctlArgs = append(buildctlArgs, "du")
99+
buildctlArgs := buildkitutil.BuildctlBaseArgs(host)
100+
buildctlArgs = append(buildctlArgs, "du")
98101

99-
return helpers.CustomCommand(buildctlBinary, buildctlArgs...)
102+
return helpers.CustomCommand(buildctlBinary, buildctlArgs...)
103+
},
104+
Expected: test.Expects(0, nil, test.Contains("Total:\t\t0B")),
100105
},
101-
Expected: test.Expects(0, nil, test.Contains("Total:\t\t0B")),
102106
},
103107
}
104108

105-
testGroup.Run(t)
109+
testCase.Run(t)
106110
}

cmd/nerdctl/volume/volume_prune_linux_test.go

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -56,54 +56,58 @@ func TestVolumePrune(t *testing.T) {
5656
}
5757

5858
// This set must be marked as private, since we cannot prune without interacting with other tests.
59-
testGroup := &test.Group{
60-
{
61-
Description: "prune anonymous only",
62-
Require: nerdtest.Private,
63-
Command: test.RunCommand("volume", "prune", "-f"),
64-
Setup: setup,
65-
Cleanup: cleanup,
66-
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
67-
return &test.Expected{
68-
Output: test.All(
69-
test.DoesNotContain(data.Get("anonIDBusy")),
70-
test.Contains(data.Get("anonIDDangling")),
71-
test.DoesNotContain(data.Get("namedBusy")),
72-
test.DoesNotContain(data.Get("namedDangling")),
73-
func(stdout string, info string, t *testing.T) {
74-
helpers.Ensure("volume", "inspect", data.Get("anonIDBusy"))
75-
helpers.Fail("volume", "inspect", data.Get("anonIDDangling"))
76-
helpers.Ensure("volume", "inspect", data.Get("namedBusy"))
77-
helpers.Ensure("volume", "inspect", data.Get("namedDangling"))
78-
},
79-
),
80-
}
59+
testCase := &test.Case{
60+
Description: "Prune",
61+
Require: nerdtest.Private,
62+
SubTests: []*test.Case{
63+
{
64+
Description: "prune anonymous only",
65+
NoParallel: true,
66+
Command: test.RunCommand("volume", "prune", "-f"),
67+
Setup: setup,
68+
Cleanup: cleanup,
69+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
70+
return &test.Expected{
71+
Output: test.All(
72+
test.DoesNotContain(data.Get("anonIDBusy")),
73+
test.Contains(data.Get("anonIDDangling")),
74+
test.DoesNotContain(data.Get("namedBusy")),
75+
test.DoesNotContain(data.Get("namedDangling")),
76+
func(stdout string, info string, t *testing.T) {
77+
helpers.Ensure("volume", "inspect", data.Get("anonIDBusy"))
78+
helpers.Fail("volume", "inspect", data.Get("anonIDDangling"))
79+
helpers.Ensure("volume", "inspect", data.Get("namedBusy"))
80+
helpers.Ensure("volume", "inspect", data.Get("namedDangling"))
81+
},
82+
),
83+
}
84+
},
8185
},
82-
},
83-
{
84-
Description: "prune all",
85-
Require: nerdtest.Private,
86-
Command: test.RunCommand("volume", "prune", "-f", "--all"),
87-
Setup: setup,
88-
Cleanup: cleanup,
89-
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
90-
return &test.Expected{
91-
Output: test.All(
92-
test.DoesNotContain(data.Get("anonIDBusy")),
93-
test.Contains(data.Get("anonIDDangling")),
94-
test.DoesNotContain(data.Get("namedBusy")),
95-
test.Contains(data.Get("namedDangling")),
96-
func(stdout string, info string, t *testing.T) {
97-
helpers.Ensure("volume", "inspect", data.Get("anonIDBusy"))
98-
helpers.Fail("volume", "inspect", data.Get("anonIDDangling"))
99-
helpers.Ensure("volume", "inspect", data.Get("namedBusy"))
100-
helpers.Fail("volume", "inspect", data.Get("namedDangling"))
101-
},
102-
),
103-
}
86+
{
87+
Description: "prune all",
88+
NoParallel: true,
89+
Command: test.RunCommand("volume", "prune", "-f", "--all"),
90+
Setup: setup,
91+
Cleanup: cleanup,
92+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
93+
return &test.Expected{
94+
Output: test.All(
95+
test.DoesNotContain(data.Get("anonIDBusy")),
96+
test.Contains(data.Get("anonIDDangling")),
97+
test.DoesNotContain(data.Get("namedBusy")),
98+
test.Contains(data.Get("namedDangling")),
99+
func(stdout string, info string, t *testing.T) {
100+
helpers.Ensure("volume", "inspect", data.Get("anonIDBusy"))
101+
helpers.Fail("volume", "inspect", data.Get("anonIDDangling"))
102+
helpers.Ensure("volume", "inspect", data.Get("namedBusy"))
103+
helpers.Fail("volume", "inspect", data.Get("namedDangling"))
104+
},
105+
),
106+
}
107+
},
104108
},
105109
},
106110
}
107111

108-
testGroup.Run(t)
112+
testCase.Run(t)
109113
}

0 commit comments

Comments
 (0)