Skip to content

Commit 4dd9ad9

Browse files
committed
Follow-up to #4012: address tests issues
Signed-off-by: apostasie <[email protected]>
1 parent 8d7539a commit 4dd9ad9

28 files changed

+165
-180
lines changed

.github/workflows/workflow-test.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,32 +209,24 @@ jobs:
209209
target: rootless
210210
runner: "ubuntu-22.04"
211211
arch: amd64
212-
nerdctl: ""
213-
comment: ""
214212
- ubuntu: 24.04
215213
containerd: v2.0.5
216214
rootlesskit: v2.3.4
217215
target: rootless
218216
arch: amd64
219217
runner: "ubuntu-24.04"
220-
nerdctl: ""
221-
comment: ""
222218
- ubuntu: 24.04
223219
containerd: v2.0.5
224220
rootlesskit: v2.3.4
225221
target: rootless
226222
arch: arm64
227223
runner: "ubuntu-24.04-arm"
228-
nerdctl: ""
229-
comment: ""
230224
- ubuntu: 24.04
231225
containerd: v2.0.5
232226
rootlesskit: v2.3.4
233227
target: rootless-port-slirp4netns
234228
arch: amd64
235229
runner: "ubuntu-24.04"
236-
nerdctl: ""
237-
comment: ""
238230
- ubuntu: 24.04
239231
containerd: v2.0.5
240232
rootlesskit: v2.3.4
@@ -296,10 +288,10 @@ jobs:
296288
fi
297289
echo "WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622}" >> "$GITHUB_ENV"
298290
- name: "Test (network driver=slirp4netns, port driver=builtin)"
299-
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} -e NERDCTL=${NERDCTL} ${TEST_TARGET} /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky=false
291+
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET} /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky=false -test.target=${NERDCTL}
300292
- name: "Test (network driver=slirp4netns, port driver=builtin) (flaky)"
301293
if: matrix.nerdctl != 'nerdctl.gomodjail'
302-
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} -e NERDCTL=${NERDCTL} ${TEST_TARGET} /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky=true
294+
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET} /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky=true -test.target=${NERDCTL}
303295

304296
test-integration-docker-compatibility:
305297
timeout-minutes: 40

Dockerfile.d/test-integration-rootless.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# limitations under the License.
1616

1717
set -eux -o pipefail
18-
: "${NERDCTL:=}"
1918
if [[ "$(id -u)" = "0" ]]; then
2019
# Ensure securityfs is mounted for apparmor to work
2120
if ! mountpoint -q /sys/kernel/security; then
@@ -33,7 +32,7 @@ if [[ "$(id -u)" = "0" ]]; then
3332

3433
# Switch to the rootless user via SSH
3534
systemctl start ssh
36-
exec ssh -o StrictHostKeyChecking=no rootless@localhost NERDCTL="$NERDCTL" "$0" "$@"
35+
exec ssh -o StrictHostKeyChecking=no rootless@localhost "$0" "$@"
3736
else
3837
containerd-rootless-setuptool.sh install
3938
if grep -q "options use-vc" /etc/resolv.conf; then
@@ -64,5 +63,5 @@ EOF
6463
# Once ssh-ed, we lost the Dockerfile working dir, so, get back in the nerdctl checkout
6564
cd /go/src/github.com/containerd/nerdctl
6665
# We also lose the PATH (and SendEnv=PATH would require sshd config changes)
67-
exec env PATH="/usr/local/go/bin:$PATH" NERDCTL="$NERDCTL" "$@"
66+
exec env PATH="/usr/local/go/bin:$PATH" "$@"
6867
fi

cmd/nerdctl/builder/builder_builder_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ CMD ["echo", "nerdctl-test-builder-prune"]`, testutil.CommonImage)
133133
{
134134
Description: "Debug",
135135
// `nerdctl builder debug` is currently incompatible with `docker buildx debug`.
136-
// FIXME: fails with gomodjail: "timed out to access cache storage. other debug session is running?"
137-
Require: require.All(require.Not(nerdtest.Docker), require.Not(nerdtest.Gomodjail)),
136+
Require: require.All(require.Not(nerdtest.Docker)),
138137
NoParallel: true,
139138
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
140139
dockerfile := fmt.Sprintf(`FROM %s

cmd/nerdctl/completion/completion_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package completion
1818

