Skip to content

Commit

Permalink
Enabling Windows integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Salahuddin Khan <salah@docker.com>
  • Loading branch information
salah-khan committed Sep 26, 2018
1 parent d3cc071 commit 4c8b1fd
Show file tree
Hide file tree
Showing 17 changed files with 630 additions and 383 deletions.
618 changes: 353 additions & 265 deletions hack/ci/windowsRS1.ps1

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions integration/build/build_squash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

func TestBuildSquashParent(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
d := daemon.New(t, daemon.WithExperimental)
d.StartWithBusybox(t)
Expand Down
2 changes: 2 additions & 0 deletions integration/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
// Test cases in #36996
func TestBuildLabelWithTargets(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "test added after 1.38")
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
bldName := "build-a"
testLabels := map[string]string{
"foo": "bar",
Expand Down Expand Up @@ -443,6 +444,7 @@ RUN [ ! -f foo ]

// #37581
func TestBuildWithHugeFile(t *testing.T) {
skip.If(t, testEnv.OSType == "windows")
ctx := context.TODO()
defer setupTest(t)()

Expand Down
101 changes: 101 additions & 0 deletions integration/container/stop_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package container // import "github.com/docker/docker/integration/container"

import (
"context"
"fmt"
"strconv"
"strings"
"testing"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/internal/test/request"
"gotest.tools/assert"
"gotest.tools/icmd"
"gotest.tools/poll"
"gotest.tools/skip"
)

// TestStopContainerWithTimeout checks that ContainerStop with
// a timeout works as documented, i.e. in case of negative timeout
// waiting is not limited (issue #35311).
func TestStopContainerWithTimeout(t *testing.T) {
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()

testCmd := container.WithCmd("sh", "-c", "sleep 2 && exit 42")
testData := []struct {
doc string
timeout int
expectedExitCode int
}{
// In case container is forcefully killed, 137 is returned,
// otherwise the exit code from the above script
{
"zero timeout: expect forceful container kill",
0, 137,
},
{
"too small timeout: expect forceful container kill",
1, 137,
},
{
"big enough timeout: expect graceful container stop",
3, 42,
},
{
"unlimited timeout: expect graceful container stop",
-1, 42,
},
}

for _, d := range testData {
d := d
t.Run(strconv.Itoa(d.timeout), func(t *testing.T) {
t.Parallel()
id := container.Run(t, ctx, client, testCmd)

timeout := time.Duration(d.timeout) * time.Second
err := client.ContainerStop(ctx, id, &timeout)
assert.NilError(t, err)

poll.WaitOn(t, container.IsStopped(ctx, client, id),
poll.WithDelay(100*time.Millisecond))

inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err)
assert.Equal(t, inspect.State.ExitCode, d.expectedExitCode)
})
}
}

func TestDeleteDevicemapper(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.Driver != "devicemapper")
skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run")

defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()

id := container.Run(t, ctx, client, container.WithName("foo-"+t.Name()), container.WithCmd("echo"))

poll.WaitOn(t, container.IsStopped(ctx, client, id), poll.WithDelay(100*time.Millisecond))

inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err)

deviceID := inspect.GraphDriver.Data["DeviceId"]

// Find pool name from device name
deviceName := inspect.GraphDriver.Data["DeviceName"]
devicePrefix := deviceName[:strings.LastIndex(deviceName, "-")]
devicePool := fmt.Sprintf("/dev/mapper/%s-pool", devicePrefix)

result := icmd.RunCommand("dmsetup", "message", devicePool, "0", fmt.Sprintf("delete %s", deviceID))
result.Assert(t, icmd.Success)

err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{})
assert.NilError(t, err)
}
89 changes: 0 additions & 89 deletions integration/container/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ package container // import "github.com/docker/docker/integration/container"

import (
"context"
"fmt"
"strconv"
"strings"
"testing"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/internal/test/request"
"gotest.tools/assert"
"gotest.tools/icmd"
"gotest.tools/poll"
"gotest.tools/skip"
)

func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
Expand Down Expand Up @@ -42,86 +36,3 @@ func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
poll.WaitOn(t, container.IsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
}
}

// TestStopContainerWithTimeout checks that ContainerStop with
// a timeout works as documented, i.e. in case of negative timeout
// waiting is not limited (issue #35311).
func TestStopContainerWithTimeout(t *testing.T) {
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()

testCmd := container.WithCmd("sh", "-c", "sleep 2 && exit 42")
testData := []struct {
doc string
timeout int
expectedExitCode int
}{
// In case container is forcefully killed, 137 is returned,
// otherwise the exit code from the above script
{
"zero timeout: expect forceful container kill",
0, 137,
},
{
"too small timeout: expect forceful container kill",
1, 137,
},
{
"big enough timeout: expect graceful container stop",
3, 42,
},
{
"unlimited timeout: expect graceful container stop",
-1, 42,
},
}

for _, d := range testData {
d := d
t.Run(strconv.Itoa(d.timeout), func(t *testing.T) {
t.Parallel()
id := container.Run(t, ctx, client, testCmd)

timeout := time.Duration(d.timeout) * time.Second
err := client.ContainerStop(ctx, id, &timeout)
assert.NilError(t, err)

poll.WaitOn(t, container.IsStopped(ctx, client, id),
poll.WithDelay(100*time.Millisecond))

inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err)
assert.Equal(t, inspect.State.ExitCode, d.expectedExitCode)
})
}
}

