From 4d86ebea420f6f3c069a3a406a1ba9dabf41fc9c Mon Sep 17 00:00:00 2001 From: apostasie Date: Sun, 3 Nov 2024 00:11:17 +0100 Subject: [PATCH] Testing windows with updated busybox image Signed-off-by: apostasie --- .../container_run_user_windows_test.go | 40 +++++++--- cmd/nerdctl/container/container_top_test.go | 2 +- cmd/nerdctl/image/image_pull_linux_test.go | 44 ----------- cmd/nerdctl/image/image_pull_test.go | 74 +++++++++++++++++++ cmd/nerdctl/issues/issues_main_test.go | 27 +++++++ .../{issues_linux_test.go => issues_test.go} | 10 ++- cmd/nerdctl/issues/main_linux_test.go | 58 --------------- .../nerdtest/platform/platform_windows.go | 16 ++-- pkg/testutil/nerdtest/requirements.go | 2 +- pkg/testutil/testutil_windows.go | 2 +- 10 files changed, 146 insertions(+), 129 deletions(-) create mode 100644 cmd/nerdctl/image/image_pull_test.go create mode 100644 cmd/nerdctl/issues/issues_main_test.go rename cmd/nerdctl/issues/{issues_linux_test.go => issues_test.go} (94%) delete mode 100644 cmd/nerdctl/issues/main_linux_test.go diff --git a/cmd/nerdctl/container/container_run_user_windows_test.go b/cmd/nerdctl/container/container_run_user_windows_test.go index e92dc595598..ba2b74b5817 100644 --- a/cmd/nerdctl/container/container_run_user_windows_test.go +++ b/cmd/nerdctl/container/container_run_user_windows_test.go @@ -24,22 +24,40 @@ import ( func TestRunUserName(t *testing.T) { base := testutil.NewBase(t) - testCases := map[string]string{ - "": "ContainerAdministrator", - "ContainerAdministrator": "ContainerAdministrator", - "ContainerUser": "ContainerUser", + testCases := []struct { + explicitUser string + whoami string + env string + }{ + { + explicitUser: "", + whoami: "ContainerUser", + env: "ContainerUser", + }, + { + explicitUser: "ContainerUser", + whoami: "ContainerUser", + env: "ContainerUser", + }, + { + explicitUser: "ContainerAdministrator", + whoami: "root", + env: "ContainerAdministrator", + }, } - for userStr, expected := range testCases { - userStr := userStr - expected := expected - t.Run(userStr, func(t *testing.T) { + + for _, user := range testCases { + t.Run(user.explicitUser, func(t *testing.T) { t.Parallel() cmd := []string{"run", "--rm"} - if userStr != "" { - cmd = append(cmd, "--user", userStr) + if user.explicitUser != "" { + cmd = append(cmd, "--user", user.explicitUser) } cmd = append(cmd, testutil.WindowsNano, "whoami") - base.Cmd(cmd...).AssertOutContains(expected) + base.Cmd(cmd...).AssertOutContains(user.whoami) + + cmd = append(cmd, testutil.WindowsNano, "echo $USERNAME") + base.Cmd(cmd...).AssertOutContains(user.whoami) }) } } diff --git a/cmd/nerdctl/container/container_top_test.go b/cmd/nerdctl/container/container_top_test.go index 8042b32a8b4..2c776892c5e 100644 --- a/cmd/nerdctl/container/container_top_test.go +++ b/cmd/nerdctl/container/container_top_test.go @@ -46,7 +46,7 @@ func TestTop(t *testing.T) { testCase.SubTests = []*test.Case{ { Description: "with o pid,user,cmd", - // Docker does not support top -o + // Docker does not support top -o. Require: test.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/image/image_pull_linux_test.go b/cmd/nerdctl/image/image_pull_linux_test.go index 611c834b2ed..851a49f7dd8 100644 --- a/cmd/nerdctl/image/image_pull_linux_test.go +++ b/cmd/nerdctl/image/image_pull_linux_test.go @@ -100,50 +100,6 @@ CMD ["echo", "nerdctl-build-test-string"] testCase.Run(t) } -func TestImagePullPlainHttpWithDefaultPort(t *testing.T) { - nerdtest.Setup() - - var registry *testregistry.RegistryServer - - testCase := &test.Case{ - Require: test.Require( - test.Linux, - test.Not(nerdtest.Docker), - nerdtest.Build, - ), - Setup: func(data test.Data, helpers test.Helpers) { - base := testutil.NewBase(t) - registry = testregistry.NewWithNoAuth(base, 80, false) - testImageRef := fmt.Sprintf("%s/%s:%s", - registry.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) - dockerfile := fmt.Sprintf(`FROM %s -CMD ["echo", "nerdctl-build-test-string"] - `, testutil.CommonImage) - - buildCtx := testhelpers.CreateBuildContext(t, dockerfile) - helpers.Ensure("build", "-t", testImageRef, buildCtx) - helpers.Ensure("--insecure-registry", "push", testImageRef) - helpers.Ensure("rmi", "-f", testImageRef) - }, - Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { - testImageRef := fmt.Sprintf("%s/%s:%s", - registry.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) - return helpers.Command("--insecure-registry", "pull", testImageRef) - }, - Expected: test.Expects(0, nil, nil), - Cleanup: func(data test.Data, helpers test.Helpers) { - if registry != nil { - registry.Cleanup(nil) - testImageRef := fmt.Sprintf("%s/%s:%s", - registry.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) - helpers.Anyhow("rmi", "-f", testImageRef) - } - }, - } - - testCase.Run(t) -} - func TestImagePullSoci(t *testing.T) { nerdtest.Setup() diff --git a/cmd/nerdctl/image/image_pull_test.go b/cmd/nerdctl/image/image_pull_test.go new file mode 100644 index 00000000000..657162110a5 --- /dev/null +++ b/cmd/nerdctl/image/image_pull_test.go @@ -0,0 +1,74 @@ +/* + 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 image + +import ( + "fmt" + "strings" + "testing" + + 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/nerdtest/registry" + "github.com/containerd/nerdctl/v2/pkg/testutil/test" +) + +func TestImagePullPlainHttpWithDefaultPort(t *testing.T) { + nerdtest.Setup() + + var reg *registry.Server + + testCase := &test.Case{ + Require: test.Require( + nerdtest.Registry, + test.Not(nerdtest.Docker), + nerdtest.Build, + ), + Setup: func(data test.Data, helpers test.Helpers) { + reg = nerdtest.RegistryWithNoAuth(data, helpers, 80, false) + reg.Setup(data, helpers) + + testImageRef := fmt.Sprintf("%s/%s:%s", + reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) + dockerfile := fmt.Sprintf(`FROM %s +CMD ["echo", "nerdctl-build-test-string"] + `, testutil.CommonImage) + + buildCtx := testhelpers.CreateBuildContext(t, dockerfile) + helpers.Ensure("build", "-t", testImageRef, buildCtx) + helpers.Ensure("--insecure-registry", "push", testImageRef) + helpers.Ensure("rmi", "-f", testImageRef) + }, + Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { + testImageRef := fmt.Sprintf("%s/%s:%s", + reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) + return helpers.Command("--insecure-registry", "pull", testImageRef) + }, + Expected: test.Expects(0, nil, nil), + Cleanup: func(data test.Data, helpers test.Helpers) { + if reg != nil { + reg.Cleanup(data, helpers) + testImageRef := fmt.Sprintf("%s/%s:%s", + reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1]) + helpers.Anyhow("rmi", "-f", testImageRef) + } + }, + } + + testCase.Run(t) +} diff --git a/cmd/nerdctl/issues/issues_main_test.go b/cmd/nerdctl/issues/issues_main_test.go new file mode 100644 index 00000000000..2a2ce7be191 --- /dev/null +++ b/cmd/nerdctl/issues/issues_main_test.go @@ -0,0 +1,27 @@ +/* + 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 issues + +import ( + "testing" + + "github.com/containerd/nerdctl/v2/pkg/testutil" +) + +func TestMain(m *testing.M) { + testutil.M(m) +} diff --git a/cmd/nerdctl/issues/issues_linux_test.go b/cmd/nerdctl/issues/issues_test.go similarity index 94% rename from cmd/nerdctl/issues/issues_linux_test.go rename to cmd/nerdctl/issues/issues_test.go index 3f9e89ffd89..15329ab89d7 100644 --- a/cmd/nerdctl/issues/issues_linux_test.go +++ b/cmd/nerdctl/issues/issues_test.go @@ -14,8 +14,6 @@ limitations under the License. */ -// Package issues is meant to document testing for complex scenarios type of issues that cannot simply be ascribed -// to a specific package. package issues import ( @@ -68,7 +66,13 @@ func TestIssue3425(t *testing.T) { }, { Description: "with commit", - Require: nerdtest.Private, + // FIXME: seems like windows commit is broken: + // time="2024-11-03T13:34:06Z" level=fatal msg="failed to apply diff: failed to reimport snapshot: + // hcsshim::ImportLayer failed in Win32: Cannot create a file when that file already exists. (0xb7)" + Require: test.Require( + nerdtest.Private, + test.Not(test.Windows), + ), Setup: func(data test.Data, helpers test.Helpers) { identifier := data.Identifier() helpers.Ensure("image", "pull", testutil.CommonImage) diff --git a/cmd/nerdctl/issues/main_linux_test.go b/cmd/nerdctl/issues/main_linux_test.go deleted file mode 100644 index a1af21d8ff5..00000000000 --- a/cmd/nerdctl/issues/main_linux_test.go +++ /dev/null @@ -1,58 +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 issues - -import ( - "testing" - - "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) { - testutil.M(m) -} - -// TestIssue108 tests https://github.com/containerd/nerdctl/issues/108 -// ("`nerdctl run --net=host -it` fails while `nerdctl run -it --net=host` works") -func TestIssue108(t *testing.T) { - testCase := nerdtest.Setup() - - testCase.SubTests = []*test.Case{ - { - Description: "-it --net=host", - Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { - cmd := helpers.Command("run", "-it", "--rm", "--net=host", testutil.CommonImage, "echo", "this was always working") - cmd.WithPseudoTTY() - return cmd - }, - Expected: test.Expects(0, nil, test.Equals("this was always working\r\n")), - }, - { - Description: "--net=host -it", - Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { - cmd := helpers.Command("run", "--rm", "--net=host", "-it", testutil.CommonImage, "echo", "this was not working due to issue #108") - cmd.WithPseudoTTY() - return cmd - }, - Expected: test.Expects(0, nil, test.Equals("this was not working due to issue #108\r\n")), - }, - } - - testCase.Run(t) -} diff --git a/pkg/testutil/nerdtest/platform/platform_windows.go b/pkg/testutil/nerdtest/platform/platform_windows.go index 56be8501931..af77a3254a5 100644 --- a/pkg/testutil/nerdtest/platform/platform_windows.go +++ b/pkg/testutil/nerdtest/platform/platform_windows.go @@ -17,21 +17,17 @@ package platform import ( - "fmt" + "github.com/containerd/nerdctl/v2/pkg/testutil" ) func DataHome() (string, error) { panic("not supported") } -// The following are here solely for windows to compile. They are not used, as the corresponding tests are running only on linux. -func mirrorOf(s string) string { - return fmt.Sprintf("ghcr.io/stargz-containers/%s-org", s) -} - var ( - RegistryImageStable = mirrorOf("registry:2") - RegistryImageNext = "ghcr.io/distribution/distribution:" - KuboImage = mirrorOf("ipfs/kubo:v0.16.0") - DockerAuthImage = mirrorOf("cesanta/docker_auth:1.7") + RegistryImageStable = "dubogus/win-registry" + // Temporary deviations just so we do not fail on download - we need these images though + RegistryImageNext = testutil.CommonImage + KuboImage = testutil.CommonImage // mirrorOf("ipfs/kubo:v0.16.0") + DockerAuthImage = testutil.CommonImage // mirrorOf("cesanta/docker_auth:1.7") ) diff --git a/pkg/testutil/nerdtest/requirements.go b/pkg/testutil/nerdtest/requirements.go index a5d89481203..2d12fe21347 100644 --- a/pkg/testutil/nerdtest/requirements.go +++ b/pkg/testutil/nerdtest/requirements.go @@ -231,7 +231,7 @@ var Stargz = &test.Requirement{ // Registry marks a test as requiring a registry to be deployed var Registry = test.Require( // Registry requires Linux currently - test.Linux, + // test.Linux, (func() *test.Requirement { // Provisional: see note in cleanup // var reg *registry.Server diff --git a/pkg/testutil/testutil_windows.go b/pkg/testutil/testutil_windows.go index 868e5df1cd8..c36b2ea58d9 100644 --- a/pkg/testutil/testutil_windows.go +++ b/pkg/testutil/testutil_windows.go @@ -35,7 +35,7 @@ const ( // for the tests that are run now this image (used in k8s upstream testing) meets the needs // use gcr.io/k8s-staging-e2e-test-images/busybox:1.36-1-windows-amd64-ltsc2022 locally on windows 11 // https://github.com/microsoft/Windows-Containers/issues/179 - BusyboxImage = "gcr.io/k8s-staging-e2e-test-images/busybox:1.36.1-1" + BusyboxImage = "docker.io/dubogus/win-busybox:latest" // "gcr.io/k8s-staging-e2e-test-images/busybox:1.36.1-1" WindowsNano = BusyboxImage CommonImage = WindowsNano