X Tutup
Skip to content

Commit e6280a7

Browse files
committed
Enable integration tests on Windows using snapshotter and differ
Signed-off-by: Darren Stahl <darst@microsoft.com>
1 parent acf2087 commit e6280a7

File tree

9 files changed

+129
-255
lines changed

9 files changed

+129
-255
lines changed

client_test.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
golog "log"
1010
"os"
1111
"os/exec"
12-
"runtime"
1312
"testing"
1413
"time"
1514

1615
"google.golang.org/grpc/grpclog"
1716

1817
"github.com/containerd/containerd/log"
1918
"github.com/containerd/containerd/namespaces"
19+
"github.com/containerd/containerd/sys"
2020
"github.com/containerd/containerd/testutil"
2121
"github.com/sirupsen/logrus"
2222
)
@@ -62,7 +62,7 @@ func TestMain(m *testing.M) {
6262
defer cancel()
6363

6464
if !noDaemon {
65-
os.RemoveAll(defaultRoot)
65+
sys.ForceRemoveAll(defaultRoot)
6666

6767
err := ctrd.start("containerd", address, []string{
6868
"--root", defaultRoot,
@@ -99,17 +99,10 @@ func TestMain(m *testing.M) {
9999
}).Info("running tests against containerd")
100100

101101
// pull a seed image
102-
if runtime.GOOS != "windows" { // TODO: remove once pull is supported on windows
103-
if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil {
104-
ctrd.Stop()
105-
ctrd.Wait()
106-
fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
107-
os.Exit(1)
108-
}
109-
}
110-
111-
if err := platformTestSetup(client); err != nil {
112-
fmt.Fprintln(os.Stderr, "platform test setup failed", err)
102+
if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil {
103+
ctrd.Stop()
104+
ctrd.Wait()
105+
fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
113106
os.Exit(1)
114107
}
115108

@@ -132,7 +125,7 @@ func TestMain(m *testing.M) {
132125
fmt.Fprintln(os.Stderr, "failed to wait for containerd", err)
133126
}
134127
}
135-
if err := os.RemoveAll(defaultRoot); err != nil {
128+
if err := sys.ForceRemoveAll(defaultRoot); err != nil {
136129
fmt.Fprintln(os.Stderr, "failed to remove test root dir", err)
137130
os.Exit(1)
138131
}
@@ -169,11 +162,6 @@ func TestNewClient(t *testing.T) {
169162

170163
// All the container's tests depends on this, we need it to run first.
171164
func TestImagePull(t *testing.T) {
172-
if runtime.GOOS == "windows" {
173-
// TODO: remove once Windows has a snapshotter
174-
t.Skip("Windows does not have a snapshotter yet")
175-
}
176-
177165
client, err := newClient(t, address)
178166
if err != nil {
179167
t.Fatal(err)

client_unix_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ var (
1616
testImage string
1717
)
1818

19-
func platformTestSetup(client *Client) error {
20-
return nil
21-
}
22-
2319
func init() {
2420
switch runtime.GOARCH {
2521
case "386":

client_windows_test.go

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,16 @@
11
package containerd
22

33
import (
4-
"encoding/json"
5-
"fmt"
64
"os"
75
"path/filepath"
8-
9-
"github.com/pkg/errors"
106
)
117

128
const (
139
defaultAddress = `\\.\pipe\containerd-containerd-test`
14-
testImage = "docker.io/library/go:nanoserver"
10+
testImage = "docker.io/microsoft/nanoserver:latest"
1511
)
1612

1713
var (
18-
dockerLayerFolders []string
19-
2014
defaultRoot = filepath.Join(os.Getenv("programfiles"), "containerd", "root-test")
2115
defaultState = filepath.Join(os.Getenv("programfiles"), "containerd", "state-test")
2216
)
23-
24-
func platformTestSetup(client *Client) error {
25-
var (
26-
roots []string
27-
layerChains = make(map[string]string)
28-
)
29-
// Since we can't pull images yet, we'll piggyback on the default
30-
// docker's images
31-
wfPath := `C:\ProgramData\docker\windowsfilter`
32-
wf, err := os.Open(wfPath)
33-
if err != nil {
34-
return errors.Wrapf(err, "failed to access docker layers @ %s", wfPath)
35-
}
36-
defer wf.Close()
37-
entries, err := wf.Readdirnames(0)
38-
if err != nil {
39-
return errors.Wrapf(err, "failed to read %s entries", wfPath)
40-
}
41-
42-
for _, fn := range entries {
43-
layerChainPath := filepath.Join(wfPath, fn, "layerchain.json")
44-
lfi, err := os.Stat(layerChainPath)
45-
switch {
46-
case err == nil && lfi.Mode().IsRegular():
47-
f, err := os.OpenFile(layerChainPath, os.O_RDONLY, 0660)
48-
if err != nil {
49-
fmt.Fprintln(os.Stderr,
50-
errors.Wrapf(err, "failed to open %s", layerChainPath))
51-
continue
52-
}
53-
defer f.Close()
54-
l := make([]string, 0)
55-
if err := json.NewDecoder(f).Decode(&l); err != nil {
56-
fmt.Fprintln(os.Stderr,
57-
errors.Wrapf(err, "failed to decode %s", layerChainPath))
58-
continue
59-
}
60-
switch {
61-
case len(l) == 1:
62-
layerChains[l[0]] = filepath.Join(wfPath, fn)
63-
case len(l) > 1:
64-
fmt.Fprintf(os.Stderr, "Too many entries in %s: %d", layerChainPath, len(l))
65-
case len(l) == 0:
66-
roots = append(roots, filepath.Join(wfPath, fn))
67-
}
68-
case os.IsNotExist(err):
69-
// keep on going
70-
default:
71-
return errors.Wrapf(err, "error trying to access %s", layerChainPath)
72-
}
73-
}
74-
75-
// They'll be 2 roots, just take the first one
76-
l := roots[0]
77-
dockerLayerFolders = append(dockerLayerFolders, l)
78-
for {
79-
l = layerChains[l]
80-
if l == "" {
81-
break
82-
}
83-
84-
dockerLayerFolders = append([]string{l}, dockerLayerFolders...)
85-
}
86-
87-
return nil
88-
}

container_linux_test.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestDaemonRestart(t *testing.T) {
187187
t.Fatal(err)
188188
}
189189

190-
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "30")), withNewSnapshot(id, image))
190+
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), withProcessArgs("sleep", "30")), WithNewSnapshot(id, image))
191191
if err != nil {
192192
t.Fatal(err)
193193
}
@@ -266,7 +266,7 @@ func TestContainerAttach(t *testing.T) {
266266
t.Fatal(err)
267267
}
268268

269-
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withCat()), withNewSnapshot(id, image))
269+
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), withCat()), WithNewSnapshot(id, image))
270270
if err != nil {
271271
t.Fatal(err)
272272
}
@@ -427,8 +427,8 @@ func TestContainerUsername(t *testing.T) {
427427

428428
// squid user in the alpine image has a uid of 31
429429
container, err := client.NewContainer(ctx, id,
430-
withNewSnapshot(id, image),
431-
WithNewSpec(withImageConfig(image), oci.WithUsername("squid"), oci.WithProcessArgs("id", "-u")),
430+
WithNewSnapshot(id, image),
431+
WithNewSpec(oci.WithImageConfig(image), oci.WithUsername("squid"), oci.WithProcessArgs("id", "-u")),
432432
)
433433
if err != nil {
434434
t.Fatal(err)
@@ -487,7 +487,7 @@ func TestContainerAttachProcess(t *testing.T) {
487487
t.Fatal(err)
488488
}
489489

490-
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "100")), withNewSnapshot(id, image))
490+
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), withProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
491491
if err != nil {
492492
t.Fatal(err)
493493
}
@@ -620,8 +620,8 @@ func TestContainerUserID(t *testing.T) {
620620

621621
// adm user in the alpine image has a uid of 3 and gid of 4.
622622
container, err := client.NewContainer(ctx, id,
623-
withNewSnapshot(id, image),
624-
WithNewSpec(withImageConfig(image), oci.WithUserID(3), oci.WithProcessArgs("sh", "-c", "echo $(id -u):$(id -g)")),
623+
WithNewSnapshot(id, image),
624+
WithNewSpec(oci.WithImageConfig(image), oci.WithUserID(3), oci.WithProcessArgs("sh", "-c", "echo $(id -u):$(id -g)")),
625625
)
626626
if err != nil {
627627
t.Fatal(err)
@@ -674,8 +674,8 @@ func TestContainerKillAll(t *testing.T) {
674674
}
675675

676676
container, err := client.NewContainer(ctx, id,
677-
withNewSnapshot(id, image),
678-
WithNewSpec(withImageConfig(image),
677+
WithNewSnapshot(id, image),
678+
WithNewSpec(oci.WithImageConfig(image),
679679
withProcessArgs("sh", "-c", "top"),
680680
oci.WithHostNamespace(specs.PIDNamespace),
681681
),
@@ -730,7 +730,7 @@ func TestShimSigkilled(t *testing.T) {
730730
if err != nil {
731731
t.Fatal(err)
732732
}
733-
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image)), withNewSnapshot(id, image))
733+
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image)), WithNewSnapshot(id, image))
734734
if err != nil {
735735
t.Fatal(err)
736736
}
@@ -793,7 +793,7 @@ func TestDaemonRestartWithRunningShim(t *testing.T) {
793793
if err != nil {
794794
t.Fatal(err)
795795
}
796-
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), withNewSnapshot(id, image))
796+
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
797797
if err != nil {
798798
t.Fatal(err)
799799
}
@@ -877,8 +877,8 @@ func TestContainerRuntimeOptions(t *testing.T) {
877877

878878
container, err := client.NewContainer(
879879
ctx, id,
880-
WithNewSpec(withImageConfig(image), withExitStatus(7)),
881-
withNewSnapshot(id, image),
880+
WithNewSpec(oci.WithImageConfig(image), withExitStatus(7)),
881+
WithNewSnapshot(id, image),
882882
WithRuntime("io.containerd.runtime.v1.linux", &runctypes.RuncOptions{Runtime: "no-runc"}),
883883
)
884884
if err != nil {
@@ -917,8 +917,8 @@ func TestContainerKillInitPidHost(t *testing.T) {
917917
}
918918

919919
container, err := client.NewContainer(ctx, id,
920-
withNewSnapshot(id, image),
921-
WithNewSpec(withImageConfig(image),
920+
WithNewSnapshot(id, image),
921+
WithNewSpec(oci.WithImageConfig(image),
922922
withProcessArgs("sh", "-c", "sleep 42; echo hi"),
923923
oci.WithHostNamespace(specs.PIDNamespace),
924924
),
@@ -1007,7 +1007,7 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
10071007
t.Fatal(err)
10081008
}
10091009

1010-
opts := []NewContainerOpts{WithNewSpec(withImageConfig(image),
1010+
opts := []NewContainerOpts{WithNewSpec(oci.WithImageConfig(image),
10111011
withExitStatus(7),
10121012
oci.WithUserNamespace(0, 1000, 10000),
10131013
)}
@@ -1081,13 +1081,11 @@ func TestTaskResize(t *testing.T) {
10811081
)
10821082
defer cancel()
10831083

1084-
if runtime.GOOS != "windows" {
1085-
image, err = client.GetImage(ctx, testImage)
1086-
if err != nil {
1087-
t.Fatal(err)
1088-
}
1084+
image, err = client.GetImage(ctx, testImage)
1085+
if err != nil {
1086+
t.Fatal(err)
10891087
}
1090-
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withExitStatus(7)), withNewSnapshot(id, image))
1088+
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), withExitStatus(7)), WithNewSnapshot(id, image))
10911089
if err != nil {
10921090
t.Fatal(err)
10931091
}

0 commit comments

Comments
 (0)
X Tutup