func TestDeleteDevicemapper(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.Driver != "devicemapper")
skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run")

defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()

id := container.Run(t, ctx, client, container.WithName("foo-"+t.Name()), container.WithCmd("echo"))

poll.WaitOn(t, container.IsStopped(ctx, client, id), poll.WithDelay(100*time.Millisecond))

inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err)

deviceID := inspect.GraphDriver.Data["DeviceId"]

// Find pool name from device name
deviceName := inspect.GraphDriver.Data["DeviceName"]
devicePrefix := deviceName[:strings.LastIndex(deviceName, "-")]
devicePool := fmt.Sprintf("/dev/mapper/%s-pool", devicePrefix)

result := icmd.RunCommand("dmsetup", "message", devicePool, "0", fmt.Sprintf("delete %s", deviceID))
result.Assert(t, icmd.Success)

err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{})
assert.NilError(t, err)
}
69 changes: 69 additions & 0 deletions integration/container/stop_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package container // import "github.com/docker/docker/integration/container"

import (
"context"
"strconv"
"testing"
"time"

"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/internal/test/request"
"gotest.tools/assert"
"gotest.tools/poll"
"gotest.tools/skip"
)

// TestStopContainerWithTimeout checks that ContainerStop with
// a timeout works as documented, i.e. in case of negative timeout
// waiting is not limited (issue #35311).
func TestStopContainerWithTimeout(t *testing.T) {
skip.If(t, testEnv.OSType == "windows")
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()

testCmd := container.WithCmd("sh", "-c", "sleep 2 && exit 42")
testData := []struct {
doc string
timeout int
expectedExitCode int
}{
// In case container is forcefully killed, 137 is returned,
// otherwise the exit code from the above script
{
"zero timeout: expect forceful container kill",
1, 0x40010004,
},
{
"too small timeout: expect forceful container kill",
2, 0x40010004,
},
{
"big enough timeout: expect graceful container stop",
120, 42,
},
{
"unlimited timeout: expect graceful container stop",
-1, 42,
},
}

for _, d := range testData {
d := d
t.Run(strconv.Itoa(d.timeout), func(t *testing.T) {
t.Parallel()
id := container.Run(t, ctx, client, testCmd)

timeout := time.Duration(d.timeout) * time.Second
err := client.ContainerStop(ctx, id, &timeout)
assert.NilError(t, err)

poll.WaitOn(t, container.IsStopped(ctx, client, id),
poll.WithDelay(100*time.Millisecond))

inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err)
assert.Equal(t, inspect.State.ExitCode, d.expectedExitCode)
})
}
}
2 changes: 1 addition & 1 deletion integration/image/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/internal/test/request"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/skip"
"gotest.tools/skip"
)

// Ensure we don't regress on CVE-2017-14992.
Expand Down
2 changes: 2 additions & 0 deletions integration/image/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/docker/internal/testutil"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/skip"
)

// tagging a named image in a new unprefixed repo should work
Expand Down Expand Up @@ -95,6 +96,7 @@ func TestTagExistedNameWithoutForce(t *testing.T) {
// ensure tagging using official names works
// ensure all tags result in the same name
func TestTagOfficialNames(t *testing.T) {
skip.If(t, testEnv.OSType == "windows")
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()
Expand Down
26 changes: 0 additions & 26 deletions integration/internal/requirement/requirement.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"strings"
"testing"
"time"

"github.com/docker/docker/pkg/parsers/kernel"
"gotest.tools/icmd"
)

// HasHubConnectivity checks to see if https://hub.docker.com is
Expand All @@ -28,26 +25,3 @@ func HasHubConnectivity(t *testing.T) bool {
}
return err == nil
}

func overlayFSSupported() bool {
result := icmd.RunCommand("/bin/sh", "-c", "cat /proc/filesystems")
if result.Error != nil {
return false
}
return strings.Contains(result.Combined(), "overlay\n")
}

// Overlay2Supported returns true if the current system supports overlay2 as graphdriver
func Overlay2Supported(kernelVersion string) bool {
if !overlayFSSupported() {
return false
}

daemonV, err := kernel.ParseRelease(kernelVersion)
if err != nil {
return false
}
requiredV := kernel.VersionInfo{Kernel: 4}
return kernel.CompareKernelVersion(*daemonV, requiredV) > -1

}
31 changes: 31 additions & 0 deletions integration/internal/requirement/requirement_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package requirement // import "github.com/docker/docker/integration/internal/requirement"

import (
"strings"

"github.com/docker/docker/pkg/parsers/kernel"
"gotest.tools/icmd"
)

func overlayFSSupported() bool {
result := icmd.RunCommand("/bin/sh", "-c", "cat /proc/filesystems")
if result.Error != nil {
return false
}
return strings.Contains(result.Combined(), "overlay\n")
}

// Overlay2Supported returns true if the current system supports overlay2 as graphdriver
func Overlay2Supported(kernelVersion string) bool {
if !overlayFSSupported() {
return false
}

daemonV, err := kernel.ParseRelease(kernelVersion)
if err != nil {
return false
}
requiredV := kernel.VersionInfo{Kernel: 4}
return kernel.CompareKernelVersion(*daemonV, requiredV) > -1

}
Loading

0 comments on commit 4c8b1fd

Please sign in to comment.