1919
import (
20+
"os/exec"
2021
"testing"
2122

2223
"github.com/containerd/nerdctl/mod/tigron/expect"
@@ -34,6 +35,11 @@ func TestMain(m *testing.M) {
3435
func TestCompletion(t *testing.T) {
3536
nerdtest.Setup()
3637

38+
// Note: some functions need to be tested without the automatic --namespace nerdctl-test argument, so we need
39+
// to retrieve the binary name.
40+
// Note that we know this works already, so no need to assert err.
41+
bin, _ := exec.LookPath(testutil.GetTarget())
42+
3743
testCase := &test.Case{
3844
Require: require.Not(nerdtest.Docker),
3945
Setup: func(data test.Data, helpers test.Helpers) {
@@ -158,25 +164,25 @@ func TestCompletion(t *testing.T) {
158164
},
159165
},
160166
{
161-
Description: "no namespace --cgroup-manager",
167+
Description: "--cgroup-manager",
162168
Require: require.Not(require.Windows),
163169
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
164-
return helpers.Custom("nerdctl", "__complete", "--cgroup-manager", "")
170+
return helpers.Command("__complete", "--cgroup-manager", "")
165171
},
166172
Expected: test.Expects(0, nil, expect.Contains("cgroupfs\n")),
167173
},
168174
{
169-
Description: "no namespace empty",
175+
Description: "empty",
170176
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
171-
return helpers.Custom("nerdctl", "__complete", "")
177+
return helpers.Command("__complete", "")
172178
},
173179
Expected: test.Expects(0, nil, expect.Contains("run\t")),
174180
},
175181
{
176182
Description: "namespace space empty",
177183
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
178184
// mind {"--namespace=nerdctl-test"} vs {"--namespace", "nerdctl-test"}
179-
return helpers.Custom("nerdctl", "__complete", "--namespace", string(helpers.Read(nerdtest.Namespace)), "")
185+
return helpers.Custom(bin, "__complete", "--namespace", string(helpers.Read(nerdtest.Namespace)), "")
180186
},
181187
Expected: test.Expects(0, nil, expect.Contains("run\t")),
182188
},
@@ -199,7 +205,7 @@ func TestCompletion(t *testing.T) {
199205
Description: "namespace run -i",
200206
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
201207
// mind {"--namespace=nerdctl-test"} vs {"--namespace", "nerdctl-test"}
202-
return helpers.Custom("nerdctl", "__complete", "--namespace", string(helpers.Read(nerdtest.Namespace)), "run", "-i", "")
208+
return helpers.Custom(bin, "__complete", "--namespace", string(helpers.Read(nerdtest.Namespace)), "run", "-i", "")
203209
},
204210
Expected: test.Expects(0, nil, expect.Contains(testutil.CommonImage+"\n")),
205211
},

cmd/nerdctl/compose/compose_up_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"gotest.tools/v3/icmd"
2828

2929
"github.com/containerd/nerdctl/v2/pkg/testutil"
30+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3031
)
3132

3233
// https://github.com/containerd/nerdctl/issues/1942
@@ -49,7 +50,8 @@ services:
4950
ExitCode: 1,
5051
Err: `exec: \"invalid\": executable file not found in $PATH`,
5152
}
52-
if base.Target == testutil.Docker {
53+
// Docker expected err is different
54+
if nerdtest.IsDocker() {
5355
expected.Err = `unknown or invalid runtime name: invalid`
5456
}
5557
c.Assert(expected)

cmd/nerdctl/container/container_cp_acid_linux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/containerd/nerdctl/v2/pkg/containerutil"
2929
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
3030
"github.com/containerd/nerdctl/v2/pkg/testutil"
31+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3132
)
3233

