Skip to content

Commit 4d86ebe

Browse files
committed
Testing windows with updated busybox image
Signed-off-by: apostasie <[email protected]>
1 parent 1f8fe6a commit 4d86ebe

10 files changed

+146
-129
lines changed

cmd/nerdctl/container/container_run_user_windows_test.go

+29-11
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,40 @@ import (
2424

2525
func TestRunUserName(t *testing.T) {
2626
base := testutil.NewBase(t)
27-
testCases := map[string]string{
28-
"": "ContainerAdministrator",
29-
"ContainerAdministrator": "ContainerAdministrator",
30-
"ContainerUser": "ContainerUser",
27+
testCases := []struct {
28+
explicitUser string
29+
whoami string
30+
env string
31+
}{
32+
{
33+
explicitUser: "",
34+
whoami: "ContainerUser",
35+
env: "ContainerUser",
36+
},
37+
{
38+
explicitUser: "ContainerUser",
39+
whoami: "ContainerUser",
40+
env: "ContainerUser",
41+
},
42+
{
43+
explicitUser: "ContainerAdministrator",
44+
whoami: "root",
45+
env: "ContainerAdministrator",
46+
},
3147
}
32-
for userStr, expected := range testCases {
33-
userStr := userStr
34-
expected := expected
35-
t.Run(userStr, func(t *testing.T) {
48+
49+
for _, user := range testCases {
50+
t.Run(user.explicitUser, func(t *testing.T) {
3651
t.Parallel()
3752
cmd := []string{"run", "--rm"}
38-
if userStr != "" {
39-
cmd = append(cmd, "--user", userStr)
53+
if user.explicitUser != "" {
54+
cmd = append(cmd, "--user", user.explicitUser)
4055
}
4156
cmd = append(cmd, testutil.WindowsNano, "whoami")
42-
base.Cmd(cmd...).AssertOutContains(expected)
57+
base.Cmd(cmd...).AssertOutContains(user.whoami)
58+
59+
cmd = append(cmd, testutil.WindowsNano, "echo $USERNAME")
60+
base.Cmd(cmd...).AssertOutContains(user.whoami)
4361
})
4462
}
4563
}

cmd/nerdctl/container/container_top_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestTop(t *testing.T) {
4646
testCase.SubTests = []*test.Case{
4747
{
4848
Description: "with o pid,user,cmd",
49-
// Docker does not support top -o
49+
// Docker does not support top -o.
5050
Require: test.Not(nerdtest.Docker),
5151
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
5252
return helpers.Command("top", data.Get("cID"), "-o", "pid,user,cmd")

cmd/nerdctl/image/image_pull_linux_test.go

-44
Original file line numberDiff line numberDiff line change
@@ -100,50 +100,6 @@ CMD ["echo", "nerdctl-build-test-string"]
100100
testCase.Run(t)
101101
}
102102

103-
func TestImagePullPlainHttpWithDefaultPort(t *testing.T) {
104-
nerdtest.Setup()
105-
106-
var registry *testregistry.RegistryServer
107-
108-
testCase := &test.Case{
109-
Require: test.Require(
110-
test.Linux,
111-
test.Not(nerdtest.Docker),
112-
nerdtest.Build,
113-
),
114-
Setup: func(data test.Data, helpers test.Helpers) {
115-
base := testutil.NewBase(t)
116-
registry = testregistry.NewWithNoAuth(base, 80, false)
117-
testImageRef := fmt.Sprintf("%s/%s:%s",
118-
registry.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1])
119-
dockerfile := fmt.Sprintf(`FROM %s
120-
CMD ["echo", "nerdctl-build-test-string"]
121-
`, testutil.CommonImage)
122-
123-
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
124-
helpers.Ensure("build", "-t", testImageRef, buildCtx)
125-
helpers.Ensure("--insecure-registry", "push", testImageRef)
126-
helpers.Ensure("rmi", "-f", testImageRef)
127-
},
128-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
129-
testImageRef := fmt.Sprintf("%s/%s:%s",
130-
registry.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1])
131-
return helpers.Command("--insecure-registry", "pull", testImageRef)
132-
},
133-
Expected: test.Expects(0, nil, nil),
134-
Cleanup: func(data test.Data, helpers test.Helpers) {
135-
if registry != nil {
136-
registry.Cleanup(nil)
137-
testImageRef := fmt.Sprintf("%s/%s:%s",
138-
registry.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1])
139-
helpers.Anyhow("rmi", "-f", testImageRef)
140-
}
141-
},
142-
}
143-
144-
testCase.Run(t)
145-
}
146-
147103
func TestImagePullSoci(t *testing.T) {
148104
nerdtest.Setup()
149105

cmd/nerdctl/image/image_pull_test.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package image
18+
19+
import (
20+
"fmt"
21+
"strings"
22+
"testing"
23+
24+
testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
25+
"github.com/containerd/nerdctl/v2/pkg/testutil"
26+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
27+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest/registry"
28+
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
29+
)
30+
31+
func TestImagePullPlainHttpWithDefaultPort(t *testing.T) {
32+
nerdtest.Setup()
33+
34+
var reg *registry.Server
35+
36+
testCase := &test.Case{
37+
Require: test.Require(
38+
nerdtest.Registry,
39+
test.Not(nerdtest.Docker),
40+
nerdtest.Build,
41+
),
42+
Setup: func(data test.Data, helpers test.Helpers) {
43+
reg = nerdtest.RegistryWithNoAuth(data, helpers, 80, false)
44+
reg.Setup(data, helpers)
45+
46+
testImageRef := fmt.Sprintf("%s/%s:%s",
47+
reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1])
48+
dockerfile := fmt.Sprintf(`FROM %s
49+
CMD ["echo", "nerdctl-build-test-string"]
50+
`, testutil.CommonImage)
51+
52+
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
53+
helpers.Ensure("build", "-t", testImageRef, buildCtx)
54+
helpers.Ensure("--insecure-registry", "push", testImageRef)
55+
helpers.Ensure("rmi", "-f", testImageRef)
56+
},
57+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
58+
testImageRef := fmt.Sprintf("%s/%s:%s",
59+
reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1])
60+
return helpers.Command("--insecure-registry", "pull", testImageRef)
61+
},
62+
Expected: test.Expects(0, nil, nil),
63+
Cleanup: func(data test.Data, helpers test.Helpers) {
64+
if reg != nil {
65+
reg.Cleanup(data, helpers)
66+
testImageRef := fmt.Sprintf("%s/%s:%s",
67+
reg.IP.String(), data.Identifier(), strings.Split(testutil.CommonImage, ":")[1])
68+
helpers.Anyhow("rmi", "-f", testImageRef)
69+
}
70+
},
71+
}
72+
73+
testCase.Run(t)
74+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package issues
18+
19+
import (
20+
"testing"
21+
22+
"github.com/containerd/nerdctl/v2/pkg/testutil"
23+
)
24+
25+
func TestMain(m *testing.M) {
26+
testutil.M(m)
27+
}

cmd/nerdctl/issues/issues_linux_test.go cmd/nerdctl/issues/issues_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
limitations under the License.
1515
*/
1616

17-
// Package issues is meant to document testing for complex scenarios type of issues that cannot simply be ascribed
18-
// to a specific package.
1917
package issues
2018

2119
import (
@@ -68,7 +66,13 @@ func TestIssue3425(t *testing.T) {
6866
},
6967
{
7068
Description: "with commit",
71-
Require: nerdtest.Private,
69+
// FIXME: seems like windows commit is broken:
70+
// time="2024-11-03T13:34:06Z" level=fatal msg="failed to apply diff: failed to reimport snapshot:
71+
// hcsshim::ImportLayer failed in Win32: Cannot create a file when that file already exists. (0xb7)"
72+
Require: test.Require(
73+
nerdtest.Private,
74+
test.Not(test.Windows),
75+
),
7276
Setup: func(data test.Data, helpers test.Helpers) {
7377
identifier := data.Identifier()
7478
helpers.Ensure("image", "pull", testutil.CommonImage)

cmd/nerdctl/issues/main_linux_test.go

-58
This file was deleted.

pkg/testutil/nerdtest/platform/platform_windows.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@
1717
package platform
1818

1919
import (
20-
"fmt"
20+
"github.com/containerd/nerdctl/v2/pkg/testutil"
2121
)
2222

2323
func DataHome() (string, error) {
2424
panic("not supported")
2525
}
2626

27-
// The following are here solely for windows to compile. They are not used, as the corresponding tests are running only on linux.
28-
func mirrorOf(s string) string {
29-
return fmt.Sprintf("ghcr.io/stargz-containers/%s-org", s)
30-
}
31-
3227
var (
33-
RegistryImageStable = mirrorOf("registry:2")
34-
RegistryImageNext = "ghcr.io/distribution/distribution:"
35-
KuboImage = mirrorOf("ipfs/kubo:v0.16.0")
36-
DockerAuthImage = mirrorOf("cesanta/docker_auth:1.7")
28+
RegistryImageStable = "dubogus/win-registry"
29+
// Temporary deviations just so we do not fail on download - we need these images though
30+
RegistryImageNext = testutil.CommonImage
31+
KuboImage = testutil.CommonImage // mirrorOf("ipfs/kubo:v0.16.0")
32+
DockerAuthImage = testutil.CommonImage // mirrorOf("cesanta/docker_auth:1.7")
3733
)

pkg/testutil/nerdtest/requirements.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ var Stargz = &test.Requirement{
231231
// Registry marks a test as requiring a registry to be deployed
232232
var Registry = test.Require(
233233
// Registry requires Linux currently
234-
test.Linux,
234+
// test.Linux,
235235
(func() *test.Requirement {
236236
// Provisional: see note in cleanup
237237
// var reg *registry.Server

pkg/testutil/testutil_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
// for the tests that are run now this image (used in k8s upstream testing) meets the needs
3636
// use gcr.io/k8s-staging-e2e-test-images/busybox:1.36-1-windows-amd64-ltsc2022 locally on windows 11
3737
// https://github.com/microsoft/Windows-Containers/issues/179
38-
BusyboxImage = "gcr.io/k8s-staging-e2e-test-images/busybox:1.36.1-1"
38+
BusyboxImage = "docker.io/dubogus/win-busybox:latest" // "gcr.io/k8s-staging-e2e-test-images/busybox:1.36.1-1"
3939
WindowsNano = BusyboxImage
4040
CommonImage = WindowsNano
4141

0 commit comments

Comments
 (0)