From 4b765cd8c06e0a01c316ef8942eaceb67e6b9548 Mon Sep 17 00:00:00 2001 From: apostasie Date: Sat, 15 Feb 2025 22:48:35 -0800 Subject: [PATCH] Reorg test package Signed-off-by: apostasie --- .../builder/builder_build_oci_layout_test.go | 8 +- cmd/nerdctl/builder/builder_build_test.go | 75 ++++---- cmd/nerdctl/builder/builder_builder_test.go | 10 +- cmd/nerdctl/completion/completion_test.go | 79 +++++---- .../container/container_attach_linux_test.go | 16 +- .../container/container_commit_linux_test.go | 3 +- .../container/container_commit_test.go | 11 +- .../container/container_create_linux_test.go | 5 +- .../container/container_create_test.go | 14 +- cmd/nerdctl/container/container_diff_test.go | 17 +- .../container/container_exec_linux_test.go | 12 +- cmd/nerdctl/container/container_logs_test.go | 39 +++-- .../container/container_prune_linux_test.go | 3 +- .../container/container_remove_test.go | 3 +- .../container/container_restart_linux_test.go | 8 +- .../container_run_cgroup_linux_test.go | 4 +- .../container/container_run_linux_test.go | 28 +-- .../container_run_mount_linux_test.go | 1 + .../container_run_network_linux_test.go | 17 +- .../container_run_stargz_linux_test.go | 10 +- .../container/container_run_windows_test.go | 6 +- .../container/container_start_linux_test.go | 6 +- cmd/nerdctl/container/container_stats_test.go | 17 +- .../container/container_stop_linux_test.go | 6 +- cmd/nerdctl/container/container_top_test.go | 6 +- cmd/nerdctl/container/container_wait_test.go | 6 +- cmd/nerdctl/image/image_convert_linux_test.go | 26 +-- cmd/nerdctl/image/image_encrypt_linux_test.go | 10 +- cmd/nerdctl/image/image_history_test.go | 12 +- cmd/nerdctl/image/image_inspect_test.go | 10 +- cmd/nerdctl/image/image_list_test.go | 57 +++--- cmd/nerdctl/image/image_load_test.go | 19 +- cmd/nerdctl/image/image_prune_test.go | 27 +-- cmd/nerdctl/image/image_pull_linux_test.go | 35 ++-- cmd/nerdctl/image/image_push_linux_test.go | 22 +-- cmd/nerdctl/image/image_remove_test.go | 55 +++--- cmd/nerdctl/image/image_save_test.go | 11 +- cmd/nerdctl/ipfs/ipfs_compose_linux_test.go | 16 +- cmd/nerdctl/ipfs/ipfs_kubo_linux_test.go | 17 +- cmd/nerdctl/ipfs/ipfs_registry_linux_test.go | 17 +- cmd/nerdctl/ipfs/ipfs_simple_linux_test.go | 29 +-- cmd/nerdctl/issues/issues_linux_test.go | 16 +- cmd/nerdctl/issues/main_linux_test.go | 8 +- cmd/nerdctl/login/login_linux_test.go | 11 +- cmd/nerdctl/main_test.go | 20 ++- cmd/nerdctl/main_test_test.go | 14 +- .../network/network_create_linux_test.go | 6 +- cmd/nerdctl/network/network_inspect_test.go | 21 ++- .../network/network_list_linux_test.go | 3 +- .../network/network_prune_linux_test.go | 8 +- .../network/network_remove_linux_test.go | 3 +- .../system/system_events_linux_test.go | 31 ++-- cmd/nerdctl/system/system_info_test.go | 13 +- cmd/nerdctl/system/system_prune_linux_test.go | 9 +- cmd/nerdctl/volume/volume_create_test.go | 11 +- cmd/nerdctl/volume/volume_inspect_test.go | 28 +-- cmd/nerdctl/volume/volume_list_test.go | 12 +- cmd/nerdctl/volume/volume_namespace_test.go | 10 +- cmd/nerdctl/volume/volume_prune_linux_test.go | 24 +-- .../volume/volume_remove_linux_test.go | 11 +- docs/testing/tools.md | 44 +++-- go.mod | 4 +- {pkg/testutil/test => mod/tigron}/LICENSE | 0 {pkg/testutil/test => mod/tigron}/Makefile | 2 +- {pkg/testutil/test => mod/tigron}/README.md | 0 .../tigron/expect/comparators.go | 59 +++---- mod/tigron/expect/comparators_test.go | 40 +++++ mod/tigron/expect/consts.go | 24 +++ {pkg/testutil/test => mod/tigron}/go.mod | 2 +- {pkg/testutil/test => mod/tigron}/go.sum | 0 .../tigron}/hack/dev-setup-linux.sh | 0 .../tigron}/hack/dev-setup-macos.sh | 0 .../test => mod/tigron}/hack/headers/bash.txt | 0 .../tigron}/hack/headers/dockerfile.txt | 0 .../test => mod/tigron}/hack/headers/go.txt | 0 .../tigron}/hack/headers/makefile.txt | 0 .../tigron}/hack/make-lint-licenses.sh | 0 .../tigron/require}/requirement.go | 38 ++-- {pkg/testutil => mod/tigron}/test/case.go | 2 +- {pkg/testutil => mod/tigron}/test/command.go | 42 ++++- {pkg/testutil => mod/tigron}/test/config.go | 0 {pkg/testutil => mod/tigron}/test/data.go | 0 mod/tigron/test/expected.go | 35 ++++ mod/tigron/test/funct.go | 34 ++++ {pkg/testutil => mod/tigron}/test/helpers.go | 39 +---- mod/tigron/test/interfaces.go | 109 ++++++++++++ mod/tigron/test/internal/consts.go | 25 +++ .../tigron}/test/internal/pty/pty.go | 0 .../tigron}/test/internal/pty/pty_darwin.go | 0 .../tigron}/test/internal/pty/pty_freebsd.go | 0 .../tigron}/test/internal/pty/pty_linux.go | 0 .../tigron}/test/internal/pty/pty_windows.go | 0 mod/tigron/test/test.go | 34 ++++ mod/tigron/test/types.go | 45 +++++ .../test => mod/tigron/utils}/utilities.go | 2 +- pkg/testutil/nerdtest/ca/ca.go | 2 +- pkg/testutil/nerdtest/command.go | 3 +- pkg/testutil/nerdtest/registry/cesanta.go | 6 +- pkg/testutil/nerdtest/registry/common.go | 2 +- pkg/testutil/nerdtest/registry/docker.go | 3 +- pkg/testutil/nerdtest/registry/kubo.go | 3 +- pkg/testutil/nerdtest/requirements.go | 16 +- pkg/testutil/nerdtest/requirements_other.go | 2 +- pkg/testutil/nerdtest/requirements_windows.go | 3 +- pkg/testutil/nerdtest/test.go | 2 +- pkg/testutil/nerdtest/third-party.go | 3 +- pkg/testutil/nerdtest/utilities.go | 6 +- pkg/testutil/nerdtest/utilities_linux.go | 3 +- pkg/testutil/test/test.go | 165 ------------------ 109 files changed, 1078 insertions(+), 753 deletions(-) rename {pkg/testutil/test => mod/tigron}/LICENSE (100%) rename {pkg/testutil/test => mod/tigron}/Makefile (99%) rename {pkg/testutil/test => mod/tigron}/README.md (100%) rename pkg/testutil/test/expected.go => mod/tigron/expect/comparators.go (52%) create mode 100644 mod/tigron/expect/comparators_test.go create mode 100644 mod/tigron/expect/consts.go rename {pkg/testutil/test => mod/tigron}/go.mod (77%) rename {pkg/testutil/test => mod/tigron}/go.sum (100%) rename {pkg/testutil/test => mod/tigron}/hack/dev-setup-linux.sh (100%) rename {pkg/testutil/test => mod/tigron}/hack/dev-setup-macos.sh (100%) rename {pkg/testutil/test => mod/tigron}/hack/headers/bash.txt (100%) rename {pkg/testutil/test => mod/tigron}/hack/headers/dockerfile.txt (100%) rename {pkg/testutil/test => mod/tigron}/hack/headers/go.txt (100%) rename {pkg/testutil/test => mod/tigron}/hack/headers/makefile.txt (100%) rename {pkg/testutil/test => mod/tigron}/hack/make-lint-licenses.sh (100%) rename {pkg/testutil/test => mod/tigron/require}/requirement.go (68%) rename {pkg/testutil => mod/tigron}/test/case.go (99%) rename {pkg/testutil => mod/tigron}/test/command.go (79%) rename {pkg/testutil => mod/tigron}/test/config.go (100%) rename {pkg/testutil => mod/tigron}/test/data.go (100%) create mode 100644 mod/tigron/test/expected.go create mode 100644 mod/tigron/test/funct.go rename {pkg/testutil => mod/tigron}/test/helpers.go (64%) create mode 100644 mod/tigron/test/interfaces.go create mode 100644 mod/tigron/test/internal/consts.go rename {pkg/testutil => mod/tigron}/test/internal/pty/pty.go (100%) rename {pkg/testutil => mod/tigron}/test/internal/pty/pty_darwin.go (100%) rename {pkg/testutil => mod/tigron}/test/internal/pty/pty_freebsd.go (100%) rename {pkg/testutil => mod/tigron}/test/internal/pty/pty_linux.go (100%) rename {pkg/testutil => mod/tigron}/test/internal/pty/pty_windows.go (100%) create mode 100644 mod/tigron/test/test.go create mode 100644 mod/tigron/test/types.go rename {pkg/testutil/test => mod/tigron/utils}/utilities.go (98%) delete mode 100644 pkg/testutil/test/test.go diff --git a/cmd/nerdctl/builder/builder_build_oci_layout_test.go b/cmd/nerdctl/builder/builder_build_oci_layout_test.go index a3fea9b5fa5..93cc4152284 100644 --- a/cmd/nerdctl/builder/builder_build_oci_layout_test.go +++ b/cmd/nerdctl/builder/builder_build_oci_layout_test.go @@ -25,9 +25,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestBuildContextWithOCILayout(t *testing.T) { @@ -36,9 +38,9 @@ func TestBuildContextWithOCILayout(t *testing.T) { var dockerBuilderArgs []string testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(test.Windows), + require.Not(require.Windows), ), Cleanup: func(data test.Data, helpers test.Helpers) { if nerdtest.IsDocker() { diff --git a/cmd/nerdctl/builder/builder_build_test.go b/cmd/nerdctl/builder/builder_build_test.go index 407804f904d..be8bc051a67 100644 --- a/cmd/nerdctl/builder/builder_build_test.go +++ b/cmd/nerdctl/builder/builder_build_test.go @@ -27,10 +27,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/platformutil" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestBuildBasics(t *testing.T) { @@ -60,7 +63,7 @@ CMD ["echo", "nerdctl-build-test-string"]`, testutil.CommonImage) Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, { Description: "Successfully build with 'buildctx first', 'tag second'", @@ -73,7 +76,7 @@ CMD ["echo", "nerdctl-build-test-string"]`, testutil.CommonImage) Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, { Description: "Successfully build with output docker, main tag still works", @@ -86,7 +89,7 @@ CMD ["echo", "nerdctl-build-test-string"]`, testutil.CommonImage) Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, { Description: "Successfully build with output docker, name cannot be used", @@ -126,7 +129,7 @@ func TestCanBuildOnOtherPlatform(t *testing.T) { } testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, requireEmulation, ), @@ -179,7 +182,7 @@ CMD ["cat", "/hello2"]`, data.Identifier("first")) Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier("second")) }, - Expected: test.Expects(0, nil, test.Equals("hello2\n")), + Expected: test.Expects(0, nil, expect.Equals("hello2\n")), } testCase.Run(t) @@ -191,9 +194,9 @@ func TestBuildFromContainerd(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier("first")) @@ -213,7 +216,7 @@ CMD ["cat", "/hello2"]`, data.Identifier("first")) Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier("second")) }, - Expected: test.Expects(0, nil, test.Equals("hello2\n")), + Expected: test.Expects(0, nil, expect.Equals("hello2\n")), } testCase.Run(t) @@ -397,7 +400,7 @@ CMD echo $TEST_STRING Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("1\n")), + Expected: test.Expects(0, nil, expect.Equals("1\n")), }, { Description: "ArgValueOverridesDefault", @@ -410,7 +413,7 @@ CMD echo $TEST_STRING Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("2\n")), + Expected: test.Expects(0, nil, expect.Equals("2\n")), }, { Description: "EmptyArgValueOverridesDefault", @@ -423,7 +426,7 @@ CMD echo $TEST_STRING Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("\n")), + Expected: test.Expects(0, nil, expect.Equals("\n")), }, { Description: "UnsetArgKeyPreservesDefault", @@ -436,7 +439,7 @@ CMD echo $TEST_STRING Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("1\n")), + Expected: test.Expects(0, nil, expect.Equals("1\n")), }, { Description: "EnvValueOverridesDefault", @@ -452,7 +455,7 @@ CMD echo $TEST_STRING Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("3\n")), + Expected: test.Expects(0, nil, expect.Equals("3\n")), }, { Description: "EmptyEnvValueOverridesDefault", @@ -468,7 +471,7 @@ CMD echo $TEST_STRING Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("\n")), + Expected: test.Expects(0, nil, expect.Equals("\n")), }, }, } @@ -499,7 +502,7 @@ CMD ["echo", "nerdctl-build-test-string"] return helpers.Command("run", "--rm", string(imageID)) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), } testCase.Run(t) @@ -526,7 +529,7 @@ LABEL name=nerdctl-build-test-label return helpers.Command("inspect", data.Identifier(), "--format", "{{json .Config.Labels }}") }, - Expected: test.Expects(0, nil, test.Equals("{\"label\":\"test\",\"name\":\"nerdctl-build-test-label\"}\n")), + Expected: test.Expects(0, nil, expect.Equals("{\"label\":\"test\",\"name\":\"nerdctl-build-test-label\"}\n")), } testCase.Run(t) @@ -561,7 +564,7 @@ CMD ["echo", "nerdctl-build-test-string"] return helpers.Command("run", "--rm", data.Get("i1")) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, { Description: "i2", @@ -569,7 +572,7 @@ CMD ["echo", "nerdctl-build-test-string"] return helpers.Command("run", "--rm", data.Get("i2")) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, { Description: "i3", @@ -577,7 +580,7 @@ CMD ["echo", "nerdctl-build-test-string"] return helpers.Command("run", "--rm", data.Get("i3")) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, }, } @@ -589,9 +592,9 @@ func TestBuildWithContainerfile(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) @@ -608,7 +611,7 @@ CMD ["echo", "nerdctl-build-test-string"] Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), } testCase.Run(t) @@ -639,7 +642,7 @@ CMD ["echo", "containerfile"] Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("dockerfile\n")), + Expected: test.Expects(0, nil, expect.Equals("dockerfile\n")), } testCase.Run(t) @@ -665,7 +668,7 @@ CMD ["echo", "nerdctl-build-test-string"] helpers.Ensure("build", buildCtx) }, Command: test.Command("images"), - Expected: test.Expects(0, nil, test.Contains("")), + Expected: test.Expects(0, nil, expect.Contains("")), } testCase.Run(t) @@ -703,9 +706,9 @@ func TestBuildContextWithCopyFromDir(t *testing.T) { filename := "hello.txt" testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) @@ -739,9 +742,9 @@ func TestBuildSourceDateEpoch(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) @@ -772,7 +775,7 @@ CMD ["cat", "/source-date-epoch"] Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("1111111111\n")), + Expected: test.Expects(0, nil, expect.Equals("1111111111\n")), }, { Description: "2222222222", @@ -788,7 +791,7 @@ CMD ["cat", "/source-date-epoch"] Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier()) }, - Expected: test.Expects(0, nil, test.Equals("2222222222\n")), + Expected: test.Expects(0, nil, expect.Equals("2222222222\n")), }, }, } @@ -800,9 +803,9 @@ func TestBuildNetwork(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier()) @@ -861,9 +864,9 @@ func TestBuildAttestation(t *testing.T) { const testProvenanceFileName = "provenance.json" testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Cleanup: func(data test.Data, helpers test.Helpers) { if nerdtest.IsDocker() { @@ -962,7 +965,7 @@ func TestBuildAddHost(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.Build, ), Cleanup: func(data test.Data, helpers test.Helpers) { diff --git a/cmd/nerdctl/builder/builder_builder_test.go b/cmd/nerdctl/builder/builder_builder_test.go index f1092680a40..57c1a864ee3 100644 --- a/cmd/nerdctl/builder/builder_builder_test.go +++ b/cmd/nerdctl/builder/builder_builder_test.go @@ -26,9 +26,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestBuilder(t *testing.T) { @@ -36,9 +38,9 @@ func TestBuilder(t *testing.T) { testCase := &test.Case{ NoParallel: true, - Require: test.Require( + Require: require.All( nerdtest.Build, - test.Not(test.Windows), + require.Not(require.Windows), ), SubTests: []*test.Case{ { @@ -72,7 +74,7 @@ CMD ["echo", "nerdctl-test-builder-prune"]`, testutil.CommonImage) { Description: "Debug", // `nerdctl builder debug` is currently incompatible with `docker buildx debug`. - Require: test.Require(test.Not(nerdtest.Docker)), + Require: require.All(require.Not(nerdtest.Docker)), NoParallel: true, Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { dockerfile := fmt.Sprintf(`FROM %s diff --git a/cmd/nerdctl/completion/completion_test.go b/cmd/nerdctl/completion/completion_test.go index 84ba1377153..23bdf833c52 100644 --- a/cmd/nerdctl/completion/completion_test.go +++ b/cmd/nerdctl/completion/completion_test.go @@ -19,9 +19,12 @@ package completion import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestMain(m *testing.M) { @@ -32,7 +35,7 @@ func TestCompletion(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { identifier := data.Identifier() helpers.Ensure("pull", "--quiet", testutil.CommonImage) @@ -48,49 +51,49 @@ func TestCompletion(t *testing.T) { SubTests: []*test.Case{ { Description: "--cgroup-manager", - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Command: test.Command("__complete", "--cgroup-manager", ""), - Expected: test.Expects(0, nil, test.Contains("cgroupfs\n")), + Expected: test.Expects(0, nil, expect.Contains("cgroupfs\n")), }, { Description: "--snapshotter", - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Command: test.Command("__complete", "--snapshotter", ""), - Expected: test.Expects(0, nil, test.Contains("native\n")), + Expected: test.Expects(0, nil, expect.Contains("native\n")), }, { Description: "empty", Command: test.Command("__complete", ""), - Expected: test.Expects(0, nil, test.Contains("run\t")), + Expected: test.Expects(0, nil, expect.Contains("run\t")), }, { Description: "build --network", Command: test.Command("__complete", "build", "--network", ""), - Expected: test.Expects(0, nil, test.Contains("default\n")), + Expected: test.Expects(0, nil, expect.Contains("default\n")), }, { Description: "run -", Command: test.Command("__complete", "run", "-"), - Expected: test.Expects(0, nil, test.Contains("--network\t")), + Expected: test.Expects(0, nil, expect.Contains("--network\t")), }, { Description: "run --n", Command: test.Command("__complete", "run", "--n"), - Expected: test.Expects(0, nil, test.Contains("--network\t")), + Expected: test.Expects(0, nil, expect.Contains("--network\t")), }, { Description: "run --ne", Command: test.Command("__complete", "run", "--ne"), - Expected: test.Expects(0, nil, test.Contains("--network\t")), + Expected: test.Expects(0, nil, expect.Contains("--network\t")), }, { Description: "run --net", Command: test.Command("__complete", "run", "--net", ""), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains("host\n"), - test.Contains(data.Get("identifier")+"\n"), + Output: expect.All( + expect.Contains("host\n"), + expect.Contains(data.Get("identifier")+"\n"), ), } }, @@ -100,9 +103,9 @@ func TestCompletion(t *testing.T) { Command: test.Command("__complete", "run", "-it", "--net", ""), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains("host\n"), - test.Contains(data.Get("identifier")+"\n"), + Output: expect.All( + expect.Contains("host\n"), + expect.Contains(data.Get("identifier")+"\n"), ), } }, @@ -112,9 +115,9 @@ func TestCompletion(t *testing.T) { Command: test.Command("__complete", "run", "-it", "--rm", "--net", ""), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains("host\n"), - test.Contains(data.Get("identifier")+"\n"), + Output: expect.All( + expect.Contains("host\n"), + expect.Contains(data.Get("identifier")+"\n"), ), } }, @@ -122,27 +125,27 @@ func TestCompletion(t *testing.T) { { Description: "run --restart", Command: test.Command("__complete", "run", "--restart", ""), - Expected: test.Expects(0, nil, test.Contains("always\n")), + Expected: test.Expects(0, nil, expect.Contains("always\n")), }, { Description: "network --rm", Command: test.Command("__complete", "network", "rm", ""), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.DoesNotContain("host\n"), - test.Contains(data.Get("identifier")+"\n"), + Output: expect.All( + expect.DoesNotContain("host\n"), + expect.Contains(data.Get("identifier")+"\n"), ), } }, }, { Description: "run --cap-add", - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Command: test.Command("__complete", "run", "--cap-add", ""), - Expected: test.Expects(0, nil, test.All( - test.Contains("sys_admin\n"), - test.DoesNotContain("CAP_SYS_ADMIN\n"), + Expected: test.Expects(0, nil, expect.All( + expect.Contains("sys_admin\n"), + expect.DoesNotContain("CAP_SYS_ADMIN\n"), )), }, { @@ -150,7 +153,7 @@ func TestCompletion(t *testing.T) { Command: test.Command("__complete", "volume", "inspect", ""), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("identifier") + "\n"), + Output: expect.Contains(data.Get("identifier") + "\n"), } }, }, @@ -159,24 +162,24 @@ func TestCompletion(t *testing.T) { Command: test.Command("__complete", "volume", "rm", ""), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("identifier") + "\n"), + Output: expect.Contains(data.Get("identifier") + "\n"), } }, }, { Description: "no namespace --cgroup-manager", - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Custom("nerdctl", "__complete", "--cgroup-manager", "") }, - Expected: test.Expects(0, nil, test.Contains("cgroupfs\n")), + Expected: test.Expects(0, nil, expect.Contains("cgroupfs\n")), }, { Description: "no namespace empty", Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Custom("nerdctl", "__complete", "") }, - Expected: test.Expects(0, nil, test.Contains("run\t")), + Expected: test.Expects(0, nil, expect.Contains("run\t")), }, { Description: "namespace space empty", @@ -184,22 +187,22 @@ func TestCompletion(t *testing.T) { // mind {"--namespace=nerdctl-test"} vs {"--namespace", "nerdctl-test"} return helpers.Custom("nerdctl", "__complete", "--namespace", string(helpers.Read(nerdtest.Namespace)), "") }, - Expected: test.Expects(0, nil, test.Contains("run\t")), + Expected: test.Expects(0, nil, expect.Contains("run\t")), }, { Description: "run -i", Command: test.Command("__complete", "run", "-i", ""), - Expected: test.Expects(0, nil, test.Contains(testutil.CommonImage)), + Expected: test.Expects(0, nil, expect.Contains(testutil.CommonImage)), }, { Description: "run -it", Command: test.Command("__complete", "run", "-it", ""), - Expected: test.Expects(0, nil, test.Contains(testutil.CommonImage)), + Expected: test.Expects(0, nil, expect.Contains(testutil.CommonImage)), }, { Description: "run -it --rm", Command: test.Command("__complete", "run", "-it", "--rm", ""), - Expected: test.Expects(0, nil, test.Contains(testutil.CommonImage)), + Expected: test.Expects(0, nil, expect.Contains(testutil.CommonImage)), }, { Description: "namespace run -i", @@ -207,7 +210,7 @@ func TestCompletion(t *testing.T) { // mind {"--namespace=nerdctl-test"} vs {"--namespace", "nerdctl-test"} return helpers.Custom("nerdctl", "__complete", "--namespace", string(helpers.Read(nerdtest.Namespace)), "run", "-i", "") }, - Expected: test.Expects(0, nil, test.Contains(testutil.CommonImage+"\n")), + Expected: test.Expects(0, nil, expect.Contains(testutil.CommonImage+"\n")), }, }, } diff --git a/cmd/nerdctl/container/container_attach_linux_test.go b/cmd/nerdctl/container/container_attach_linux_test.go index 6b550bf3710..d2f5a7b7b0d 100644 --- a/cmd/nerdctl/container/container_attach_linux_test.go +++ b/cmd/nerdctl/container/container_attach_linux_test.go @@ -25,9 +25,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) /* @@ -90,8 +92,8 @@ func TestAttach(t *testing.T) { return &test.Expected{ ExitCode: ex, Errors: []error{errors.New("read detach keys")}, - Output: test.All( - test.Contains("markmark"), + Output: expect.All( + expect.Contains("markmark"), func(stdout string, info string, t *testing.T) { assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true")) }, @@ -153,8 +155,8 @@ func TestAttachDetachKeys(t *testing.T) { return &test.Expected{ ExitCode: ex, Errors: []error{errors.New("read detach keys")}, - Output: test.All( - test.Contains("markmark"), + Output: expect.All( + expect.Contains("markmark"), func(stdout string, info string, t *testing.T) { assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true")) }, @@ -206,8 +208,8 @@ func TestAttachForAutoRemovedContainer(t *testing.T) { testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ ExitCode: 42, - Output: test.All( - test.Contains("markmark"), + Output: expect.All( + expect.Contains("markmark"), func(stdout string, info string, t *testing.T) { assert.Assert(t, !strings.Contains(helpers.Capture("ps", "-a"), data.Identifier())) }, diff --git a/cmd/nerdctl/container/container_commit_linux_test.go b/cmd/nerdctl/container/container_commit_linux_test.go index ca9bb15f9fd..8da0ee01b4f 100644 --- a/cmd/nerdctl/container/container_commit_linux_test.go +++ b/cmd/nerdctl/container/container_commit_linux_test.go @@ -20,9 +20,10 @@ import ( "strings" "testing" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestKubeCommitSave(t *testing.T) { diff --git a/cmd/nerdctl/container/container_commit_test.go b/cmd/nerdctl/container/container_commit_test.go index 22d3a3bf02c..b0744f014a8 100644 --- a/cmd/nerdctl/container/container_commit_test.go +++ b/cmd/nerdctl/container/container_commit_test.go @@ -19,9 +19,12 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestCommit(t *testing.T) { @@ -51,11 +54,11 @@ func TestCommit(t *testing.T) { identifier, identifier) return helpers.Command("run", "--rm", identifier) }, - Expected: test.Expects(0, nil, test.Equals("hello-test-commit\n")), + Expected: test.Expects(0, nil, expect.Equals("hello-test-commit\n")), }, { Description: "no pause", - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Cleanup: func(data test.Data, helpers test.Helpers) { identifier := data.Identifier() helpers.Anyhow("rm", "-f", identifier) @@ -77,7 +80,7 @@ func TestCommit(t *testing.T) { identifier, identifier) return helpers.Command("run", "--rm", identifier) }, - Expected: test.Expects(0, nil, test.Equals("hello-test-commit\n")), + Expected: test.Expects(0, nil, expect.Equals("hello-test-commit\n")), }, } diff --git a/cmd/nerdctl/container/container_create_linux_test.go b/cmd/nerdctl/container/container_create_linux_test.go index a4b3bc64fa2..0a20ddac9c2 100644 --- a/cmd/nerdctl/container/container_create_linux_test.go +++ b/cmd/nerdctl/container/container_create_linux_test.go @@ -28,12 +28,13 @@ import ( "gotest.tools/v3/assert" "github.com/containerd/containerd/v2/defaults" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestCreateWithLabel(t *testing.T) { @@ -178,7 +179,7 @@ func TestCreateWithTty(t *testing.T) { func TestIssue2993(t *testing.T) { testCase := nerdtest.Setup() - testCase.Require = test.Not(nerdtest.Docker) + testCase.Require = require.Not(nerdtest.Docker) const ( containersPathKey = "containersPath" diff --git a/cmd/nerdctl/container/container_create_test.go b/cmd/nerdctl/container/container_create_test.go index 6885a1e64aa..8b507d37fc6 100644 --- a/cmd/nerdctl/container/container_create_test.go +++ b/cmd/nerdctl/container/container_create_test.go @@ -23,10 +23,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestCreate(t *testing.T) { @@ -47,7 +49,7 @@ func TestCreate(t *testing.T) { NoParallel: true, Command: test.Command("ps", "-a"), // FIXME: this might get a false positive if other tests have created a container - Expected: test.Expects(0, nil, test.Contains("Created")), + Expected: test.Expects(0, nil, expect.Contains("Created")), }, { Description: "start", @@ -63,7 +65,7 @@ func TestCreate(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("logs", data.Get("cID")) }, - Expected: test.Expects(0, nil, test.Contains("foo")), + Expected: test.Expects(0, nil, expect.Contains("foo")), }, } @@ -90,7 +92,7 @@ func TestCreateHyperVContainer(t *testing.T) { NoParallel: true, Command: test.Command("ps", "-a"), // FIXME: this might get a false positive if other tests have created a container - Expected: test.Expects(0, nil, test.Contains("Created")), + Expected: test.Expects(0, nil, expect.Contains("Created")), }, { Description: "start", @@ -101,7 +103,7 @@ func TestCreateHyperVContainer(t *testing.T) { for i := 0; i < 10 && !ran; i++ { helpers.Command("container", "inspect", data.Get("cID")). Run(&test.Expected{ - ExitCode: test.ExitCodeNoCheck, + ExitCode: expect.ExitCodeNoCheck, Output: func(stdout string, info string, t *testing.T) { var dc []dockercompat.Container err := json.Unmarshal([]byte(stdout), &dc) @@ -119,7 +121,7 @@ func TestCreateHyperVContainer(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("logs", data.Get("cID")) }, - Expected: test.Expects(0, nil, test.Contains("foo")), + Expected: test.Expects(0, nil, expect.Contains("foo")), }, } diff --git a/cmd/nerdctl/container/container_diff_test.go b/cmd/nerdctl/container/container_diff_test.go index b47631dd600..07e0cb4fd45 100644 --- a/cmd/nerdctl/container/container_diff_test.go +++ b/cmd/nerdctl/container/container_diff_test.go @@ -19,9 +19,12 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestDiff(t *testing.T) { @@ -33,7 +36,7 @@ func TestDiff(t *testing.T) { testCase.NoParallel = true } - testCase.Require = test.Not(test.Windows) + testCase.Require = require.Not(require.Windows) testCase.Setup = func(data test.Data, helpers test.Helpers) { helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, @@ -48,11 +51,11 @@ func TestDiff(t *testing.T) { return helpers.Command("diff", data.Identifier()) } - testCase.Expected = test.Expects(0, nil, test.All( - test.Contains("A /a"), - test.Contains("C /bin"), - test.Contains("A /bin/b"), - test.Contains("D /bin/base64"), + testCase.Expected = test.Expects(0, nil, expect.All( + expect.Contains("A /a"), + expect.Contains("C /bin"), + expect.Contains("A /bin/b"), + expect.Contains("D /bin/base64"), )) testCase.Run(t) diff --git a/cmd/nerdctl/container/container_exec_linux_test.go b/cmd/nerdctl/container/container_exec_linux_test.go index 917c8cc563d..c5624085643 100644 --- a/cmd/nerdctl/container/container_exec_linux_test.go +++ b/cmd/nerdctl/container/container_exec_linux_test.go @@ -19,9 +19,11 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestExecWithUser(t *testing.T) { @@ -74,7 +76,7 @@ func TestExecTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(0, nil, test.Contains(sttyPartialOutput)), + Expected: test.Expects(0, nil, expect.Contains(sttyPartialOutput)), }, { Description: "stty with -t", @@ -83,7 +85,7 @@ func TestExecTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(0, nil, test.Contains(sttyPartialOutput)), + Expected: test.Expects(0, nil, expect.Contains(sttyPartialOutput)), }, { Description: "stty with -i", @@ -92,7 +94,7 @@ func TestExecTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(test.ExitCodeGenericFail, nil, nil), + Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil), }, { Description: "stty without params", @@ -101,7 +103,7 @@ func TestExecTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(test.ExitCodeGenericFail, nil, nil), + Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil), }, } diff --git a/cmd/nerdctl/container/container_logs_test.go b/cmd/nerdctl/container/container_logs_test.go index b15fc4c00cb..449e780345f 100644 --- a/cmd/nerdctl/container/container_logs_test.go +++ b/cmd/nerdctl/container/container_logs_test.go @@ -27,9 +27,12 @@ import ( "gotest.tools/v3/assert" "gotest.tools/v3/icmd" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestLogs(t *testing.T) { @@ -164,7 +167,7 @@ func TestLogsWithFailingContainer(t *testing.T) { func TestLogsWithForegroundContainers(t *testing.T) { testCase := nerdtest.Setup() // dual logging is not supported on Windows - testCase.Require = test.Not(test.Windows) + testCase.Require = require.Not(require.Windows) testCase.Run(t) @@ -180,10 +183,10 @@ func TestLogsWithForegroundContainers(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("logs", data.Identifier()) }, - Expected: test.Expects(0, nil, test.All( - test.Contains("foo"), - test.Contains("bar"), - test.DoesNotContain("baz"), + Expected: test.Expects(0, nil, expect.All( + expect.Contains("foo"), + expect.Contains("bar"), + expect.DoesNotContain("baz"), )), }, { @@ -197,10 +200,10 @@ func TestLogsWithForegroundContainers(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("logs", data.Identifier()) }, - Expected: test.Expects(0, nil, test.All( - test.Contains("foo"), - test.Contains("bar"), - test.DoesNotContain("baz"), + Expected: test.Expects(0, nil, expect.All( + expect.Contains("foo"), + expect.Contains("bar"), + expect.DoesNotContain("baz"), )), }, { @@ -216,10 +219,10 @@ func TestLogsWithForegroundContainers(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("logs", data.Identifier()) }, - Expected: test.Expects(0, nil, test.All( - test.Contains("foo"), - test.Contains("bar"), - test.DoesNotContain("baz"), + Expected: test.Expects(0, nil, expect.All( + expect.Contains("foo"), + expect.Contains("bar"), + expect.DoesNotContain("baz"), )), }, { @@ -235,10 +238,10 @@ func TestLogsWithForegroundContainers(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("logs", data.Identifier()) }, - Expected: test.Expects(0, nil, test.All( - test.Contains("foo"), - test.Contains("bar"), - test.DoesNotContain("baz"), + Expected: test.Expects(0, nil, expect.All( + expect.Contains("foo"), + expect.Contains("bar"), + expect.DoesNotContain("baz"), )), }, } diff --git a/cmd/nerdctl/container/container_prune_linux_test.go b/cmd/nerdctl/container/container_prune_linux_test.go index 4ff48954385..c9e4b9a8c92 100644 --- a/cmd/nerdctl/container/container_prune_linux_test.go +++ b/cmd/nerdctl/container/container_prune_linux_test.go @@ -19,9 +19,10 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestPruneContainer(t *testing.T) { diff --git a/cmd/nerdctl/container/container_remove_test.go b/cmd/nerdctl/container/container_remove_test.go index 36c81c2c6ab..8c3d83543fd 100644 --- a/cmd/nerdctl/container/container_remove_test.go +++ b/cmd/nerdctl/container/container_remove_test.go @@ -19,9 +19,10 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRemoveContainer(t *testing.T) { diff --git a/cmd/nerdctl/container/container_restart_linux_test.go b/cmd/nerdctl/container/container_restart_linux_test.go index 231b0128c1b..95b404099cd 100644 --- a/cmd/nerdctl/container/container_restart_linux_test.go +++ b/cmd/nerdctl/container/container_restart_linux_test.go @@ -25,9 +25,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRestart(t *testing.T) { @@ -144,9 +146,9 @@ func TestRestartWithSignal(t *testing.T) { return &test.Expected{ // Check the container did indeed exit ExitCode: 137, - Output: test.All( + Output: expect.All( // Check that we saw SIGUSR1 inside the container - test.Contains(nerdtest.SignalCaught), + expect.Contains(nerdtest.SignalCaught), func(stdout string, info string, t *testing.T) { // Ensure the container was restarted nerdtest.EnsureContainerStarted(helpers, data.Identifier()) diff --git a/cmd/nerdctl/container/container_run_cgroup_linux_test.go b/cmd/nerdctl/container/container_run_cgroup_linux_test.go index c4b5c77de7c..287d372908e 100644 --- a/cmd/nerdctl/container/container_run_cgroup_linux_test.go +++ b/cmd/nerdctl/container/container_run_cgroup_linux_test.go @@ -30,12 +30,12 @@ import ( "github.com/containerd/cgroups/v3" containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/continuity/testutil/loopback" + "github.com/containerd/nerdctl/mod/tigron/require" "github.com/containerd/nerdctl/v2/pkg/cmd/container" "github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRunCgroupV2(t *testing.T) { @@ -178,7 +178,7 @@ func TestRunCgroupV1(t *testing.T) { func TestIssue3781(t *testing.T) { t.Parallel() testCase := nerdtest.Setup() - testCase.Require = test.Not(nerdtest.Docker) + testCase.Require = require.Not(nerdtest.Docker) base := testutil.NewBase(t) info := base.Info() diff --git a/cmd/nerdctl/container/container_run_linux_test.go b/cmd/nerdctl/container/container_run_linux_test.go index 8fcd8e0b5b3..c0c37615b03 100644 --- a/cmd/nerdctl/container/container_run_linux_test.go +++ b/cmd/nerdctl/container/container_run_linux_test.go @@ -33,13 +33,15 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/rootlessutil" "github.com/containerd/nerdctl/v2/pkg/strutil" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRunCustomRootfs(t *testing.T) { @@ -324,7 +326,7 @@ func TestRunTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(0, nil, test.Contains(sttyPartialOutput)), + Expected: test.Expects(0, nil, expect.Contains(sttyPartialOutput)), }, { Description: "stty with -t", @@ -336,7 +338,7 @@ func TestRunTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(0, nil, test.Contains(sttyPartialOutput)), + Expected: test.Expects(0, nil, expect.Contains(sttyPartialOutput)), }, { Description: "stty with -i", @@ -348,7 +350,7 @@ func TestRunTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(test.ExitCodeGenericFail, nil, nil), + Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil), }, { Description: "stty without params", @@ -360,7 +362,7 @@ func TestRunTTY(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(test.ExitCodeGenericFail, nil, nil), + Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil), }, } } @@ -383,7 +385,7 @@ func TestRunSigProxy(t *testing.T) { return cmd }, - Expected: test.Expects(0, nil, test.Contains(nerdtest.SignalCaught)), + Expected: test.Expects(0, nil, expect.Contains(nerdtest.SignalCaught)), }, { Description: "SigProxyTrue", @@ -399,7 +401,7 @@ func TestRunSigProxy(t *testing.T) { return cmd }, - Expected: test.Expects(0, nil, test.Contains(nerdtest.SignalCaught)), + Expected: test.Expects(0, nil, expect.Contains(nerdtest.SignalCaught)), }, { Description: "SigProxyFalse", @@ -415,7 +417,7 @@ func TestRunSigProxy(t *testing.T) { return cmd }, - Expected: test.Expects(127, nil, test.DoesNotContain(nerdtest.SignalCaught)), + Expected: test.Expects(127, nil, expect.DoesNotContain(nerdtest.SignalCaught)), }, } @@ -523,8 +525,8 @@ func TestRunWithDetachKeys(t *testing.T) { return &test.Expected{ ExitCode: 0, Errors: []error{errors.New("detach keys")}, - Output: test.All( - test.Contains("markmark"), + Output: expect.All( + expect.Contains("markmark"), func(stdout string, info string, t *testing.T) { assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true")) }, @@ -591,8 +593,8 @@ func TestIssue3568(t *testing.T) { return &test.Expected{ ExitCode: 0, Errors: []error{errors.New("detach keys")}, - Output: test.All( - test.Contains("markmark"), + Output: expect.All( + expect.Contains("markmark"), func(stdout string, info string, t *testing.T) { assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true")) }, @@ -627,7 +629,7 @@ func TestPortBindingWithCustomHost(t *testing.T) { return &test.Expected{ ExitCode: 0, Errors: []error{}, - Output: test.All( + Output: expect.All( func(stdout string, info string, t *testing.T) { resp, err := nettestutil.HTTPGet(address, 30, false) assert.NilError(t, err) diff --git a/cmd/nerdctl/container/container_run_mount_linux_test.go b/cmd/nerdctl/container/container_run_mount_linux_test.go index 0e810551191..f02d47d5198 100644 --- a/cmd/nerdctl/container/container_run_mount_linux_test.go +++ b/cmd/nerdctl/container/container_run_mount_linux_test.go @@ -706,6 +706,7 @@ func TestBindMountWhenHostFolderDoesNotExist(t *testing.T) { } defer os.RemoveAll(hostDir) hp := filepath.Join(hostDir, "does-not-exist") + base.Cmd("rm", "-f", containerName).AssertOK() base.Cmd("run", "--name", containerName, "-d", "-v", fmt.Sprintf("%s:/tmp", hp), testutil.AlpineImage).AssertOK() base.Cmd("rm", "-f", containerName).AssertOK() diff --git a/cmd/nerdctl/container/container_run_network_linux_test.go b/cmd/nerdctl/container/container_run_network_linux_test.go index 1ffe72b3f69..62e8770f51d 100644 --- a/cmd/nerdctl/container/container_run_network_linux_test.go +++ b/cmd/nerdctl/container/container_run_network_linux_test.go @@ -37,13 +37,14 @@ import ( "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/pkg/netns" "github.com/containerd/errdefs" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/rootlessutil" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func extractHostPort(portMapping string, port string) (string, error) { @@ -355,7 +356,7 @@ func TestRunPort(t *testing.T) { func TestRunWithInvalidPortThenCleanUp(t *testing.T) { testCase := nerdtest.Setup() // docker does not set label restriction to 4096 bytes - testCase.Require = test.Not(nerdtest.Docker) + testCase.Require = require.Not(nerdtest.Docker) testCase.SubTests = []*test.Case{ { @@ -515,7 +516,7 @@ func TestRunNetworkHost2613(t *testing.T) { func TestSharedNetworkSetup(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { data.Set("containerName1", data.Identifier("-container1")) containerName1 := data.Get("containerName1") @@ -678,7 +679,7 @@ func TestSharedNetworkSetup(t *testing.T) { func TestSharedNetworkWithNone(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { data.Set("containerName1", data.Identifier("-container1")) containerName1 := data.Get("containerName1") @@ -921,7 +922,7 @@ func TestRunContainerWithStaticIP6(t *testing.T) { func TestNoneNetworkHostName(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { data.Set("containerName1", data.Identifier()) }, @@ -949,7 +950,7 @@ func TestNoneNetworkHostName(t *testing.T) { func TestHostNetworkHostName(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { data.Set("containerName1", data.Identifier()) }, @@ -974,7 +975,7 @@ func TestHostNetworkHostName(t *testing.T) { func TestNoneNetworkDnsConfigs(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { data.Set("containerName1", data.Identifier()) }, @@ -1003,7 +1004,7 @@ func TestNoneNetworkDnsConfigs(t *testing.T) { func TestHostNetworkDnsConfigs(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { data.Set("containerName1", data.Identifier()) }, diff --git a/cmd/nerdctl/container/container_run_stargz_linux_test.go b/cmd/nerdctl/container/container_run_stargz_linux_test.go index 523ef5cd44c..3132b28f9b9 100644 --- a/cmd/nerdctl/container/container_run_stargz_linux_test.go +++ b/cmd/nerdctl/container/container_run_stargz_linux_test.go @@ -19,18 +19,20 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRunStargz(t *testing.T) { testCase := nerdtest.Setup() - testCase.Require = test.Require( + testCase.Require = require.All( nerdtest.Stargz, - test.Amd64, - test.Not(nerdtest.Docker), + require.Amd64, + require.Not(nerdtest.Docker), ) testCase.Command = test.Command("--snapshotter=stargz", "run", "--rm", testutil.FedoraESGZImage, "ls", "/.stargz-snapshotter") diff --git a/cmd/nerdctl/container/container_run_windows_test.go b/cmd/nerdctl/container/container_run_windows_test.go index 843a6eac702..6c054292ec2 100644 --- a/cmd/nerdctl/container/container_run_windows_test.go +++ b/cmd/nerdctl/container/container_run_windows_test.go @@ -24,9 +24,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRunHostProcessContainer(t *testing.T) { @@ -141,7 +143,7 @@ func TestRunWithTtyAndDetached(t *testing.T) { return helpers.Command("logs", data.Identifier("with-terminal")) } - testCase.Expected = test.Expects(0, nil, test.Contains("Hello, World with TTY!")) + testCase.Expected = test.Expects(0, nil, expect.Contains("Hello, World with TTY!")) testCase.Run(t) } diff --git a/cmd/nerdctl/container/container_start_linux_test.go b/cmd/nerdctl/container/container_start_linux_test.go index eda4e5d812a..afd7d1d788b 100644 --- a/cmd/nerdctl/container/container_start_linux_test.go +++ b/cmd/nerdctl/container/container_start_linux_test.go @@ -24,9 +24,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestStartDetachKeys(t *testing.T) { @@ -71,7 +73,7 @@ func TestStartDetachKeys(t *testing.T) { return &test.Expected{ ExitCode: 0, Errors: []error{errors.New("detach keys")}, - Output: test.All( + Output: expect.All( func(stdout string, info string, t *testing.T) { assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true")) }, diff --git a/cmd/nerdctl/container/container_stats_test.go b/cmd/nerdctl/container/container_stats_test.go index 9522e73e009..0648d502d94 100644 --- a/cmd/nerdctl/container/container_stats_test.go +++ b/cmd/nerdctl/container/container_stats_test.go @@ -20,21 +20,24 @@ import ( "runtime" "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestStats(t *testing.T) { testCase := nerdtest.Setup() // FIXME: does not seem to work on windows - testCase.Require = test.Not(test.Windows) + testCase.Require = require.Not(require.Windows) if runtime.GOOS == "linux" { // this comment is for `nerdctl ps` but it also valid for `nerdctl stats` : // https://github.com/containerd/nerdctl/pull/223#issuecomment-851395178 - testCase.Require = test.Require( + testCase.Require = require.All( testCase.Require, nerdtest.CgroupsAccessible, ) @@ -59,7 +62,7 @@ func TestStats(t *testing.T) { Command: test.Command("stats", "--no-stream", "--no-trunc"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("id")), + Output: expect.Contains(data.Get("id")), } }, }, @@ -68,7 +71,7 @@ func TestStats(t *testing.T) { Command: test.Command("container", "stats", "--no-stream", "--no-trunc"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("id")), + Output: expect.Contains(data.Get("id")), } }, }, @@ -93,14 +96,14 @@ func TestStats(t *testing.T) { }, // https://github.com/containerd/nerdctl/issues/1240 // nerdctl used to print UINT64_MAX as the memory limit, so, ensure it does no more - Expected: test.Expects(0, nil, test.DoesNotContain("16EiB")), + Expected: test.Expects(0, nil, expect.DoesNotContain("16EiB")), }, { Description: "mem limit set", Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("stats", "--no-stream") }, - Expected: test.Expects(0, nil, test.Contains("1GiB")), + Expected: test.Expects(0, nil, expect.Contains("1GiB")), }, } diff --git a/cmd/nerdctl/container/container_stop_linux_test.go b/cmd/nerdctl/container/container_stop_linux_test.go index bc12485c935..c9ba8874af1 100644 --- a/cmd/nerdctl/container/container_stop_linux_test.go +++ b/cmd/nerdctl/container/container_stop_linux_test.go @@ -26,12 +26,14 @@ import ( "github.com/coreos/go-iptables/iptables" "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/rootlessutil" "github.com/containerd/nerdctl/v2/pkg/testutil" iptablesutil "github.com/containerd/nerdctl/v2/pkg/testutil/iptables" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestStopStart(t *testing.T) { @@ -89,7 +91,7 @@ func TestStopWithStopSignal(t *testing.T) { } // Verify that SIGQUIT was sent to the container AND that the container did forcefully exit - testCase.Expected = test.Expects(137, nil, test.Contains(nerdtest.SignalCaught)) + testCase.Expected = test.Expects(137, nil, expect.Contains(nerdtest.SignalCaught)) testCase.Run(t) } diff --git a/cmd/nerdctl/container/container_top_test.go b/cmd/nerdctl/container/container_top_test.go index 8042b32a8b4..6f18721b14e 100644 --- a/cmd/nerdctl/container/container_top_test.go +++ b/cmd/nerdctl/container/container_top_test.go @@ -20,9 +20,11 @@ import ( "runtime" "testing" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestTop(t *testing.T) { @@ -47,7 +49,7 @@ func TestTop(t *testing.T) { { Description: "with o pid,user,cmd", // Docker does not support top -o - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("top", data.Get("cID"), "-o", "pid,user,cmd") }, diff --git a/cmd/nerdctl/container/container_wait_test.go b/cmd/nerdctl/container/container_wait_test.go index 9c0c93da3ff..fdbfd367ebd 100644 --- a/cmd/nerdctl/container/container_wait_test.go +++ b/cmd/nerdctl/container/container_wait_test.go @@ -19,9 +19,11 @@ package container import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestWait(t *testing.T) { @@ -41,7 +43,7 @@ func TestWait(t *testing.T) { return helpers.Command("wait", data.Identifier("1"), data.Identifier("2"), data.Identifier("3")) } - testCase.Expected = test.Expects(0, nil, test.Equals(`0 + testCase.Expected = test.Expects(0, nil, expect.Equals(`0 0 123 `)) diff --git a/cmd/nerdctl/image/image_convert_linux_test.go b/cmd/nerdctl/image/image_convert_linux_test.go index 6968e5ab7a5..3d2615741bc 100644 --- a/cmd/nerdctl/image/image_convert_linux_test.go +++ b/cmd/nerdctl/image/image_convert_linux_test.go @@ -20,9 +20,11 @@ import ( "fmt" "testing" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" "github.com/containerd/nerdctl/v2/pkg/testutil/testregistry" ) @@ -30,10 +32,10 @@ func TestImageConvert(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( // FIXME: windows does not support stargz - test.Not(test.Windows), - test.Not(nerdtest.Docker), + require.Not(require.Windows), + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) @@ -52,8 +54,8 @@ func TestImageConvert(t *testing.T) { }, { Description: "nydus", - Require: test.Require( - test.Binary("nydus-image"), + Require: require.All( + require.Binary("nydus-image"), ), Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier("converted-image")) @@ -101,12 +103,12 @@ func TestImageConvertNydusVerify(t *testing.T) { var registry *testregistry.RegistryServer testCase := &test.Case{ - Require: test.Require( - test.Linux, - test.Binary("nydus-image"), - test.Binary("nydusify"), - test.Binary("nydusd"), - test.Not(nerdtest.Docker), + Require: require.All( + require.Linux, + require.Binary("nydus-image"), + require.Binary("nydusify"), + require.Binary("nydusd"), + require.Not(nerdtest.Docker), nerdtest.Rootful, ), Setup: func(data test.Data, helpers test.Helpers) { diff --git a/cmd/nerdctl/image/image_encrypt_linux_test.go b/cmd/nerdctl/image/image_encrypt_linux_test.go index 3e2e93ac29e..ac883133f63 100644 --- a/cmd/nerdctl/image/image_encrypt_linux_test.go +++ b/cmd/nerdctl/image/image_encrypt_linux_test.go @@ -23,10 +23,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" "github.com/containerd/nerdctl/v2/pkg/testutil/testregistry" ) @@ -39,9 +41,9 @@ func TestImageEncryptJWE(t *testing.T) { const remoteImageKey = "remoteImageKey" testCase := &test.Case{ - Require: test.Require( - test.Linux, - test.Not(nerdtest.Docker), + Require: require.All( + require.Linux, + require.Not(nerdtest.Docker), // This test needs to rmi the common image nerdtest.Private, ), diff --git a/cmd/nerdctl/image/image_history_test.go b/cmd/nerdctl/image/image_history_test.go index 9520e72535b..f4f0d2c0505 100644 --- a/cmd/nerdctl/image/image_history_test.go +++ b/cmd/nerdctl/image/image_history_test.go @@ -26,9 +26,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) type historyObj struct { @@ -69,12 +71,12 @@ func TestImageHistory(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), // XXX the results here are obviously platform dependent - and it seems like windows cannot pull a linux image? - test.Not(test.Windows), + require.Not(require.Windows), // XXX Currently, history does not work on non-native platform, so, we cannot test reliably on other platforms - test.Arm64, + require.Arm64, ), Setup: func(data test.Data, helpers test.Helpers) { // XXX: despite efforts to isolate this test, it keeps on having side effects linked to diff --git a/cmd/nerdctl/image/image_inspect_test.go b/cmd/nerdctl/image/image_inspect_test.go index 808fd199d46..c4bd92c94fd 100644 --- a/cmd/nerdctl/image/image_inspect_test.go +++ b/cmd/nerdctl/image/image_inspect_test.go @@ -26,10 +26,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestImageInspectSimpleCases(t *testing.T) { @@ -95,10 +97,10 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) { } testCase := &test.Case{ - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), // FIXME: this test depends on hub images that do not have windows versions - test.Not(test.Windows), + require.Not(require.Windows), // We need a clean slate nerdtest.Private, ), diff --git a/cmd/nerdctl/image/image_list_test.go b/cmd/nerdctl/image/image_list_test.go index bc88386ef4c..38b0b034fed 100644 --- a/cmd/nerdctl/image/image_list_test.go +++ b/cmd/nerdctl/image/image_list_test.go @@ -28,17 +28,20 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/tabutil" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestImages(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) helpers.Ensure("pull", "--quiet", testutil.NginxAlpineImage) @@ -78,8 +81,8 @@ func TestImages(t *testing.T) { Command: test.Command("images", "--names", testutil.CommonImage), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(testutil.CommonImage), + Output: expect.All( + expect.Contains(testutil.CommonImage), func(stdout string, info string, t *testing.T) { lines := strings.Split(strings.TrimSpace(stdout), "\n") assert.Assert(t, len(lines) >= 2, info) @@ -120,7 +123,7 @@ func TestImages(t *testing.T) { } if runtime.GOOS == "windows" { - testCase.Require = test.Require( + testCase.Require = require.All( testCase.Require, nerdtest.IsFlaky("https://github.com/containerd/nerdctl/issues/3524"), ) @@ -166,7 +169,7 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", "label=foo=bar"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("builtImageID")), + Output: expect.Contains(data.Get("builtImageID")), } }, }, @@ -175,7 +178,7 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", "label=foo=bar1"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.DoesNotContain(data.Get("builtImageID")), + Output: expect.DoesNotContain(data.Get("builtImageID")), } }, }, @@ -184,7 +187,7 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", "label=foo=bar", "--filter", "label=version=0.1"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("builtImageID")), + Output: expect.Contains(data.Get("builtImageID")), } }, }, @@ -193,7 +196,7 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", "label=foo=bar", "--filter", "label=version=0.2"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.DoesNotContain(data.Get("builtImageID")), + Output: expect.DoesNotContain(data.Get("builtImageID")), } }, }, @@ -202,7 +205,7 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", "label=version"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("builtImageID")), + Output: expect.Contains(data.Get("builtImageID")), } }, }, @@ -213,16 +216,16 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Get("builtImageID")), + Output: expect.Contains(data.Get("builtImageID")), } }, }, { Description: "reference=tagged*:*fragment*", Command: test.Command("images", "--filter", "reference=tagged*:*fragment*"), - Expected: test.Expects(0, nil, test.All( - test.Contains("one-"), - test.Contains("two-"), + Expected: test.Expects(0, nil, expect.All( + expect.Contains("one-"), + expect.Contains("two-"), )), }, { @@ -232,9 +235,9 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(testutil.ImageRepo(testutil.CommonImage)), - test.DoesNotContain(data.Get("builtImageID")), + Output: expect.All( + expect.Contains(testutil.ImageRepo(testutil.CommonImage)), + expect.DoesNotContain(data.Get("builtImageID")), ), } }, @@ -244,9 +247,9 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", fmt.Sprintf("since=%s", testutil.CommonImage)), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(data.Get("builtImageID")), - test.DoesNotContain(testutil.ImageRepo(testutil.CommonImage)), + Output: expect.All( + expect.Contains(data.Get("builtImageID")), + expect.DoesNotContain(testutil.ImageRepo(testutil.CommonImage)), ), } }, @@ -256,9 +259,9 @@ RUN echo "actually creating a layer so that docker sets the createdAt time" Command: test.Command("images", "--filter", fmt.Sprintf("since=%s", testutil.CommonImage), testutil.CommonImage), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.DoesNotContain(data.Get("builtImageID")), - test.DoesNotContain(testutil.ImageRepo(testutil.CommonImage)), + Output: expect.All( + expect.DoesNotContain(data.Get("builtImageID")), + expect.DoesNotContain(testutil.ImageRepo(testutil.CommonImage)), ), } }, @@ -310,12 +313,12 @@ CMD ["echo", "nerdctl-build-notag-string"] { Description: "dangling", Command: test.Command("images", "--filter", "dangling=true"), - Expected: test.Expects(0, nil, test.Contains("")), + Expected: test.Expects(0, nil, expect.Contains("")), }, { Description: "not dangling", Command: test.Command("images", "--filter", "dangling=false"), - Expected: test.Expects(0, nil, test.DoesNotContain("")), + Expected: test.Expects(0, nil, expect.DoesNotContain("")), }, }, } @@ -327,7 +330,7 @@ func TestImagesKubeWithKubeHideDupe(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( + Require: require.All( nerdtest.OnlyKubernetes, ), Setup: func(data test.Data, helpers test.Helpers) { @@ -380,7 +383,7 @@ func TestImagesKubeWithKubeHideDupe(t *testing.T) { Command: test.Command("images"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(""), + Output: expect.Contains(""), } }, }, diff --git a/cmd/nerdctl/image/image_load_test.go b/cmd/nerdctl/image/image_load_test.go index 4a0e170fa3e..d9d3781217d 100644 --- a/cmd/nerdctl/image/image_load_test.go +++ b/cmd/nerdctl/image/image_load_test.go @@ -25,9 +25,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestLoadStdinFromPipe(t *testing.T) { @@ -35,7 +38,7 @@ func TestLoadStdinFromPipe(t *testing.T) { testCase := &test.Case{ Description: "TestLoadStdinFromPipe", - Require: test.Linux, + Require: require.Linux, Setup: func(data test.Data, helpers test.Helpers) { identifier := data.Identifier() helpers.Ensure("pull", "--quiet", testutil.CommonImage) @@ -56,8 +59,8 @@ func TestLoadStdinFromPipe(t *testing.T) { Expected: func(data test.Data, helpers test.Helpers) *test.Expected { identifier := data.Identifier() return &test.Expected{ - Output: test.All( - test.Contains(fmt.Sprintf("Loaded image: %s:latest", identifier)), + Output: expect.All( + expect.Contains(fmt.Sprintf("Loaded image: %s:latest", identifier)), func(stdout string, info string, t *testing.T) { assert.Assert(t, strings.Contains(helpers.Capture("images"), identifier)) }, @@ -74,7 +77,7 @@ func TestLoadStdinEmpty(t *testing.T) { testCase := &test.Case{ Description: "TestLoadStdinEmpty", - Require: test.Linux, + Require: require.Linux, Command: test.Command("load"), Expected: test.Expects(1, nil, nil), } @@ -102,9 +105,9 @@ func TestLoadQuiet(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(fmt.Sprintf("Loaded image: %s:latest", data.Identifier())), - test.DoesNotContain("Loading layer"), + Output: expect.All( + expect.Contains(fmt.Sprintf("Loaded image: %s:latest", data.Identifier())), + expect.DoesNotContain("Loading layer"), ), } }, diff --git a/cmd/nerdctl/image/image_prune_test.go b/cmd/nerdctl/image/image_prune_test.go index c71c99e6919..1c8b402e332 100644 --- a/cmd/nerdctl/image/image_prune_test.go +++ b/cmd/nerdctl/image/image_prune_test.go @@ -26,9 +26,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestImagePrune(t *testing.T) { @@ -53,10 +56,10 @@ func TestImagePrune(t *testing.T) { { Description: "without all", NoParallel: true, - Require: test.Require( + Require: require.All( // This never worked with Docker - the only reason we ever got was side effects from other tests // See inline comments. - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), nerdtest.Build, ), Cleanup: func(data test.Data, helpers test.Helpers) { @@ -83,7 +86,7 @@ func TestImagePrune(t *testing.T) { Expected: func(data test.Data, helpers test.Helpers) *test.Expected { identifier := data.Identifier() return &test.Expected{ - Output: test.All( + Output: expect.All( func(stdout string, info string, t *testing.T) { assert.Assert(t, !strings.Contains(stdout, identifier), info) }, @@ -98,9 +101,9 @@ func TestImagePrune(t *testing.T) { }, { Description: "with all", - Require: test.Require( + Require: require.All( // Same as above - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), nerdtest.Build, ), // Cannot use a custom namespace with buildkitd right now, so, no parallel it is @@ -129,7 +132,7 @@ func TestImagePrune(t *testing.T) { Command: test.Command("image", "prune", "--force", "--all"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( + Output: expect.All( func(stdout string, info string, t *testing.T) { assert.Assert(t, !strings.Contains(stdout, data.Identifier()), info) }, @@ -170,7 +173,7 @@ LABEL version=0.1`, testutil.CommonImage) Command: test.Command("image", "prune", "--force", "--all", "--filter", "label=foo=baz"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( + Output: expect.All( func(stdout string, info string, t *testing.T) { assert.Assert(t, !strings.Contains(stdout, data.Identifier()), info) }, @@ -211,8 +214,8 @@ CMD ["echo", "nerdctl-test-image-prune-until"]`, testutil.CommonImage) Command: test.Command("image", "prune", "--force", "--all", "--filter", "until=12h"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.DoesNotContain(data.Get("imageID")), + Output: expect.All( + expect.DoesNotContain(data.Get("imageID")), func(stdout string, info string, t *testing.T) { imgList := helpers.Capture("images") assert.Assert(t, strings.Contains(imgList, data.Get("imageID")), info) @@ -230,8 +233,8 @@ CMD ["echo", "nerdctl-test-image-prune-until"]`, testutil.CommonImage) Command: test.Command("image", "prune", "--force", "--all", "--filter", "until=10ms"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(data.Get("imageID")), + Output: expect.All( + expect.Contains(data.Get("imageID")), func(stdout string, info string, t *testing.T) { imgList := helpers.Capture("images") assert.Assert(t, !strings.Contains(imgList, data.Get("imageID")), imgList, info) diff --git a/cmd/nerdctl/image/image_pull_linux_test.go b/cmd/nerdctl/image/image_pull_linux_test.go index c350d1e71a4..ebd7976632f 100644 --- a/cmd/nerdctl/image/image_pull_linux_test.go +++ b/cmd/nerdctl/image/image_pull_linux_test.go @@ -26,10 +26,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" "github.com/containerd/nerdctl/v2/pkg/testutil/testregistry" ) @@ -40,11 +43,11 @@ func TestImagePullWithCosign(t *testing.T) { var keyPair *testhelpers.CosignKeyPair testCase := &test.Case{ - Require: test.Require( - test.Linux, + Require: require.All( + require.Linux, nerdtest.Build, - test.Binary("cosign"), - test.Not(nerdtest.Docker), + require.Binary("cosign"), + require.Not(nerdtest.Docker), ), Env: map[string]string{ "COSIGN_PASSWORD": "1", @@ -110,9 +113,9 @@ func TestImagePullPlainHttpWithDefaultPort(t *testing.T) { var registry *testregistry.RegistryServer testCase := &test.Case{ - Require: test.Require( - test.Linux, - test.Not(nerdtest.Docker), + Require: require.All( + require.Linux, + require.Not(nerdtest.Docker), nerdtest.Build, ), Setup: func(data test.Data, helpers test.Helpers) { @@ -154,9 +157,9 @@ func TestImagePullSoci(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ - Require: test.Require( - test.Linux, - test.Not(nerdtest.Docker), + Require: require.All( + require.Linux, + require.Not(nerdtest.Docker), nerdtest.Soci, ), @@ -166,8 +169,7 @@ func TestImagePullSoci(t *testing.T) { { Description: "Run without specifying SOCI index", NoParallel: true, - Data: test. - WithData("remoteSnapshotsExpectedCount", "11"). + Data: test.WithData("remoteSnapshotsExpectedCount", "11"). Set("sociIndexDigest", ""), Setup: func(data test.Data, helpers test.Helpers) { cmd := helpers.Custom("mount") @@ -200,8 +202,7 @@ func TestImagePullSoci(t *testing.T) { { Description: "Run with bad SOCI index", NoParallel: true, - Data: test. - WithData("remoteSnapshotsExpectedCount", "11"). + Data: test.WithData("remoteSnapshotsExpectedCount", "11"). Set("sociIndexDigest", "sha256:thisisabadindex0000000000000000000000000000000000000000000000000"), Setup: func(data test.Data, helpers test.Helpers) { cmd := helpers.Custom("mount") @@ -251,7 +252,7 @@ func TestImagePullProcessOutput(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("pull", testutil.BusyboxImage) }, - Expected: test.Expects(0, nil, test.Contains(testutil.BusyboxImage)), + Expected: test.Expects(0, nil, expect.Contains(testutil.BusyboxImage)), }, { Description: "Run Container with image pull - output should be in stderr", @@ -262,7 +263,7 @@ func TestImagePullProcessOutput(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", testutil.BusyboxImage) }, - Expected: test.Expects(0, nil, test.DoesNotContain(testutil.BusyboxImage)), + Expected: test.Expects(0, nil, expect.DoesNotContain(testutil.BusyboxImage)), }, }, } diff --git a/cmd/nerdctl/image/image_push_linux_test.go b/cmd/nerdctl/image/image_push_linux_test.go index 791141876ee..66d26512a8a 100644 --- a/cmd/nerdctl/image/image_push_linux_test.go +++ b/cmd/nerdctl/image/image_push_linux_test.go @@ -25,9 +25,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" "github.com/containerd/nerdctl/v2/pkg/testutil/testregistry" ) @@ -37,7 +39,7 @@ func TestPush(t *testing.T) { var registryNoAuthHTTPRandom, registryNoAuthHTTPDefault, registryTokenAuthHTTPSRandom *testregistry.RegistryServer testCase := &test.Case{ - Require: test.Linux, + Require: require.Linux, Setup: func(data test.Data, helpers test.Helpers) { base := testutil.NewBase(t) @@ -80,7 +82,7 @@ func TestPush(t *testing.T) { }, { Description: "plain http with insecure", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) testImageRef := fmt.Sprintf("%s:%d/%s:%s", @@ -114,7 +116,7 @@ func TestPush(t *testing.T) { }, { Description: "plain http with insecure, default port", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) testImageRef := fmt.Sprintf("%s/%s:%s", @@ -134,7 +136,7 @@ func TestPush(t *testing.T) { }, { Description: "with insecure, with login", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) testImageRef := fmt.Sprintf("%s:%d/%s:%s", @@ -157,7 +159,7 @@ func TestPush(t *testing.T) { }, { Description: "with hosts dir, with login", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) testImageRef := fmt.Sprintf("%s:%d/%s:%s", @@ -180,7 +182,7 @@ func TestPush(t *testing.T) { }, { Description: "non distributable artifacts", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.NonDistBlobImage) testImageRef := fmt.Sprintf("%s:%d/%s:%s", @@ -212,7 +214,7 @@ func TestPush(t *testing.T) { }, { Description: "non distributable artifacts (with)", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.NonDistBlobImage) testImageRef := fmt.Sprintf("%s:%d/%s:%s", @@ -244,9 +246,9 @@ func TestPush(t *testing.T) { }, { Description: "soci", - Require: test.Require( + Require: require.All( nerdtest.Soci, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.UbuntuImage) diff --git a/cmd/nerdctl/image/image_remove_test.go b/cmd/nerdctl/image/image_remove_test.go index e7e0e4d2c92..4dc1d683aae 100644 --- a/cmd/nerdctl/image/image_remove_test.go +++ b/cmd/nerdctl/image/image_remove_test.go @@ -23,10 +23,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/imgutil" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestRemove(t *testing.T) { @@ -46,8 +49,8 @@ func TestRemove(t *testing.T) { { Description: "Remove image with stopped container - without -f", NoParallel: true, - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("run", "--pull", "always", "--name", data.Identifier(), testutil.CommonImage) @@ -62,7 +65,7 @@ func TestRemove(t *testing.T) { Errors: []error{errors.New("image is being used")}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(repoName), + Output: expect.Contains(repoName), }) }, } @@ -82,7 +85,7 @@ func TestRemove(t *testing.T) { return &test.Expected{ Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.DoesNotContain(repoName), + Output: expect.DoesNotContain(repoName), }) }, } @@ -91,8 +94,8 @@ func TestRemove(t *testing.T) { { Description: "Remove image with running container - without -f", NoParallel: true, - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", nerdtest.Infinity) @@ -107,7 +110,7 @@ func TestRemove(t *testing.T) { Errors: []error{errors.New("image is being used")}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(repoName), + Output: expect.Contains(repoName), }) }, } @@ -116,8 +119,8 @@ func TestRemove(t *testing.T) { { Description: "Remove image with running container - with -f", NoParallel: true, - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", nerdtest.Infinity) @@ -139,7 +142,7 @@ func TestRemove(t *testing.T) { Errors: []error{}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(""), + Output: expect.Contains(""), }) }, } @@ -161,7 +164,7 @@ func TestRemove(t *testing.T) { Errors: []error{errors.New("image is being used")}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(repoName), + Output: expect.Contains(repoName), }) }, } @@ -183,10 +186,10 @@ func TestRemove(t *testing.T) { return &test.Expected{ Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.All( - test.DoesNotContain(repoName), + Output: expect.All( + expect.DoesNotContain(repoName), // a created container with removed image doesn't impact other `rmi` command - test.DoesNotContain(nginxRepoName), + expect.DoesNotContain(nginxRepoName), ), }) }, @@ -196,8 +199,8 @@ func TestRemove(t *testing.T) { { Description: "Remove image with paused container - without -f", NoParallel: true, - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), nerdtest.CGroup, ), Setup: func(data test.Data, helpers test.Helpers) { @@ -214,7 +217,7 @@ func TestRemove(t *testing.T) { Errors: []error{errors.New("image is being used")}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(repoName), + Output: expect.Contains(repoName), }) }, } @@ -223,9 +226,9 @@ func TestRemove(t *testing.T) { { Description: "Remove image with paused container - with -f", NoParallel: true, - Require: test.Require( + Require: require.All( nerdtest.CGroup, - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", nerdtest.Infinity) @@ -248,7 +251,7 @@ func TestRemove(t *testing.T) { Errors: []error{}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(""), + Output: expect.Contains(""), }) }, } @@ -257,8 +260,8 @@ func TestRemove(t *testing.T) { { Description: "Remove image with killed container - without -f", NoParallel: true, - Require: test.Require( - test.Not(nerdtest.Docker), + Require: require.All( + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", nerdtest.Infinity) @@ -274,7 +277,7 @@ func TestRemove(t *testing.T) { Errors: []error{errors.New("image is being used")}, Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.Contains(repoName), + Output: expect.Contains(repoName), }) }, } @@ -295,7 +298,7 @@ func TestRemove(t *testing.T) { return &test.Expected{ Output: func(stdout string, info string, t *testing.T) { helpers.Command("images").Run(&test.Expected{ - Output: test.DoesNotContain(repoName), + Output: expect.DoesNotContain(repoName), }) }, } @@ -363,7 +366,7 @@ func TestRemoveKubeWithKubeHideDupe(t *testing.T) { numTags = len(strings.Split(strings.TrimSpace(helpers.Capture("--kube-hide-dupe", "images")), "\n")) numNoTags = len(strings.Split(strings.TrimSpace(helpers.Capture("images")), "\n")) } - testCase.Require = test.Require( + testCase.Require = require.All( nerdtest.OnlyKubernetes, ) testCase.SubTests = []*test.Case{ diff --git a/cmd/nerdctl/image/image_save_test.go b/cmd/nerdctl/image/image_save_test.go index 9e2dae5cda0..7e61ef6e28f 100644 --- a/cmd/nerdctl/image/image_save_test.go +++ b/cmd/nerdctl/image/image_save_test.go @@ -25,10 +25,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestSaveContent(t *testing.T) { @@ -36,7 +39,7 @@ func TestSaveContent(t *testing.T) { testCase := &test.Case{ // FIXME: move to busybox for windows? - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) }, @@ -103,7 +106,7 @@ func TestSave(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get("id"), "sh", "-euxc", "echo foo") }, - Expected: test.Expects(0, nil, test.Equals("foo\n")), + Expected: test.Expects(0, nil, expect.Equals("foo\n")), }, { Description: "Image with different names, by id", @@ -132,7 +135,7 @@ func TestSave(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get("id"), "sh", "-euxc", "echo foo") }, - Expected: test.Expects(0, nil, test.Equals("foo\n")), + Expected: test.Expects(0, nil, expect.Equals("foo\n")), }, } diff --git a/cmd/nerdctl/ipfs/ipfs_compose_linux_test.go b/cmd/nerdctl/ipfs/ipfs_compose_linux_test.go index e1b78cc4c1e..aa36f35b08e 100644 --- a/cmd/nerdctl/ipfs/ipfs_compose_linux_test.go +++ b/cmd/nerdctl/ipfs/ipfs_compose_linux_test.go @@ -26,12 +26,14 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" "github.com/containerd/nerdctl/v2/pkg/testutil/portlock" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestIPFSCompNoBuild(t *testing.T) { @@ -41,9 +43,9 @@ func TestIPFSCompNoBuild(t *testing.T) { var ipfsRegistry *registry.Server - testCase.Require = test.Require( - test.Linux, - test.Not(nerdtest.Docker), + testCase.Require = require.All( + require.Linux, + require.Not(nerdtest.Docker), nerdtest.Registry, nerdtest.IPFS, nerdtest.IsFlaky("https://github.com/containerd/nerdctl/issues/3510"), @@ -194,11 +196,11 @@ func TestIPFSCompBuild(t *testing.T) { assert.NilError(t, err) var listenAddr = "localhost:" + strconv.Itoa(safePort) - testCase.Require = test.Require( + testCase.Require = require.All( // Linux only - test.Linux, + require.Linux, // Obviously not docker supported - test.Not(nerdtest.Docker), + require.Not(nerdtest.Docker), nerdtest.Build, nerdtest.IPFS, ) diff --git a/cmd/nerdctl/ipfs/ipfs_kubo_linux_test.go b/cmd/nerdctl/ipfs/ipfs_kubo_linux_test.go index cb21a839779..93cf046b0d3 100644 --- a/cmd/nerdctl/ipfs/ipfs_kubo_linux_test.go +++ b/cmd/nerdctl/ipfs/ipfs_kubo_linux_test.go @@ -21,10 +21,13 @@ import ( "regexp" "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestIPFSAddrWithKubo(t *testing.T) { @@ -35,9 +38,9 @@ func TestIPFSAddrWithKubo(t *testing.T) { var ipfsRegistry *registry.Server - testCase.Require = test.Require( - test.Linux, - test.Not(nerdtest.Docker), + testCase.Require = require.All( + require.Linux, + require.Not(nerdtest.Docker), nerdtest.Registry, nerdtest.Private, ) @@ -74,12 +77,12 @@ func TestIPFSAddrWithKubo(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get(mainImageCIDKey), "echo", "hello") }, - Expected: test.Expects(0, nil, test.Equals("hello\n")), + Expected: test.Expects(0, nil, expect.Equals("hello\n")), }, { Description: "with stargz snapshotter", NoParallel: true, - Require: test.Require( + Require: require.All( nerdtest.Stargz, nerdtest.Private, nerdtest.NerdctlNeedsFixing("https://github.com/containerd/nerdctl/issues/3475"), @@ -97,7 +100,7 @@ func TestIPFSAddrWithKubo(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get(mainImageCIDKey), "ls", "/.stargz-snapshotter") }, - Expected: test.Expects(0, nil, test.Match(regexp.MustCompile("sha256:.*[.]json[\n]"))), + Expected: test.Expects(0, nil, expect.Match(regexp.MustCompile("sha256:.*[.]json[\n]"))), }, } diff --git a/cmd/nerdctl/ipfs/ipfs_registry_linux_test.go b/cmd/nerdctl/ipfs/ipfs_registry_linux_test.go index 3b4f61183e8..20865efc834 100644 --- a/cmd/nerdctl/ipfs/ipfs_registry_linux_test.go +++ b/cmd/nerdctl/ipfs/ipfs_registry_linux_test.go @@ -27,9 +27,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func pushToIPFS(helpers test.Helpers, name string, opts ...string) string { @@ -56,9 +59,9 @@ func TestIPFSNerdctlRegistry(t *testing.T) { var ipfsServer test.TestableCommand - testCase.Require = test.Require( - test.Linux, - test.Not(nerdtest.Docker), + testCase.Require = require.All( + require.Linux, + require.Not(nerdtest.Docker), nerdtest.IPFS, ) @@ -96,7 +99,7 @@ func TestIPFSNerdctlRegistry(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get(ipfsImageURLKey), "echo", "hello") }, - Expected: test.Expects(0, nil, test.Equals("hello\n")), + Expected: test.Expects(0, nil, expect.Equals("hello\n")), }, { Description: "with stargz snapshotterr", @@ -114,7 +117,7 @@ func TestIPFSNerdctlRegistry(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get(ipfsImageURLKey), "ls", "/.stargz-snapshotter") }, - Expected: test.Expects(0, nil, test.Match(regexp.MustCompile("sha256:.*[.]json[\n]"))), + Expected: test.Expects(0, nil, expect.Match(regexp.MustCompile("sha256:.*[.]json[\n]"))), }, { Description: "with build", @@ -142,7 +145,7 @@ CMD ["echo", "nerdctl-build-test-string"] Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Identifier("built-image")) }, - Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")), + Expected: test.Expects(0, nil, expect.Equals("nerdctl-build-test-string\n")), }, } diff --git a/cmd/nerdctl/ipfs/ipfs_simple_linux_test.go b/cmd/nerdctl/ipfs/ipfs_simple_linux_test.go index f2d59a15618..581704ec6fd 100644 --- a/cmd/nerdctl/ipfs/ipfs_simple_linux_test.go +++ b/cmd/nerdctl/ipfs/ipfs_simple_linux_test.go @@ -20,10 +20,13 @@ import ( "regexp" "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestIPFSSimple(t *testing.T) { @@ -32,9 +35,9 @@ func TestIPFSSimple(t *testing.T) { const mainImageCIDKey = "mainImageCIDKey" const transformedImageCIDKey = "transformedImageCIDKey" - testCase.Require = test.Require( - test.Linux, - test.Not(nerdtest.Docker), + testCase.Require = require.All( + require.Linux, + require.Not(nerdtest.Docker), nerdtest.IPFS, // We constantly rmi the image by its CID which is shared across tests, so, we make this group private // and every subtest NoParallel @@ -61,12 +64,12 @@ func TestIPFSSimple(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get(mainImageCIDKey), "echo", "hello") }, - Expected: test.Expects(0, nil, test.Equals("hello\n")), + Expected: test.Expects(0, nil, expect.Equals("hello\n")), }, { Description: "with stargz snapshotter", NoParallel: true, - Require: test.Require( + Require: require.All( nerdtest.Stargz, nerdtest.NerdctlNeedsFixing("https://github.com/containerd/nerdctl/issues/3475"), ), @@ -82,7 +85,7 @@ func TestIPFSSimple(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", data.Get(mainImageCIDKey), "ls", "/.stargz-snapshotter") }, - Expected: test.Expects(0, nil, test.Match(regexp.MustCompile("sha256:.*[.]json[\n]"))), + Expected: test.Expects(0, nil, expect.Match(regexp.MustCompile("sha256:.*[.]json[\n]"))), }, { Description: "with commit and push", @@ -116,12 +119,12 @@ func TestIPFSSimple(t *testing.T) { return helpers.Command("run", "--rm", data.Get(transformedImageCIDKey), "cat", "/hello") }, - Expected: test.Expects(0, nil, test.Equals("hello\n")), + Expected: test.Expects(0, nil, expect.Equals("hello\n")), }, { Description: "with commit and push, stargz lazy pulling", NoParallel: true, - Require: test.Require( + Require: require.All( nerdtest.Stargz, nerdtest.NerdctlNeedsFixing("https://github.com/containerd/nerdctl/issues/3475"), ), @@ -154,12 +157,12 @@ func TestIPFSSimple(t *testing.T) { return helpers.Command("run", "--rm", data.Get(transformedImageCIDKey), "sh", "-c", "--", "cat /hello && ls /.stargz-snapshotter") }, - Expected: test.Expects(0, nil, test.Match(regexp.MustCompile("hello[\n]sha256:.*[.]json[\n]"))), + Expected: test.Expects(0, nil, expect.Match(regexp.MustCompile("hello[\n]sha256:.*[.]json[\n]"))), }, { Description: "with encryption", NoParallel: true, - Require: test.Binary("openssl"), + Require: require.Binary("openssl"), Setup: func(data test.Data, helpers test.Helpers) { data.Set(mainImageCIDKey, pushToIPFS(helpers, testutil.CommonImage)) helpers.Ensure("pull", "ipfs://"+data.Get(mainImageCIDKey)) @@ -175,11 +178,11 @@ func TestIPFSSimple(t *testing.T) { helpers.Ensure("image", "encrypt", "--recipient=jwe:"+keyPair.Pub, data.Get(mainImageCIDKey), data.Identifier("encrypted")) cmd := helpers.Command("image", "inspect", "--mode=native", "--format={{len .Index.Manifests}}", data.Identifier("encrypted")) cmd.Run(&test.Expected{ - Output: test.Equals("1\n"), + Output: expect.Equals("1\n"), }) cmd = helpers.Command("image", "inspect", "--mode=native", "--format={{json (index .Manifest.Layers 0) }}", data.Identifier("encrypted")) cmd.Run(&test.Expected{ - Output: test.Contains("org.opencontainers.image.enc.keys.jwe"), + Output: expect.Contains("org.opencontainers.image.enc.keys.jwe"), }) // Push the encrypted image and save the CID diff --git a/cmd/nerdctl/issues/issues_linux_test.go b/cmd/nerdctl/issues/issues_linux_test.go index 3f9e89ffd89..7b4949296fa 100644 --- a/cmd/nerdctl/issues/issues_linux_test.go +++ b/cmd/nerdctl/issues/issues_linux_test.go @@ -22,10 +22,12 @@ import ( "fmt" "testing" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestIssue3425(t *testing.T) { @@ -105,10 +107,10 @@ func TestIssue3425(t *testing.T) { }, { Description: "with convert", - Require: test.Require( + Require: require.All( nerdtest.Private, - test.Not(test.Windows), - test.Not(nerdtest.Docker), + require.Not(require.Windows), + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("image", "pull", testutil.CommonImage) @@ -127,11 +129,11 @@ func TestIssue3425(t *testing.T) { }, { Description: "with ipfs", - Require: test.Require( + Require: require.All( nerdtest.Private, nerdtest.IPFS, - test.Not(test.Windows), - test.Not(nerdtest.Docker), + require.Not(require.Windows), + require.Not(nerdtest.Docker), ), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("image", "pull", testutil.CommonImage) diff --git a/cmd/nerdctl/issues/main_linux_test.go b/cmd/nerdctl/issues/main_linux_test.go index a1af21d8ff5..4703897a7e2 100644 --- a/cmd/nerdctl/issues/main_linux_test.go +++ b/cmd/nerdctl/issues/main_linux_test.go @@ -19,9 +19,11 @@ package issues import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestMain(m *testing.M) { @@ -41,7 +43,7 @@ func TestIssue108(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(0, nil, test.Equals("this was always working\r\n")), + Expected: test.Expects(0, nil, expect.Equals("this was always working\r\n")), }, { Description: "--net=host -it", @@ -50,7 +52,7 @@ func TestIssue108(t *testing.T) { cmd.WithPseudoTTY() return cmd }, - Expected: test.Expects(0, nil, test.Equals("this was not working due to issue #108\r\n")), + Expected: test.Expects(0, nil, expect.Equals("this was not working due to issue #108\r\n")), }, } diff --git a/cmd/nerdctl/login/login_linux_test.go b/cmd/nerdctl/login/login_linux_test.go index 2ac21fa374f..3eab9293db5 100644 --- a/cmd/nerdctl/login/login_linux_test.go +++ b/cmd/nerdctl/login/login_linux_test.go @@ -29,9 +29,10 @@ import ( "gotest.tools/v3/icmd" + "github.com/containerd/nerdctl/mod/tigron/utils" + "github.com/containerd/nerdctl/v2/pkg/imgutil/dockerconfigresolver" "github.com/containerd/nerdctl/v2/pkg/testutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" "github.com/containerd/nerdctl/v2/pkg/testutil/testca" "github.com/containerd/nerdctl/v2/pkg/testutil/testregistry" ) @@ -109,8 +110,8 @@ func TestLoginPersistence(t *testing.T) { t.Run(fmt.Sprintf("Server %s", tc.auth), func(t *testing.T) { t.Parallel() - username := test.RandomStringBase64(30) + "∞" - password := test.RandomStringBase64(30) + ":∞" + username := utils.RandomStringBase64(30) + "∞" + password := utils.RandomStringBase64(30) + ":∞" // Add the requested authentication var auth testregistry.Auth @@ -298,8 +299,8 @@ func TestLoginAgainstVariants(t *testing.T) { } // Generate credentials that are specific to each registry, so that we never cross hit another one - username := test.RandomStringBase64(30) + "∞" - password := test.RandomStringBase64(30) + ":∞" + username := utils.RandomStringBase64(30) + "∞" + password := utils.RandomStringBase64(30) + ":∞" // Get a CA if we want TLS var ca *testca.CA diff --git a/cmd/nerdctl/main_test.go b/cmd/nerdctl/main_test.go index 49aac4a0813..bcd84434556 100644 --- a/cmd/nerdctl/main_test.go +++ b/cmd/nerdctl/main_test.go @@ -21,10 +21,12 @@ import ( "testing" "github.com/containerd/containerd/v2/defaults" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestMain(m *testing.M) { @@ -66,12 +68,12 @@ func TestUnknownCommand(t *testing.T) { { Description: "system info", Command: test.Command("system", "info"), - Expected: test.Expects(0, nil, test.Contains("Kernel Version:")), + Expected: test.Expects(0, nil, expect.Contains("Kernel Version:")), }, { Description: "info", Command: test.Command("info"), - Expected: test.Expects(0, nil, test.Contains("Kernel Version:")), + Expected: test.Expects(0, nil, expect.Contains("Kernel Version:")), }, } @@ -83,38 +85,38 @@ func TestNerdctlConfig(t *testing.T) { testCase := nerdtest.Setup() // Docker does not support nerdctl.toml obviously - testCase.Require = test.Not(nerdtest.Docker) + testCase.Require = require.Not(nerdtest.Docker) testCase.SubTests = []*test.Case{ { Description: "Default", Command: test.Command("info", "-f", "{{.Driver}}"), - Expected: test.Expects(0, nil, test.Equals(defaults.DefaultSnapshotter+"\n")), + Expected: test.Expects(0, nil, expect.Equals(defaults.DefaultSnapshotter+"\n")), }, { Description: "TOML > Default", Command: test.Command("info", "-f", "{{.Driver}}"), - Expected: test.Expects(0, nil, test.Equals("dummy-snapshotter-via-toml\n")), + Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-toml\n")), Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`), }, { Description: "Cli > TOML > Default", Command: test.Command("info", "-f", "{{.Driver}}", "--snapshotter=dummy-snapshotter-via-cli"), - Expected: test.Expects(0, nil, test.Equals("dummy-snapshotter-via-cli\n")), + Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-cli\n")), Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`), }, { Description: "Env > TOML > Default", Command: test.Command("info", "-f", "{{.Driver}}"), Env: map[string]string{"CONTAINERD_SNAPSHOTTER": "dummy-snapshotter-via-env"}, - Expected: test.Expects(0, nil, test.Equals("dummy-snapshotter-via-env\n")), + Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-env\n")), Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`), }, { Description: "Cli > Env > TOML > Default", Command: test.Command("info", "-f", "{{.Driver}}", "--snapshotter=dummy-snapshotter-via-cli"), Env: map[string]string{"CONTAINERD_SNAPSHOTTER": "dummy-snapshotter-via-env"}, - Expected: test.Expects(0, nil, test.Equals("dummy-snapshotter-via-cli\n")), + Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-cli\n")), Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`), }, { diff --git a/cmd/nerdctl/main_test_test.go b/cmd/nerdctl/main_test_test.go index 695c52bac07..36c6a96e3a9 100644 --- a/cmd/nerdctl/main_test_test.go +++ b/cmd/nerdctl/main_test_test.go @@ -21,8 +21,10 @@ import ( "log" "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) // TestTest is testing the test tooling itself @@ -48,12 +50,12 @@ func TestTest(t *testing.T) { { Description: "success with contains output testing", Command: test.Command("info"), - Expected: test.Expects(0, nil, test.Contains("Kernel")), + Expected: test.Expects(0, nil, expect.Contains("Kernel")), }, { Description: "success with negative output testing", Command: test.Command("info"), - Expected: test.Expects(0, nil, test.DoesNotContain("foobar")), + Expected: test.Expects(0, nil, expect.DoesNotContain("foobar")), }, // Note that docker annoyingly returns 125 in a few conditions like this { @@ -66,7 +68,7 @@ func TestTest(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Custom("echo", "foobar") }, - Expected: test.Expects(0, nil, test.Equals("foobar\n")), + Expected: test.Expects(0, nil, expect.Equals("foobar\n")), }, { Description: "data propagation", @@ -94,10 +96,10 @@ func TestTest(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Custom("printf", data.Get("status")) }, - Expected: test.Expects(0, nil, test.Equals("uninitialized-setup-command")), + Expected: test.Expects(0, nil, expect.Equals("uninitialized-setup-command")), }, }, - Expected: test.Expects(0, nil, test.Equals("uninitialized-setup")), + Expected: test.Expects(0, nil, expect.Equals("uninitialized-setup")), }, } diff --git a/cmd/nerdctl/network/network_create_linux_test.go b/cmd/nerdctl/network/network_create_linux_test.go index 15012eabe88..418f07fde74 100644 --- a/cmd/nerdctl/network/network_create_linux_test.go +++ b/cmd/nerdctl/network/network_create_linux_test.go @@ -23,10 +23,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + ipv6helper "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestNetworkCreate(t *testing.T) { @@ -74,7 +76,7 @@ func TestNetworkCreate(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--rm", "--net", data.Identifier(), testutil.CommonImage, "ifconfig", "eth0") }, - Expected: test.Expects(0, nil, test.Contains("MTU:9216")), + Expected: test.Expects(0, nil, expect.Contains("MTU:9216")), }, { Description: "with ipv6", diff --git a/cmd/nerdctl/network/network_inspect_test.go b/cmd/nerdctl/network/network_inspect_test.go index d493db498fd..cb89f25f2d4 100644 --- a/cmd/nerdctl/network/network_inspect_test.go +++ b/cmd/nerdctl/network/network_inspect_test.go @@ -24,9 +24,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestNetworkInspect(t *testing.T) { @@ -86,7 +89,7 @@ func TestNetworkInspect(t *testing.T) { }, { Description: "bridge", - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Command: test.Command("network", "inspect", "bridge"), Expected: test.Expects(0, nil, func(stdout string, info string, t *testing.T) { var dc []dockercompat.Network @@ -98,7 +101,7 @@ func TestNetworkInspect(t *testing.T) { }, { Description: "nat", - Require: test.Windows, + Require: require.Windows, Command: test.Command("network", "inspect", "nat"), Expected: test.Expects(0, nil, func(stdout string, info string, t *testing.T) { var dc []dockercompat.Network @@ -148,7 +151,7 @@ func TestNetworkInspect(t *testing.T) { Description: "match part of id", // FIXME: for windows, network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} MAY fail here // This is bizarre, as it is working in the match exact id test - and there does not seem to be a particular reason for that - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { id := strings.TrimSpace(helpers.Capture("network", "inspect", data.Get("basenet"), "--format", "{{ .Id }}")) return helpers.Command("network", "inspect", id[0:25]) @@ -169,7 +172,7 @@ func TestNetworkInspect(t *testing.T) { Description: "using another net short id", // FIXME: for windows, network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} MAY fail here // This is bizarre, as it is working in the match exact id test - and there does not seem to be a particular reason for that - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { id := strings.TrimSpace(helpers.Capture("network", "inspect", data.Get("basenet"), "--format", "{{ .Id }}")) helpers.Ensure("network", "create", id[0:12]) @@ -196,7 +199,7 @@ func TestNetworkInspect(t *testing.T) { { Description: "basic", // FIXME: IPAMConfig is not implemented on Windows yet - Require: test.Not(test.Windows), + Require: require.Not(require.Windows), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("network", "create", "--label", "tag=testNetwork", "--subnet", testSubnet, "--gateway", testGateway, "--ip-range", testIPRange, data.Identifier()) @@ -230,7 +233,7 @@ func TestNetworkInspect(t *testing.T) { }, { Description: "with namespace", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Cleanup: func(data test.Data, helpers test.Helpers) { identifier := data.Identifier() helpers.Anyhow("network", "rm", identifier) @@ -263,13 +266,13 @@ func TestNetworkInspect(t *testing.T) { com = cmd.Clone() com.WithArgs("network", "ls") com.Run(&test.Expected{ - Output: test.DoesNotContain(data.Identifier()), + Output: expect.DoesNotContain(data.Identifier()), }) com = cmd.Clone() com.WithArgs("network", "prune", "-f") com.Run(&test.Expected{ - Output: test.DoesNotContain(data.Identifier()), + Output: expect.DoesNotContain(data.Identifier()), }) }, } diff --git a/cmd/nerdctl/network/network_list_linux_test.go b/cmd/nerdctl/network/network_list_linux_test.go index 22620287a66..96f35dedf2e 100644 --- a/cmd/nerdctl/network/network_list_linux_test.go +++ b/cmd/nerdctl/network/network_list_linux_test.go @@ -22,8 +22,9 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestNetworkLsFilter(t *testing.T) { diff --git a/cmd/nerdctl/network/network_prune_linux_test.go b/cmd/nerdctl/network/network_prune_linux_test.go index 5c1fc0bfb17..2cf6eb95db3 100644 --- a/cmd/nerdctl/network/network_prune_linux_test.go +++ b/cmd/nerdctl/network/network_prune_linux_test.go @@ -19,9 +19,11 @@ package network import ( "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestNetworkPrune(t *testing.T) { @@ -45,7 +47,7 @@ func TestNetworkPrune(t *testing.T) { Command: test.Command("network", "prune", "-f"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.DoesNotContain(data.Identifier()), + Output: expect.DoesNotContain(data.Identifier()), } }, }, @@ -64,7 +66,7 @@ func TestNetworkPrune(t *testing.T) { Command: test.Command("network", "prune", "-f"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Contains(data.Identifier()), + Output: expect.Contains(data.Identifier()), } }, }, diff --git a/cmd/nerdctl/network/network_remove_linux_test.go b/cmd/nerdctl/network/network_remove_linux_test.go index f1d6e2e5876..48906cbad08 100644 --- a/cmd/nerdctl/network/network_remove_linux_test.go +++ b/cmd/nerdctl/network/network_remove_linux_test.go @@ -23,9 +23,10 @@ import ( "github.com/vishvananda/netlink" "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestNetworkRemove(t *testing.T) { diff --git a/cmd/nerdctl/system/system_events_linux_test.go b/cmd/nerdctl/system/system_events_linux_test.go index ae371ec479b..20f1f8e3f06 100644 --- a/cmd/nerdctl/system/system_events_linux_test.go +++ b/cmd/nerdctl/system/system_events_linux_test.go @@ -20,9 +20,12 @@ import ( "testing" "time" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func testEventFilterExecutor(data test.Data, helpers test.Helpers) test.TestableCommand { @@ -38,12 +41,12 @@ func TestEventFilters(t *testing.T) { testCase.SubTests = []*test.Case{ { Description: "CapitalizedFilter", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: testEventFilterExecutor, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - ExitCode: test.ExitCodeTimeout, - Output: test.Contains(data.Get("output")), + ExitCode: expect.ExitCodeTimeout, + Output: expect.Contains(data.Get("output")), } }, Data: test.WithData("filter", "event=START"). @@ -54,8 +57,8 @@ func TestEventFilters(t *testing.T) { Command: testEventFilterExecutor, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - ExitCode: test.ExitCodeTimeout, - Output: test.Contains(data.Get("output")), + ExitCode: expect.ExitCodeTimeout, + Output: expect.Contains(data.Get("output")), } }, Data: test.WithData("filter", "event=start"). @@ -63,12 +66,12 @@ func TestEventFilters(t *testing.T) { }, { Description: "UnsupportedEventFilter", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: testEventFilterExecutor, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - ExitCode: test.ExitCodeTimeout, - Output: test.Contains(data.Get("output")), + ExitCode: expect.ExitCodeTimeout, + Output: expect.Contains(data.Get("output")), } }, Data: test.WithData("filter", "event=unknown"). @@ -79,8 +82,8 @@ func TestEventFilters(t *testing.T) { Command: testEventFilterExecutor, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - ExitCode: test.ExitCodeTimeout, - Output: test.Contains(data.Get("output")), + ExitCode: expect.ExitCodeTimeout, + Output: expect.Contains(data.Get("output")), } }, Data: test.WithData("filter", "status=start"). @@ -88,12 +91,12 @@ func TestEventFilters(t *testing.T) { }, { Description: "UnsupportedStatusFilter", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: testEventFilterExecutor, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - ExitCode: test.ExitCodeTimeout, - Output: test.Contains(data.Get("output")), + ExitCode: expect.ExitCodeTimeout, + Output: expect.Contains(data.Get("output")), } }, Data: test.WithData("filter", "status=unknown"). diff --git a/cmd/nerdctl/system/system_info_test.go b/cmd/nerdctl/system/system_info_test.go index dc4af4b0381..6248a1e0711 100644 --- a/cmd/nerdctl/system/system_info_test.go +++ b/cmd/nerdctl/system/system_info_test.go @@ -23,10 +23,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/infoutil" "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func testInfoComparator(stdout string, info string, t *testing.T) { @@ -53,22 +56,22 @@ func TestInfo(t *testing.T) { }, { Description: "info with namespace", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Custom("nerdctl", "info") }, - Expected: test.Expects(0, nil, test.Contains("Namespace: default")), + Expected: test.Expects(0, nil, expect.Contains("Namespace: default")), }, { Description: "info with namespace env var", Env: map[string]string{ "CONTAINERD_NAMESPACE": "test", }, - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Custom("nerdctl", "info") }, - Expected: test.Expects(0, nil, test.Contains("Namespace: test")), + Expected: test.Expects(0, nil, expect.Contains("Namespace: test")), }, } diff --git a/cmd/nerdctl/system/system_prune_linux_test.go b/cmd/nerdctl/system/system_prune_linux_test.go index 1d47b26690c..45a0b896d01 100644 --- a/cmd/nerdctl/system/system_prune_linux_test.go +++ b/cmd/nerdctl/system/system_prune_linux_test.go @@ -23,9 +23,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestSystemPrune(t *testing.T) { @@ -76,7 +79,7 @@ func TestSystemPrune(t *testing.T) { // FIXME: using a dedicated namespace does not work with rootful (because of buildkitd) NoParallel: true, // buildkitd is not available with docker - Require: test.Require(nerdtest.Build, test.Not(nerdtest.Docker)), + Require: require.All(nerdtest.Build, require.Not(nerdtest.Docker)), // FIXME: this test will happily say "green" even if the command actually fails to do its duty // if there is nothing in the build cache. // Ensure with setup here that we DO build something first @@ -86,7 +89,7 @@ func TestSystemPrune(t *testing.T) { Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return nerdtest.BuildCtlCommand(helpers, "du") }, - Expected: test.Expects(0, nil, test.Contains("Total:\t\t0B")), + Expected: test.Expects(0, nil, expect.Contains("Total:\t\t0B")), }, } diff --git a/cmd/nerdctl/volume/volume_create_test.go b/cmd/nerdctl/volume/volume_create_test.go index 1cde5336199..8e761c6e015 100644 --- a/cmd/nerdctl/volume/volume_create_test.go +++ b/cmd/nerdctl/volume/volume_create_test.go @@ -22,9 +22,10 @@ import ( "testing" "github.com/containerd/errdefs" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestVolumeCreate(t *testing.T) { @@ -34,7 +35,7 @@ func TestVolumeCreate(t *testing.T) { { Description: "arg missing should create anonymous volume", Command: test.Command("volume", "create"), - Expected: test.Expects(0, nil, test.Match(regexp.MustCompile("^[a-f0-9]{64}\n$"))), + Expected: test.Expects(0, nil, expect.Match(regexp.MustCompile("^[a-f0-9]{64}\n$"))), }, { Description: "invalid identifier should fail", @@ -56,7 +57,7 @@ func TestVolumeCreate(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Equals(data.Identifier() + "\n"), + Output: expect.Equals(data.Identifier() + "\n"), } }, }, @@ -70,7 +71,7 @@ func TestVolumeCreate(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Equals(data.Identifier() + "\n"), + Output: expect.Equals(data.Identifier() + "\n"), } }, }, @@ -99,7 +100,7 @@ func TestVolumeCreate(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Equals(data.Identifier() + "\n"), + Output: expect.Equals(data.Identifier() + "\n"), } }, }, diff --git a/cmd/nerdctl/volume/volume_inspect_test.go b/cmd/nerdctl/volume/volume_inspect_test.go index a7ec478b55a..7e627a119b5 100644 --- a/cmd/nerdctl/volume/volume_inspect_test.go +++ b/cmd/nerdctl/volume/volume_inspect_test.go @@ -28,10 +28,12 @@ import ( "gotest.tools/v3/assert" "github.com/containerd/errdefs" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/pkg/inspecttypes/native" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func createFileWithSize(mountPoint string, size int64) error { @@ -95,8 +97,8 @@ func TestVolumeInspect(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(data.Get("vol1")), + Output: expect.All( + expect.Contains(data.Get("vol1")), func(stdout string, info string, t *testing.T) { var dc []native.Volume if err := json.Unmarshal([]byte(stdout), &dc); err != nil { @@ -117,8 +119,8 @@ func TestVolumeInspect(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(data.Get("vol2")), + Output: expect.All( + expect.Contains(data.Get("vol2")), func(stdout string, info string, t *testing.T) { var dc []native.Volume if err := json.Unmarshal([]byte(stdout), &dc); err != nil { @@ -135,14 +137,14 @@ func TestVolumeInspect(t *testing.T) { }, { Description: "inspect size", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("volume", "inspect", "--size", data.Get("vol1")) }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(data.Get("vol1")), + Output: expect.All( + expect.Contains(data.Get("vol1")), func(stdout string, info string, t *testing.T) { var dc []native.Volume if err := json.Unmarshal([]byte(stdout), &dc); err != nil { @@ -161,9 +163,9 @@ func TestVolumeInspect(t *testing.T) { }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.Contains(data.Get("vol1")), - test.Contains(data.Get("vol2")), + Output: expect.All( + expect.Contains(data.Get("vol1")), + expect.Contains(data.Get("vol2")), func(stdout string, info string, t *testing.T) { var dc []native.Volume if err := json.Unmarshal([]byte(stdout), &dc); err != nil { @@ -186,8 +188,8 @@ func TestVolumeInspect(t *testing.T) { return &test.Expected{ ExitCode: 1, Errors: []error{errdefs.ErrNotFound, errdefs.ErrInvalidArgument}, - Output: test.All( - test.Contains(data.Get("vol1")), + Output: expect.All( + expect.Contains(data.Get("vol1")), func(stdout string, info string, t *testing.T) { var dc []native.Volume if err := json.Unmarshal([]byte(stdout), &dc); err != nil { diff --git a/cmd/nerdctl/volume/volume_list_test.go b/cmd/nerdctl/volume/volume_list_test.go index d48b35809c3..0610925df32 100644 --- a/cmd/nerdctl/volume/volume_list_test.go +++ b/cmd/nerdctl/volume/volume_list_test.go @@ -24,16 +24,18 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/tabutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestVolumeLsSize(t *testing.T) { nerdtest.Setup() tc := &test.Case{ - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("volume", "create", data.Identifier("1")) helpers.Ensure("volume", "create", data.Identifier("2")) @@ -304,7 +306,7 @@ func TestVolumeLsFilter(t *testing.T) { }, { Description: "Retrieving size=1024000", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("volume", "ls", "--size", "--filter", "size=1024000") }, @@ -335,7 +337,7 @@ func TestVolumeLsFilter(t *testing.T) { }, { Description: "Retrieving size>=1024000 size<=2048000", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("volume", "ls", "--size", "--filter", "size>=1024000", "--filter", "size<=2048000") }, @@ -366,7 +368,7 @@ func TestVolumeLsFilter(t *testing.T) { }, { Description: "Retrieving size>204800 size<1024000", - Require: test.Not(nerdtest.Docker), + Require: require.Not(nerdtest.Docker), Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("volume", "ls", "--size", "--filter", "size>204800", "--filter", "size<1024000") }, diff --git a/cmd/nerdctl/volume/volume_namespace_test.go b/cmd/nerdctl/volume/volume_namespace_test.go index c2a2d6ce3db..a4b351d9286 100644 --- a/cmd/nerdctl/volume/volume_namespace_test.go +++ b/cmd/nerdctl/volume/volume_namespace_test.go @@ -20,16 +20,18 @@ import ( "testing" "github.com/containerd/errdefs" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestVolumeNamespace(t *testing.T) { testCase := nerdtest.Setup() // Docker does not support namespaces - testCase.Require = test.Not(nerdtest.Docker) + testCase.Require = require.Not(nerdtest.Docker) // Create a volume in a different namespace testCase.Setup = func(data test.Data, helpers test.Helpers) { @@ -72,8 +74,8 @@ func TestVolumeNamespace(t *testing.T) { Command: test.Command("volume", "prune", "-a", "-f"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.DoesNotContain(data.Get("root_volume")), + Output: expect.All( + expect.DoesNotContain(data.Get("root_volume")), func(stdout string, info string, t *testing.T) { helpers.Ensure("--namespace", data.Get("root_namespace"), "volume", "inspect", data.Get("root_volume")) }, diff --git a/cmd/nerdctl/volume/volume_prune_linux_test.go b/cmd/nerdctl/volume/volume_prune_linux_test.go index c33922c730b..10b4e6b85f6 100644 --- a/cmd/nerdctl/volume/volume_prune_linux_test.go +++ b/cmd/nerdctl/volume/volume_prune_linux_test.go @@ -20,9 +20,11 @@ import ( "strings" "testing" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func TestVolumePrune(t *testing.T) { @@ -66,11 +68,11 @@ func TestVolumePrune(t *testing.T) { Command: test.Command("volume", "prune", "-f"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.DoesNotContain(data.Get("anonIDBusy")), - test.Contains(data.Get("anonIDDangling")), - test.DoesNotContain(data.Get("namedBusy")), - test.DoesNotContain(data.Get("namedDangling")), + Output: expect.All( + expect.DoesNotContain(data.Get("anonIDBusy")), + expect.Contains(data.Get("anonIDDangling")), + expect.DoesNotContain(data.Get("namedBusy")), + expect.DoesNotContain(data.Get("namedDangling")), func(stdout string, info string, t *testing.T) { helpers.Ensure("volume", "inspect", data.Get("anonIDBusy")) helpers.Fail("volume", "inspect", data.Get("anonIDDangling")) @@ -89,11 +91,11 @@ func TestVolumePrune(t *testing.T) { Command: test.Command("volume", "prune", "-f", "--all"), Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.All( - test.DoesNotContain(data.Get("anonIDBusy")), - test.Contains(data.Get("anonIDDangling")), - test.DoesNotContain(data.Get("namedBusy")), - test.Contains(data.Get("namedDangling")), + Output: expect.All( + expect.DoesNotContain(data.Get("anonIDBusy")), + expect.Contains(data.Get("anonIDDangling")), + expect.DoesNotContain(data.Get("namedBusy")), + expect.Contains(data.Get("namedDangling")), func(stdout string, info string, t *testing.T) { helpers.Ensure("volume", "inspect", data.Get("anonIDBusy")) helpers.Fail("volume", "inspect", data.Get("anonIDDangling")) diff --git a/cmd/nerdctl/volume/volume_remove_linux_test.go b/cmd/nerdctl/volume/volume_remove_linux_test.go index 50bd936d6da..01680bd30ec 100644 --- a/cmd/nerdctl/volume/volume_remove_linux_test.go +++ b/cmd/nerdctl/volume/volume_remove_linux_test.go @@ -24,10 +24,11 @@ import ( "gotest.tools/v3/assert" "github.com/containerd/errdefs" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) // TestVolumeRemove does test a large variety of volume remove situations, albeit none of them being @@ -123,7 +124,7 @@ func TestVolumeRemove(t *testing.T) { Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Equals(data.Identifier() + "\n"), + Output: expect.Equals(data.Identifier() + "\n"), } }, }, @@ -144,7 +145,7 @@ func TestVolumeRemove(t *testing.T) { Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Equals(data.Identifier() + "\n"), + Output: expect.Equals(data.Identifier() + "\n"), } }, }, @@ -175,7 +176,7 @@ func TestVolumeRemove(t *testing.T) { errdefs.ErrFailedPrecondition, errdefs.ErrInvalidArgument, }, - Output: test.Equals(data.Identifier() + "\n"), + Output: expect.Equals(data.Identifier() + "\n"), } }, }, @@ -197,7 +198,7 @@ func TestVolumeRemove(t *testing.T) { Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ - Output: test.Equals(data.Identifier("1") + "\n" + data.Identifier("2") + "\n"), + Output: expect.Equals(data.Identifier("1") + "\n" + data.Identifier("2") + "\n"), } }, }, diff --git a/docs/testing/tools.md b/docs/testing/tools.md index 2f53441b30c..70230ae663b 100644 --- a/docs/testing/tools.md +++ b/docs/testing/tools.md @@ -24,7 +24,9 @@ import ( "testing" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/expect" ) func TestMyThing(t *testing.T) { @@ -33,7 +35,7 @@ func TestMyThing(t *testing.T) { // This is going to run `nerdctl info` (or `docker info`) mytest.Command = test.Command("info") // Verify the command exits with 0, and stdout contains the word `Kernel` - myTest.Expected = test.Expects(0, nil, test.Contains("Kernel")) + myTest.Expected = test.Expects(0, nil, expect.Contains("Kernel")) // Run it myTest.Run(t) } @@ -63,11 +65,11 @@ Secondly, `test.Contains` - which is a `Comparator`. ### Comparators -Besides `test.Contains(string)`, there are a few more: -- `test.DoesNotContain(string)` -- `test.Equals(string)` -- `test.Match(*regexp.Regexp)` -- `test.All(comparators ...Comparator)`, which allows you to bundle together a bunch of other comparators +Besides `expect.Contains(string)`, there are a few more: +- `expect.DoesNotContain(string)` +- `expect.Equals(string)` +- `expect.Match(*regexp.Regexp)` +- `expect.All(comparators ...Comparator)`, which allows you to bundle together a bunch of other comparators The following example shows how to implement your own custom `Comparator` (this is actually the `Equals` comparator). @@ -80,7 +82,9 @@ import ( "gotest.tools/v3/assert" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/expect" ) func MyComparator(compare string) test.Comparator { @@ -119,7 +123,9 @@ import ( "github.com/containerd/errdefs" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/expect" ) func TestMyThing(t *testing.T) { @@ -228,7 +234,9 @@ import ( "github.com/containerd/errdefs" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/expect" ) func TestMyThing(t *testing.T) { @@ -307,7 +315,9 @@ import ( "github.com/containerd/errdefs" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/expect" ) func TestMyThing(t *testing.T) { @@ -375,15 +385,15 @@ expectations. Here are a few: ```go -test.Windows // a test runs only on Windows (or Not(Windows)) -test.Linux // a test runs only on Linux +require.Windows // a test runs only on Windows (or Not(Windows)) +require.Linux // a test runs only on Linux test.Darwin // a test runs only on Darwin test.OS(name string) // a test runs only on the OS `name` -test.Binary(name string) // a test requires the bin `name` to be in the PATH -test.Not(req Requirement) // a test runs only if the opposite of the requirement `req` is fulfilled -test.Require(req ...Requirement) // a test runs only if all requirements are fulfilled +require.Binary(name string) // a test requires the bin `name` to be in the PATH +require.Not(req Requirement) // a test runs only if the opposite of the requirement `req` is fulfilled +require.All(req ...Requirement) // a test runs only if all requirements are fulfilled -nerdtest.Docker // a test only run on Docker - normally used with test.Not(nerdtest.Docker) +nerdtest.Docker // a test only run on Docker - normally used with require.Not(nerdtest.Docker) nerdtest.Soci // a test requires the soci snapshotter nerdtest.Stargz // a test requires the stargz snapshotter nerdtest.Rootless // a test requires Rootless diff --git a/go.mod b/go.mod index 3d9fccf1910..49937439da0 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/containerd/go-cni v1.1.12 github.com/containerd/imgcrypt/v2 v2.0.0 github.com/containerd/log v0.1.0 - github.com/containerd/nerdctl/v2/pkg/testutil/test v0.0.0 + github.com/containerd/nerdctl/mod/tigron v0.0.0 github.com/containerd/nydus-snapshotter v0.15.0 github.com/containerd/platforms v1.0.0-rc.1 github.com/containerd/stargz-snapshotter v0.16.3 @@ -144,4 +144,4 @@ require ( tags.cncf.io/container-device-interface/specs-go v0.8.0 // indirect ) -replace github.com/containerd/nerdctl/v2/pkg/testutil/test v0.0.0 => ./pkg/testutil/test +replace github.com/containerd/nerdctl/mod/tigron v0.0.0 => ./mod/tigron diff --git a/pkg/testutil/test/LICENSE b/mod/tigron/LICENSE similarity index 100% rename from pkg/testutil/test/LICENSE rename to mod/tigron/LICENSE diff --git a/pkg/testutil/test/Makefile b/mod/tigron/Makefile similarity index 99% rename from pkg/testutil/test/Makefile rename to mod/tigron/Makefile index 812eeb42c54..01d87881480 100644 --- a/pkg/testutil/test/Makefile +++ b/mod/tigron/Makefile @@ -34,7 +34,7 @@ ifdef VERBOSE VERBOSE_FLAG_LONG := --verbose endif -ifndef DC_NO_FANCY +ifndef NO_COLORS NC := \033[0m GREEN := \033[1;32m ORANGE := \033[1;33m diff --git a/pkg/testutil/test/README.md b/mod/tigron/README.md similarity index 100% rename from pkg/testutil/test/README.md rename to mod/tigron/README.md diff --git a/pkg/testutil/test/expected.go b/mod/tigron/expect/comparators.go similarity index 52% rename from pkg/testutil/test/expected.go rename to mod/tigron/expect/comparators.go index 9057974c909..dde002db544 100644 --- a/pkg/testutil/test/expected.go +++ b/mod/tigron/expect/comparators.go @@ -14,7 +14,7 @@ limitations under the License. */ -package test +package expect import ( "fmt" @@ -23,65 +23,58 @@ import ( "testing" "gotest.tools/v3/assert" -) -// RunCommand is the simplest way to express a test.TestableCommand for very basic cases when access to test data is not necessary -func Command(args ...string) Executor { - return func(data Data, helpers Helpers) TestableCommand { - return helpers.Command(args...) - } -} - -// Expects is provided as a simple helper covering "expectations" for simple use-cases where access to the test data is not necessary -func Expects(exitCode int, errors []error, output Comparator) Manager { - return func(_ Data, _ Helpers) *Expected { - return &Expected{ - ExitCode: exitCode, - Errors: errors, - Output: output, - } - } -} + "github.com/containerd/nerdctl/mod/tigron/test" +) -// All can be used as a parameter for expected.Output to group a set of comparators -func All(comparators ...Comparator) Comparator { +// All can be used as a parameter for expected.Output to group a set of comparators. +func All(comparators ...test.Comparator) test.Comparator { + //nolint:thelper return func(stdout string, info string, t *testing.T) { t.Helper() + for _, comparator := range comparators { comparator(stdout, info, t) } } } -// Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the output -func Contains(compare string) Comparator { +// Contains can be used as a parameter for expected.Output and ensures a comparison string +// is found contained in the output. +func Contains(compare string) test.Comparator { + //nolint:thelper return func(stdout string, info string, t *testing.T) { t.Helper() - assert.Check(t, strings.Contains(stdout, compare), fmt.Sprintf("Output does not contain: %q", compare)+info) + assert.Check(t, strings.Contains(stdout, compare), + fmt.Sprintf("Output does not contain: %q", compare)+info) } } -// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output -func DoesNotContain(compare string) Comparator { +// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output. +func DoesNotContain(compare string) test.Comparator { + //nolint:thelper return func(stdout string, info string, t *testing.T) { t.Helper() - assert.Check(t, !strings.Contains(stdout, compare), fmt.Sprintf("Output does contain: %q", compare)+info) + assert.Check(t, !strings.Contains(stdout, compare), + fmt.Sprintf("Output does contain: %q", compare)+info) } } -// Equals is to be used for expected.Output to ensure it is exactly the output -func Equals(compare string) Comparator { +// Equals is to be used for expected.Output to ensure it is exactly the output. +func Equals(compare string) test.Comparator { + //nolint:thelper return func(stdout string, info string, t *testing.T) { t.Helper() assert.Equal(t, compare, stdout, info) } } -// Provisional - expected use, but have not seen it so far -// Match is to be used for expected.Output to ensure we match a regexp -func Match(reg *regexp.Regexp) Comparator { +// Match is to be used for expected.Output to ensure we match a regexp. +// Provisional - expected use, but have not seen it so far. +func Match(reg *regexp.Regexp) test.Comparator { + //nolint:thelper return func(stdout string, info string, t *testing.T) { t.Helper() - assert.Check(t, reg.MatchString(stdout), fmt.Sprintf("Output does not match: %s", reg), info) + assert.Check(t, reg.MatchString(stdout), "Output does not match: "+reg.String(), info) } } diff --git a/mod/tigron/expect/comparators_test.go b/mod/tigron/expect/comparators_test.go new file mode 100644 index 00000000000..211ca7ad03e --- /dev/null +++ b/mod/tigron/expect/comparators_test.go @@ -0,0 +1,40 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package expect_test + +import ( + "regexp" + "testing" + + "github.com/containerd/nerdctl/mod/tigron/expect" +) + +func TestExpect(t *testing.T) { + t.Parallel() + + expect.Contains("b")("a b c", "info", t) + expect.DoesNotContain("d")("a b c", "info", t) + expect.Equals("a b c")("a b c", "info", t) + expect.Match(regexp.MustCompile("[a-z ]+"))("a b c", "info", t) + + expect.All( + expect.Contains("b"), + expect.DoesNotContain("d"), + expect.Equals("a b c"), + expect.Match(regexp.MustCompile("[a-z ]+")), + )("a b c", "info", t) +} diff --git a/mod/tigron/expect/consts.go b/mod/tigron/expect/consts.go new file mode 100644 index 00000000000..670e12b4f52 --- /dev/null +++ b/mod/tigron/expect/consts.go @@ -0,0 +1,24 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package expect + +const ( + ExitCodeSuccess = 0 + ExitCodeGenericFail = -1 + ExitCodeNoCheck = -2 + ExitCodeTimeout = -3 +) diff --git a/pkg/testutil/test/go.mod b/mod/tigron/go.mod similarity index 77% rename from pkg/testutil/test/go.mod rename to mod/tigron/go.mod index 85016f344ef..78efedc51b8 100644 --- a/pkg/testutil/test/go.mod +++ b/mod/tigron/go.mod @@ -1,4 +1,4 @@ -module github.com/containerd/nerdctl/v2/pkg/testutil/test +module github.com/containerd/nerdctl/mod/tigron go 1.23 diff --git a/pkg/testutil/test/go.sum b/mod/tigron/go.sum similarity index 100% rename from pkg/testutil/test/go.sum rename to mod/tigron/go.sum diff --git a/pkg/testutil/test/hack/dev-setup-linux.sh b/mod/tigron/hack/dev-setup-linux.sh similarity index 100% rename from pkg/testutil/test/hack/dev-setup-linux.sh rename to mod/tigron/hack/dev-setup-linux.sh diff --git a/pkg/testutil/test/hack/dev-setup-macos.sh b/mod/tigron/hack/dev-setup-macos.sh similarity index 100% rename from pkg/testutil/test/hack/dev-setup-macos.sh rename to mod/tigron/hack/dev-setup-macos.sh diff --git a/pkg/testutil/test/hack/headers/bash.txt b/mod/tigron/hack/headers/bash.txt similarity index 100% rename from pkg/testutil/test/hack/headers/bash.txt rename to mod/tigron/hack/headers/bash.txt diff --git a/pkg/testutil/test/hack/headers/dockerfile.txt b/mod/tigron/hack/headers/dockerfile.txt similarity index 100% rename from pkg/testutil/test/hack/headers/dockerfile.txt rename to mod/tigron/hack/headers/dockerfile.txt diff --git a/pkg/testutil/test/hack/headers/go.txt b/mod/tigron/hack/headers/go.txt similarity index 100% rename from pkg/testutil/test/hack/headers/go.txt rename to mod/tigron/hack/headers/go.txt diff --git a/pkg/testutil/test/hack/headers/makefile.txt b/mod/tigron/hack/headers/makefile.txt similarity index 100% rename from pkg/testutil/test/hack/headers/makefile.txt rename to mod/tigron/hack/headers/makefile.txt diff --git a/pkg/testutil/test/hack/make-lint-licenses.sh b/mod/tigron/hack/make-lint-licenses.sh similarity index 100% rename from pkg/testutil/test/hack/make-lint-licenses.sh rename to mod/tigron/hack/make-lint-licenses.sh diff --git a/pkg/testutil/test/requirement.go b/mod/tigron/require/requirement.go similarity index 68% rename from pkg/testutil/test/requirement.go rename to mod/tigron/require/requirement.go index 9a7abe0ca16..15c1d0bb526 100644 --- a/pkg/testutil/test/requirement.go +++ b/mod/tigron/require/requirement.go @@ -14,17 +14,19 @@ limitations under the License. */ -package test +package require import ( "fmt" "os/exec" "runtime" + + "github.com/containerd/nerdctl/mod/tigron/test" ) -func Binary(name string) *Requirement { - return &Requirement{ - Check: func(data Data, helpers Helpers) (bool, string) { +func Binary(name string) *test.Requirement { + return &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (bool, string) { mess := fmt.Sprintf("executable %q has been found in PATH", name) ret := true if _, err := exec.LookPath(name); err != nil { @@ -37,9 +39,9 @@ func Binary(name string) *Requirement { } } -func OS(os string) *Requirement { - return &Requirement{ - Check: func(data Data, helpers Helpers) (bool, string) { +func OS(os string) *test.Requirement { + return &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (bool, string) { mess := fmt.Sprintf("current operating system is %q", runtime.GOOS) ret := true if runtime.GOOS != os { @@ -51,9 +53,9 @@ func OS(os string) *Requirement { } } -func Arch(arch string) *Requirement { - return &Requirement{ - Check: func(data Data, helpers Helpers) (bool, string) { +func Arch(arch string) *test.Requirement { + return &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (bool, string) { mess := fmt.Sprintf("current architecture is %q", runtime.GOARCH) ret := true if runtime.GOARCH != arch { @@ -73,18 +75,18 @@ var Darwin = OS("darwin") // NOTE: Not will always lose setups and cleanups... -func Not(requirement *Requirement) *Requirement { - return &Requirement{ - Check: func(data Data, helpers Helpers) (bool, string) { +func Not(requirement *test.Requirement) *test.Requirement { + return &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (bool, string) { ret, mess := requirement.Check(data, helpers) return !ret, mess }, } } -func Require(requirements ...*Requirement) *Requirement { - return &Requirement{ - Check: func(data Data, helpers Helpers) (bool, string) { +func All(requirements ...*test.Requirement) *test.Requirement { + return &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (bool, string) { ret := true mess := "" var subMess string @@ -97,14 +99,14 @@ func Require(requirements ...*Requirement) *Requirement { } return ret, mess }, - Setup: func(data Data, helpers Helpers) { + Setup: func(data test.Data, helpers test.Helpers) { for _, requirement := range requirements { if requirement.Setup != nil { requirement.Setup(data, helpers) } } }, - Cleanup: func(data Data, helpers Helpers) { + Cleanup: func(data test.Data, helpers test.Helpers) { for _, requirement := range requirements { if requirement.Cleanup != nil { requirement.Cleanup(data, helpers) diff --git a/pkg/testutil/test/case.go b/mod/tigron/test/case.go similarity index 99% rename from pkg/testutil/test/case.go rename to mod/tigron/test/case.go index 58f9f573757..46c02f2f4f6 100644 --- a/pkg/testutil/test/case.go +++ b/mod/tigron/test/case.go @@ -23,7 +23,7 @@ import ( "gotest.tools/v3/assert" ) -// Case describes an entire test-case, including data, setup and cleanup routines, command and expectations +// Case describes an entire test-case, including data, setup and cleanup routines, command and expectations. type Case struct { // Description contains a human-readable short desc, used as a seed for the identifier and as a title for the test Description string diff --git a/pkg/testutil/test/command.go b/mod/tigron/test/command.go similarity index 79% rename from pkg/testutil/test/command.go rename to mod/tigron/test/command.go index 6e81de74dad..764de70f9c6 100644 --- a/pkg/testutil/test/command.go +++ b/mod/tigron/test/command.go @@ -30,12 +30,40 @@ import ( "gotest.tools/v3/assert" "gotest.tools/v3/icmd" - "github.com/containerd/nerdctl/v2/pkg/testutil/test/internal/pty" + "github.com/containerd/nerdctl/mod/tigron/test/internal" + "github.com/containerd/nerdctl/mod/tigron/test/internal/pty" ) -const ExitCodeGenericFail = -1 -const ExitCodeNoCheck = -2 -const ExitCodeTimeout = -3 +// CustomizableCommand is an interface meant for people who want to heavily customize the base command +// of their test case. +type CustomizableCommand interface { + TestableCommand + + PrependArgs(args ...string) + // WithBlacklist allows to filter out unwanted variables from the embedding environment - + // default it pass any that is defined by WithEnv + WithBlacklist(env []string) + + // withEnv *copies* the passed map to the environment of the command to be executed + // Note that this will override any variable defined in the embedding environment + withEnv(env map[string]string) + // withTempDir specifies a temporary directory to use + withTempDir(path string) + // WithConfig allows passing custom config properties from the test to the base command + withConfig(config Config) + withT(t *testing.T) + // Clear does a clone, but will clear binary and arguments, but retain the env, or any other custom properties + // Gotcha: if GenericCommand is embedded with a custom Run and an overridden clear to return the embedding type + // the result will be the embedding command, no longer the GenericCommand + clear() TestableCommand + + // Will manipulate specific configuration option on the command + // Note that config is a copy of the test config + // Any modification done here will not be passed along to subtests, although they are shared + // amongst all commands of the test. + write(key ConfigKey, value ConfigValue) + read(key ConfigKey) ConfigValue +} // GenericCommand is a concrete Command implementation type GenericCommand struct { @@ -148,14 +176,14 @@ func (gc *GenericCommand) Run(expect *Expected) { // Build the debug string - additionally attach the env (which iCmd does not do) debug := result.String() + "Env:\n" + strings.Join(env, "\n") // ExitCode goes first - if expect.ExitCode == ExitCodeNoCheck { //nolint:revive + if expect.ExitCode == internal.ExitCodeNoCheck { //nolint:revive // ExitCodeNoCheck means we do not care at all about exit code. It can be a failure, a success, or a timeout. - } else if expect.ExitCode == ExitCodeGenericFail { + } else if expect.ExitCode == internal.ExitCodeGenericFail { // ExitCodeGenericFail means we expect an error (excluding timeout). assert.Assert(gc.t, result.ExitCode != 0, "Command succeeded while we were expecting an error\n"+debug) } else if result.Timeout { - assert.Assert(gc.t, expect.ExitCode == ExitCodeTimeout, + assert.Assert(gc.t, expect.ExitCode == internal.ExitCodeTimeout, "Command unexpectedly timed-out\n"+debug) } else { assert.Assert(gc.t, expect.ExitCode == result.ExitCode, diff --git a/pkg/testutil/test/config.go b/mod/tigron/test/config.go similarity index 100% rename from pkg/testutil/test/config.go rename to mod/tigron/test/config.go diff --git a/pkg/testutil/test/data.go b/mod/tigron/test/data.go similarity index 100% rename from pkg/testutil/test/data.go rename to mod/tigron/test/data.go diff --git a/mod/tigron/test/expected.go b/mod/tigron/test/expected.go new file mode 100644 index 00000000000..3ef181a7009 --- /dev/null +++ b/mod/tigron/test/expected.go @@ -0,0 +1,35 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package test + +// RunCommand is the simplest way to express a test.TestableCommand for very basic cases when access to test data is not necessary +func Command(args ...string) Executor { + return func(data Data, helpers Helpers) TestableCommand { + return helpers.Command(args...) + } +} + +// Expects is provided as a simple helper covering "expectations" for simple use-cases where access to the test data is not necessary +func Expects(exitCode int, errors []error, output Comparator) Manager { + return func(_ Data, _ Helpers) *Expected { + return &Expected{ + ExitCode: exitCode, + Errors: errors, + Output: output, + } + } +} diff --git a/mod/tigron/test/funct.go b/mod/tigron/test/funct.go new file mode 100644 index 00000000000..cc6f80c04cd --- /dev/null +++ b/mod/tigron/test/funct.go @@ -0,0 +1,34 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package test + +import "testing" + +// An Evaluator is a function that decides whether a test should run or not. +type Evaluator func(data Data, helpers Helpers) (bool, string) + +// A Butler is the function signature meant to be attached to a Setup or Cleanup routine for a Case or Requirement. +type Butler func(data Data, helpers Helpers) + +// A Comparator is the function signature to implement for the Output property of an Expected. +type Comparator func(stdout string, info string, t *testing.T) + +// A Manager is the function signature meant to produce expectations for a command. +type Manager func(data Data, helpers Helpers) *Expected + +// An Executor is the function signature meant to be attached to the Command property of a Case. +type Executor func(data Data, helpers Helpers) TestableCommand diff --git a/pkg/testutil/test/helpers.go b/mod/tigron/test/helpers.go similarity index 64% rename from pkg/testutil/test/helpers.go rename to mod/tigron/test/helpers.go index 9247f4098e8..d09443b3f0b 100644 --- a/pkg/testutil/test/helpers.go +++ b/mod/tigron/test/helpers.go @@ -16,36 +16,11 @@ package test -import "testing" - -// Helpers provides a set of helpers to run commands with simple expectations, available at all stages of a test (Setup, Cleanup, etc...) -type Helpers interface { - // Ensure runs a command and verifies it is succeeding - Ensure(args ...string) - // Anyhow runs a command and ignores its result - Anyhow(args ...string) - // Fail runs a command and verifies it failed - Fail(args ...string) - // Capture runs a command, verifies it succeeded, and returns stdout - Capture(args ...string) string - // Err runs a command, and returns stderr regardless of its outcome - // This is mostly useful for debugging - Err(args ...string) string - - // Command will return a populated command from the default internal command, with the provided arguments, - // ready to be Run or further configured - Command(args ...string) TestableCommand - // Custom will return a bare command, without configuration nor defaults (still has the Env) - Custom(binary string, args ...string) TestableCommand - - // Read return the config value associated with a key - Read(key ConfigKey) ConfigValue - // Write saves a value in the config - Write(key ConfigKey, value ConfigValue) - - // T returns the current testing object - T() *testing.T -} +import ( + "testing" + + "github.com/containerd/nerdctl/mod/tigron/test/internal" +) // This is the implementation of Helpers @@ -70,7 +45,7 @@ func (help *helpersInternal) Anyhow(args ...string) { // Fail will run a command and make sure it does fail func (help *helpersInternal) Fail(args ...string) { help.Command(args...).Run(&Expected{ - ExitCode: ExitCodeGenericFail, + ExitCode: internal.ExitCodeGenericFail, }) } @@ -85,7 +60,7 @@ func (help *helpersInternal) Capture(args ...string) string { return ret } -// Capture will run a command, ensure it is successful and return stdout +// Err will run a command, ensure it is successful and return stdout func (help *helpersInternal) Err(args ...string) string { cmd := help.Command(args...) cmd.Run(nil) diff --git a/mod/tigron/test/interfaces.go b/mod/tigron/test/interfaces.go new file mode 100644 index 00000000000..d83b3117887 --- /dev/null +++ b/mod/tigron/test/interfaces.go @@ -0,0 +1,109 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package test + +import ( + "io" + "os" + "testing" + "time" +) + +// Data is meant to hold information about a test: +// - first, any random key value data that the test implementer wants to carry / modify - this is test data +// - second, some commonly useful immutable test properties (a way to generate unique identifiers for that test, +// temporary directory, etc.) +// Note that Data is inherited, from parent test to subtest (except for Identifier and TempDir of course). +type Data interface { + // Get returns the value of a certain key for custom data + Get(key string) string + // Set will save `value` for `key` + Set(key string, value string) Data + + // Identifier returns the test identifier that can be used to name resources + Identifier(suffix ...string) string + // TempDir returns the test temporary directory + TempDir() string +} + +// Helpers provides a set of helpers to run commands with simple expectations, +// available at all stages of a test (Setup, Cleanup, etc...) +type Helpers interface { + // Ensure runs a command and verifies it is succeeding + Ensure(args ...string) + // Anyhow runs a command and ignores its result + Anyhow(args ...string) + // Fail runs a command and verifies it failed + Fail(args ...string) + // Capture runs a command, verifies it succeeded, and returns stdout + Capture(args ...string) string + // Err runs a command, and returns stderr regardless of its outcome + // This is mostly useful for debugging + Err(args ...string) string + + // Command will return a populated command from the default internal command, with the provided arguments, + // ready to be Run or further configured + Command(args ...string) TestableCommand + // Custom will return a bare command, without configuration nor defaults (still has the Env) + Custom(binary string, args ...string) TestableCommand + + // Read return the config value associated with a key + Read(key ConfigKey) ConfigValue + // Write saves a value in the config + Write(key ConfigKey, value ConfigValue) + + // T returns the current testing object + T() *testing.T +} + +// The TestableCommand interface represents a low-level command to execute, typically to be compared with an Expected +// A TestableCommand can be used as a Case Command obviously, but also as part of a Setup or Cleanup routine, +// and as the basis of any type of helper. +// For more powerful use-cases outside of test cases, see below CustomizableCommand. +type TestableCommand interface { + // WithBinary specifies what binary to execute + WithBinary(binary string) + // WithArgs specifies the args to pass to the binary. Note that WithArgs can be used multiple times and is additive. + WithArgs(args ...string) + // WithWrapper allows wrapping a command with another command (for example: `time`) + WithWrapper(binary string, args ...string) + WithPseudoTTY(writers ...func(*os.File) error) + // WithStdin allows passing a reader to be used for stdin for the command + WithStdin(r io.Reader) + // WithCwd allows specifying the working directory for the command + WithCwd(path string) + // Clone returns a copy of the command + Clone() TestableCommand + + // Run does execute the command, and compare the output with the provided expectation. + // Passing nil for `Expected` will just run the command regardless of outcome. + // An empty `&Expected{}` is (of course) equivalent to &Expected{Exit: 0}, meaning the command is + // verified to be successful + Run(expect *Expected) + // Background allows starting a command in the background + Background(timeout time.Duration) + // Signal sends a signal to a backgrounded command + Signal(sig os.Signal) error + // Stderr allows retrieving the raw stderr output of the command once it has been run + Stderr() string +} + +// Config is meant to hold information relevant to the binary (eg: flags defining certain behaviors, etc.) +type Config interface { + Write(key ConfigKey, value ConfigValue) Config + Read(key ConfigKey) ConfigValue +} diff --git a/mod/tigron/test/internal/consts.go b/mod/tigron/test/internal/consts.go new file mode 100644 index 00000000000..dd058dcf7bf --- /dev/null +++ b/mod/tigron/test/internal/consts.go @@ -0,0 +1,25 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package internal + +// This is duplicated form `expect` to avoid circular imports. +const ( + ExitCodeSuccess = 0 + ExitCodeGenericFail = -1 + ExitCodeNoCheck = -2 + ExitCodeTimeout = -3 +) diff --git a/pkg/testutil/test/internal/pty/pty.go b/mod/tigron/test/internal/pty/pty.go similarity index 100% rename from pkg/testutil/test/internal/pty/pty.go rename to mod/tigron/test/internal/pty/pty.go diff --git a/pkg/testutil/test/internal/pty/pty_darwin.go b/mod/tigron/test/internal/pty/pty_darwin.go similarity index 100% rename from pkg/testutil/test/internal/pty/pty_darwin.go rename to mod/tigron/test/internal/pty/pty_darwin.go diff --git a/pkg/testutil/test/internal/pty/pty_freebsd.go b/mod/tigron/test/internal/pty/pty_freebsd.go similarity index 100% rename from pkg/testutil/test/internal/pty/pty_freebsd.go rename to mod/tigron/test/internal/pty/pty_freebsd.go diff --git a/pkg/testutil/test/internal/pty/pty_linux.go b/mod/tigron/test/internal/pty/pty_linux.go similarity index 100% rename from pkg/testutil/test/internal/pty/pty_linux.go rename to mod/tigron/test/internal/pty/pty_linux.go diff --git a/pkg/testutil/test/internal/pty/pty_windows.go b/mod/tigron/test/internal/pty/pty_windows.go similarity index 100% rename from pkg/testutil/test/internal/pty/pty_windows.go rename to mod/tigron/test/internal/pty/pty_windows.go diff --git a/mod/tigron/test/test.go b/mod/tigron/test/test.go new file mode 100644 index 00000000000..d1d2490e05a --- /dev/null +++ b/mod/tigron/test/test.go @@ -0,0 +1,34 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package test + +import ( + "testing" +) + +type Testable interface { + CustomCommand(testCase *Case, t *testing.T) CustomizableCommand + AmbientRequirements(testCase *Case, t *testing.T) +} + +var ( + registeredTestable Testable +) + +func Customize(testable Testable) { + registeredTestable = testable +} diff --git a/mod/tigron/test/types.go b/mod/tigron/test/types.go new file mode 100644 index 00000000000..7544d808814 --- /dev/null +++ b/mod/tigron/test/types.go @@ -0,0 +1,45 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package test + +type ( + ConfigKey string + ConfigValue string +) + +// A Requirement offers a way to verify random conditions to decide if a test should be skipped or run. +// It can also (optionally) provide custom Setup and Cleanup routines. +type Requirement struct { + // Check is expected to verify if the requirement is fulfilled, and return a boolean and an explanatory message + Check Evaluator + // Setup, if provided, will be run before any test-specific Setup routine, in the order that requirements + // have been declared + Setup Butler + // Cleanup, if provided, will be run after any test-specific Cleanup routine, in the reverse order that + // requirements have been declared + Cleanup Butler +} + +// Expected expresses the expected output of a command. +type Expected struct { + // ExitCode + ExitCode int + // Errors contains any error that (once serialized) should be seen in stderr + Errors []error + // Output function to match against stdout + Output Comparator +} diff --git a/pkg/testutil/test/utilities.go b/mod/tigron/utils/utilities.go similarity index 98% rename from pkg/testutil/test/utilities.go rename to mod/tigron/utils/utilities.go index 26da36bdbaa..ea8fa458bc1 100644 --- a/pkg/testutil/test/utilities.go +++ b/mod/tigron/utils/utilities.go @@ -14,7 +14,7 @@ limitations under the License. */ -package test +package utils import ( "crypto/rand" diff --git a/pkg/testutil/nerdtest/ca/ca.go b/pkg/testutil/nerdtest/ca/ca.go index da367d464e1..08615f7058b 100644 --- a/pkg/testutil/nerdtest/ca/ca.go +++ b/pkg/testutil/nerdtest/ca/ca.go @@ -32,7 +32,7 @@ import ( "gotest.tools/v3/assert" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" ) type CA struct { diff --git a/pkg/testutil/nerdtest/command.go b/pkg/testutil/nerdtest/command.go index 99fb0e3b0f5..2675d07a78c 100644 --- a/pkg/testutil/nerdtest/command.go +++ b/pkg/testutil/nerdtest/command.go @@ -25,10 +25,11 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/rootlessutil" "github.com/containerd/nerdctl/v2/pkg/testutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/platform" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) const defaultNamespace = testutil.Namespace diff --git a/pkg/testutil/nerdtest/registry/cesanta.go b/pkg/testutil/nerdtest/registry/cesanta.go index cf074542c35..58bc361f212 100644 --- a/pkg/testutil/nerdtest/registry/cesanta.go +++ b/pkg/testutil/nerdtest/registry/cesanta.go @@ -29,12 +29,14 @@ import ( "gopkg.in/yaml.v3" "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/ca" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/platform" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" "github.com/containerd/nerdctl/v2/pkg/testutil/portlock" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) type CesantaConfigServer struct { @@ -92,7 +94,7 @@ func ensureContainerStarted(helpers test.Helpers, con string) { for i := 0; i < 5 && !started; i++ { helpers.Command("container", "inspect", con). Run(&test.Expected{ - ExitCode: test.ExitCodeNoCheck, + ExitCode: expect.ExitCodeNoCheck, Output: func(stdout string, info string, t *testing.T) { var dc []dockercompat.Container err := json.Unmarshal([]byte(stdout), &dc) diff --git a/pkg/testutil/nerdtest/registry/common.go b/pkg/testutil/nerdtest/registry/common.go index 0f7496b049a..d662d00f7c0 100644 --- a/pkg/testutil/nerdtest/registry/common.go +++ b/pkg/testutil/nerdtest/registry/common.go @@ -24,7 +24,7 @@ import ( "golang.org/x/crypto/bcrypt" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" ) // Auth describes a struct able to serialize authenticator information into arguments to be fed to a registry container run diff --git a/pkg/testutil/nerdtest/registry/docker.go b/pkg/testutil/nerdtest/registry/docker.go index 9248dc56652..30ee7626b53 100644 --- a/pkg/testutil/nerdtest/registry/docker.go +++ b/pkg/testutil/nerdtest/registry/docker.go @@ -24,12 +24,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/ca" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/hoststoml" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/platform" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" "github.com/containerd/nerdctl/v2/pkg/testutil/portlock" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func NewDockerRegistry(data test.Data, helpers test.Helpers, currentCA *ca.CA, port int, auth Auth) *Server { diff --git a/pkg/testutil/nerdtest/registry/kubo.go b/pkg/testutil/nerdtest/registry/kubo.go index 8cb350a65b0..1a9a3ca2db8 100644 --- a/pkg/testutil/nerdtest/registry/kubo.go +++ b/pkg/testutil/nerdtest/registry/kubo.go @@ -24,11 +24,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/ca" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/platform" "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil" "github.com/containerd/nerdctl/v2/pkg/testutil/portlock" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func NewKuboRegistry(data test.Data, helpers test.Helpers, t *testing.T, currentCA *ca.CA, port int, auth Auth) *Server { diff --git a/pkg/testutil/nerdtest/requirements.go b/pkg/testutil/nerdtest/requirements.go index a5d89481203..88acba1802d 100644 --- a/pkg/testutil/nerdtest/requirements.go +++ b/pkg/testutil/nerdtest/requirements.go @@ -25,11 +25,13 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/require" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/buildkitutil" "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/rootlessutil" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/platform" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) var BuildkitHost test.ConfigKey = "BuildkitHost" @@ -94,7 +96,7 @@ var IsFlaky = func(issueLink string) *test.Requirement { } // Docker marks a test as suitable solely for Docker and not Nerdctl -// Generally used as test.Not(nerdtest.Docker), which of course it the opposite +// Generally used as require.Not(nerdtest.Docker), which of course it the opposite var Docker = &test.Requirement{ Check: func(data test.Data, helpers test.Helpers) (ret bool, mess string) { ret = getTarget() == targetDocker @@ -151,7 +153,7 @@ var Rootless = &test.Requirement{ } // Rootful marks a test as suitable only for rootful env -var Rootful = test.Not(Rootless) +var Rootful = require.Not(Rootless) // CGroup requires that cgroup is enabled var CGroup = &test.Requirement{ @@ -171,7 +173,7 @@ var CGroup = &test.Requirement{ }, } -var CgroupsAccessible = test.Require( +var CgroupsAccessible = require.All( CGroup, &test.Requirement{ Check: func(data test.Data, helpers test.Helpers) (ret bool, mess string) { @@ -229,9 +231,9 @@ var Stargz = &test.Requirement{ } // Registry marks a test as requiring a registry to be deployed -var Registry = test.Require( +var Registry = require.All( // Registry requires Linux currently - test.Linux, + require.Linux, (func() *test.Requirement { // Provisional: see note in cleanup // var reg *registry.Server @@ -307,7 +309,7 @@ var IPFS = &test.Requirement{ // FIXME: we should be able to access the env (at least through helpers.Command().) instead of this gym helpers.Write(ipfs, enabled) // FIXME: this is incomplete. We obviously need a daemon running, properly configured - return test.Binary("ipfs").Check(data, helpers) + return require.Binary("ipfs").Check(data, helpers) }, } diff --git a/pkg/testutil/nerdtest/requirements_other.go b/pkg/testutil/nerdtest/requirements_other.go index 74e280670c7..bc2e02927d0 100644 --- a/pkg/testutil/nerdtest/requirements_other.go +++ b/pkg/testutil/nerdtest/requirements_other.go @@ -19,7 +19,7 @@ package nerdtest import ( - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" ) var HyperV = &test.Requirement{ diff --git a/pkg/testutil/nerdtest/requirements_windows.go b/pkg/testutil/nerdtest/requirements_windows.go index a1155a970db..7cf9b6e8c25 100644 --- a/pkg/testutil/nerdtest/requirements_windows.go +++ b/pkg/testutil/nerdtest/requirements_windows.go @@ -17,8 +17,9 @@ package nerdtest import ( + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) var HyperV = &test.Requirement{ diff --git a/pkg/testutil/nerdtest/test.go b/pkg/testutil/nerdtest/test.go index 7bfd485cdf2..9aa623c76d1 100644 --- a/pkg/testutil/nerdtest/test.go +++ b/pkg/testutil/nerdtest/test.go @@ -19,7 +19,7 @@ package nerdtest import ( "testing" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" + "github.com/containerd/nerdctl/mod/tigron/test" ) var DockerConfig test.ConfigKey = "DockerConfig" diff --git a/pkg/testutil/nerdtest/third-party.go b/pkg/testutil/nerdtest/third-party.go index 087ed50ed78..0a0906599e9 100644 --- a/pkg/testutil/nerdtest/third-party.go +++ b/pkg/testutil/nerdtest/third-party.go @@ -21,9 +21,10 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/ca" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) func BuildCtlCommand(helpers test.Helpers, args ...string) test.TestableCommand { diff --git a/pkg/testutil/nerdtest/utilities.go b/pkg/testutil/nerdtest/utilities.go index 18f34a8af7c..b15e5e535a8 100644 --- a/pkg/testutil/nerdtest/utilities.go +++ b/pkg/testutil/nerdtest/utilities.go @@ -23,10 +23,12 @@ import ( "gotest.tools/v3/assert" + "github.com/containerd/nerdctl/mod/tigron/expect" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" "github.com/containerd/nerdctl/v2/pkg/inspecttypes/native" "github.com/containerd/nerdctl/v2/pkg/testutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) const ( @@ -104,7 +106,7 @@ func EnsureContainerStarted(helpers test.Helpers, con string) { for i := 0; i < maxRetry && !started; i++ { helpers.Command("container", "inspect", con). Run(&test.Expected{ - ExitCode: test.ExitCodeNoCheck, + ExitCode: expect.ExitCodeNoCheck, Output: func(stdout string, info string, t *testing.T) { var dc []dockercompat.Container err := json.Unmarshal([]byte(stdout), &dc) diff --git a/pkg/testutil/nerdtest/utilities_linux.go b/pkg/testutil/nerdtest/utilities_linux.go index 08df2087268..2a12bfd1aec 100644 --- a/pkg/testutil/nerdtest/utilities_linux.go +++ b/pkg/testutil/nerdtest/utilities_linux.go @@ -23,8 +23,9 @@ import ( "syscall" "time" + "github.com/containerd/nerdctl/mod/tigron/test" + "github.com/containerd/nerdctl/v2/pkg/testutil" - "github.com/containerd/nerdctl/v2/pkg/testutil/test" ) const SignalCaught = "received" diff --git a/pkg/testutil/test/test.go b/pkg/testutil/test/test.go deleted file mode 100644 index 5d4202e33d3..00000000000 --- a/pkg/testutil/test/test.go +++ /dev/null @@ -1,165 +0,0 @@ -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package test - -import ( - "io" - "os" - "testing" - "time" -) - -// A Requirement offers a way to verify random conditions to decide if a test should be skipped or run. -// It can furthermore (optionally) provide custom Setup and Cleanup routines. -type Requirement struct { - // Check is expected to perform random operations and return a boolean and an explanatory message - Check Evaluator - // Setup, if provided, will be run before any test-specific Setup routine, in the order that requirements have been declared - Setup Butler - // Cleanup, if provided, will be run after any test-specific Cleanup routine, in the revers order that requirements have been declared - Cleanup Butler -} - -// An Evaluator is a function that decides whether a test should run or not -type Evaluator func(data Data, helpers Helpers) (bool, string) - -// A Butler is the function signature meant to be attached to a Setup or Cleanup routine for a Case or Requirement -type Butler func(data Data, helpers Helpers) - -// An Executor is the function signature meant to be attached to the Command property of a Case -type Executor func(data Data, helpers Helpers) TestableCommand - -// A Manager is the function signature to be run to produce expectations to be fed to a command -type Manager func(data Data, helpers Helpers) *Expected - -// A Comparator is the function signature to implement for the Output property of an Expected -type Comparator func(stdout string, info string, t *testing.T) - -// Expected expresses the expected output of a command -type Expected struct { - // ExitCode - ExitCode int - // Errors contains any error that (once serialized) should be seen in stderr - Errors []error - // Output function to match against stdout - Output Comparator -} - -// Data is meant to hold information about a test: -// - first, any random key value data that the test implementer wants to carry / modify - this is test data -// - second, some commonly useful immutable test properties (a way to generate unique identifiers for that test, -// temporary directory, etc.) -// Note that Data is inherited, from parent test to subtest (except for Identifier and TempDir of course) -type Data interface { - // Get returns the value of a certain key for custom data - Get(key string) string - // Set will save `value` for `key` - Set(key string, value string) Data - - // Identifier returns the test identifier that can be used to name resources - Identifier(suffix ...string) string - // TempDir returns the test temporary directory - TempDir() string -} - -type ConfigKey string -type ConfigValue string - -// Config is meant to hold information relevant to the binary (eg: flags defining certain behaviors, etc.) -type Config interface { - // Write - Write(key ConfigKey, value ConfigValue) Config - // Read - Read(key ConfigKey) ConfigValue -} - -// The TestableCommand interface represents a low-level command to execute, typically to be compared with an Expected -// A TestableCommand can be used as a Case Command obviously, but also as part of a Setup or Cleanup routine, -// and as the basis of any type of helper. -// For more powerful usecase outside of test cases, see below CustomizableCommand -type TestableCommand interface { - // WithBinary specifies what binary to execute - WithBinary(binary string) - // WithArgs specifies the args to pass to the binary. Note that WithArgs can be used multiple times and is additive. - WithArgs(args ...string) - // WithWrapper allows wrapping a command with another command (for example: `time`, `unbuffer`) - WithWrapper(binary string, args ...string) - // WithPseudoTTY - WithPseudoTTY(writers ...func(*os.File) error) - // WithStdin allows passing a reader to be used for stdin for the command - WithStdin(r io.Reader) - // WithCwd allows specifying the working directory for the command - WithCwd(path string) - // Clone returns a copy of the command - Clone() TestableCommand - - // Run does execute the command, and compare the output with the provided expectation. - // Passing nil for `Expected` will just run the command regardless of outcome. - // An empty `&Expected{}` is (of course) equivalent to &Expected{Exit: 0}, meaning the command is verified to be - // successful - Run(expect *Expected) - // Background allows starting a command in the background - Background(timeout time.Duration) - // Signal sends a signal to a backgrounded command - Signal(sig os.Signal) error - // Stderr allows retrieving the raw stderr output of the command - Stderr() string -} - -// ///////////////////////////////////////////// -// CustomizableCommand is an interface meant for people who want to heavily customize the base command of their test case -// It is passed along -type CustomizableCommand interface { - TestableCommand - - PrependArgs(args ...string) - // WithBlacklist allows to filter out unwanted variables from the embedding environment - default it pass any that is - // defined by WithEnv - WithBlacklist(env []string) - - // withEnv *copies* the passed map to the environment of the command to be executed - // Note that this will override any variable defined in the embedding environment - withEnv(env map[string]string) - // withTempDir specifies a temporary directory to use - withTempDir(path string) - // WithConfig allows passing custom config properties from the test to the base command - withConfig(config Config) - withT(t *testing.T) - // Clear does a clone, but will clear binary and arguments, but retain the env, or any other custom properties - // Gotcha: if GenericCommand is embedded with a custom Run and an overridden clear to return the embedding type - // the result will be the embedding command, no longer the GenericCommand - clear() TestableCommand - - // Will manipulate specific configuration option on the command - // Note that config is a copy of the test config - // Any modification done here will not be passed along to subtests, although they are shared amongst all commands of the test. - write(key ConfigKey, value ConfigValue) - read(key ConfigKey) ConfigValue -} - -type Testable interface { - CustomCommand(testCase *Case, t *testing.T) CustomizableCommand - AmbientRequirements(testCase *Case, t *testing.T) -} - -var ( - registeredTestable Testable -) - -func Customize(testable Testable) { - registeredTestable = testable -}