3334
// This is a separate set of tests for cp specifically meant to test corner or extreme cases that do not fit in the normal testing rig
@@ -87,7 +88,7 @@ func TestCopyAcid(t *testing.T) {
8788
setup()
8889

8990
expectedErr := containerutil.ErrTargetIsReadOnly.Error()
90-
if testutil.GetTarget() == testutil.Docker {
91+
if nerdtest.IsDocker() {
9192
expectedErr = ""
9293
}
9394

cmd/nerdctl/container/container_cp_linux_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/containerd/nerdctl/v2/pkg/containerutil"
3131
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
3232
"github.com/containerd/nerdctl/v2/pkg/testutil"
33+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3334
)
3435

3536
// For the test matrix, see https://docs.docker.com/engine/reference/commandline/cp/
@@ -898,7 +899,7 @@ func cpTestHelper(t *testing.T, tg *testgroup) {
898899
setup()
899900

900901
// If Docker, removes the err part of expectation
901-
if testutil.GetTarget() == testutil.Docker {
902+
if nerdtest.IsDocker() {
902903
testCase.expect.Err = ""
903904
}
904905

@@ -938,7 +939,7 @@ func cpTestHelper(t *testing.T, tg *testgroup) {
938939
cmd = base.Cmd("cp", containerStopped+":"+sourceSpec, destinationSpec)
939940
}
940941

941-
if rootlessutil.IsRootless() && testutil.GetTarget() == testutil.Nerdctl {
942+
if rootlessutil.IsRootless() && !nerdtest.IsDocker() {
942943
cmd.Assert(
943944
icmd.Expected{
944945
ExitCode: 1,

cmd/nerdctl/container/container_create_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestCreateWithMACAddress(t *testing.T) {
126126
assert.Assert(t, strings.Contains(res.Stdout(), expect), fmt.Sprintf("expected output to contain %q: %q", expect, res.Stdout()))
127127
assert.Assert(t, res.ExitCode == 0, "Command should have succeeded")
128128
} else {
129-
if testutil.GetTarget() == testutil.Docker &&
129+
if nerdtest.IsDocker() &&
130130
(network == networkIPvlan || network == "container:whatever"+tID) {
131131
// unlike nerdctl
132132
// when using network ipvlan or container in Docker
@@ -137,7 +137,7 @@ func TestCreateWithMACAddress(t *testing.T) {
137137
}
138138

139139
// See https://github.com/containerd/nerdctl/issues/3101
140-
if testutil.GetTarget() == testutil.Docker &&
140+
if nerdtest.IsDocker() &&
141141
(network == networkBridge) {
142142
expect = ""
143143
}

cmd/nerdctl/container/container_inspect_linux_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestContainerInspectState(t *testing.T) {
198198
// nerdctl: run error produces a nil Task, so the Status is empty because Status comes from Task.
199199
// docker : run error gives => `Status=created` as in docker there is no a separation between container and Task.
200200
errStatus := ""
201-
if base.Target == testutil.Docker {
201+
if nerdtest.IsDocker() {
202202
errStatus = "created"
203203
}
204204
testCases := []testCase{
@@ -295,7 +295,7 @@ func TestContainerInspectHostConfigDefaults(t *testing.T) {
295295

296296
// Hostconfig default values differ with Docker.
297297
// This is because we directly retrieve the configured values instead of using preset defaults.
298-
if testutil.GetTarget() == testutil.Docker {
298+
if nerdtest.IsDocker() {
299299
hc.Driver = ""
300300
hc.GroupAddSize = 0
301301
hc.ShmSize = int64(67108864) // Docker default 64M
@@ -399,7 +399,7 @@ func TestContainerInspectHostConfigPID(t *testing.T) {
399399

400400
var hc hostConfigValues
401401

402-
if testutil.GetTarget() == testutil.Docker {
402+
if nerdtest.IsDocker() {
403403
hc.PidMode = "container:" + containerID1
404404
} else {
405405
hc.PidMode = containerID1
@@ -444,7 +444,7 @@ func TestContainerInspectDevices(t *testing.T) {
444444
t.Fatal(err)
445445
}
446446

447-
if testutil.GetTarget() == testutil.Docker {
447+
if nerdtest.IsDocker() {
448448
dir = "/dev/zero"
449449
}
450450

cmd/nerdctl/container/container_kill_linux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
2828
"github.com/containerd/nerdctl/v2/pkg/testutil"
2929
iptablesutil "github.com/containerd/nerdctl/v2/pkg/testutil/iptables"
30+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3031
)
3132

3233
// TestKillCleanupForwards runs a container that exposes a port and then kill it.
@@ -66,7 +67,7 @@ func TestKillCleanupForwards(t *testing.T) {
6667

6768
// define iptables chain name depending on the target (docker/nerdctl)
6869
var chain string
69-
if testutil.GetTarget() == testutil.Docker {
70+
if nerdtest.IsDocker() {
7071
chain = "DOCKER"
7172
} else {
7273
redirectChain := "CNI-HOSTPORT-DNAT"

0 commit comments

Comments
 (0)