Skip to content

Commit

Permalink
Testing windows with updated busybox image
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Dec 5, 2024
1 parent 1f8fe6a commit de1c917
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestRunInternetConnectivity(t *testing.T) {
args = append(args, tc.args...)
// TODO(aznashwan): smarter way to ensure internet connectivity is working.
// ping doesn't seem to work on GitHub Actions ("Request timed out.")
args = append(args, testutil.CommonImage, "curl.exe -sSL https://github.com")
args = append(args, testutil.CommonImage, "curl.exe", "-sSL", "https://github.com")
cmd := base.Cmd(args...)
cmd.AssertOutContains("<!DOCTYPE html>")
})
Expand Down
40 changes: 29 additions & 11 deletions cmd/nerdctl/container/container_run_user_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "root",
env: "ContainerAdministrator",
},
{
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)
})
}
}
2 changes: 1 addition & 1 deletion cmd/nerdctl/container/container_top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 0 additions & 44 deletions cmd/nerdctl/image/image_pull_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
74 changes: 74 additions & 0 deletions cmd/nerdctl/image/image_pull_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
27 changes: 27 additions & 0 deletions cmd/nerdctl/issues/issues_main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
58 changes: 0 additions & 58 deletions cmd/nerdctl/issues/main_linux_test.go

This file was deleted.

16 changes: 6 additions & 10 deletions pkg/testutil/nerdtest/platform/platform_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
2 changes: 1 addition & 1 deletion pkg/testutil/nerdtest/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutil/testutil_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit de1c917

Please sign in to comment.