forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
test-integration
target (and deprecate/freeze `test-integ…
…ration-cli`) This adds a new package `integration` where `engine` integration tests should live. Those integration tests should not depends on any `cli` components (except from the `dockerd` daemon for now — to actually start a daemon). Signed-off-by: Vincent Demeester <vincent@sbr.pm>
- Loading branch information
1 parent
187cd25
commit 6b025a8
Showing
8 changed files
with
201 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ DEFAULT_BUNDLES=( | |
dynbinary | ||
|
||
test-unit | ||
test-integration | ||
test-integration-cli | ||
test-docker-py | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
source hack/make/.integration-test-helpers | ||
|
||
# subshell so that we can export PATH without breaking other things | ||
( | ||
bundle .integration-daemon-start | ||
|
||
bundle .integration-daemon-setup | ||
|
||
bundle_test_integration | ||
|
||
bundle .integration-daemon-stop | ||
|
||
if [ "$(go env GOOS)" != 'windows' ] | ||
then | ||
leftovers=$(ps -ax -o pid,cmd | awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration-cli/ { print $1 }') | ||
if [ -n "$leftovers" ] | ||
then | ||
ps aux | ||
kill -9 $leftovers 2> /dev/null | ||
echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
) 2>&1 | tee -a "$DEST/test.log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package container | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"strconv" | ||
|
||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/api/types/network" | ||
"github.com/docker/docker/client" | ||
"github.com/docker/docker/integration-cli/environment" | ||
"github.com/docker/docker/integration-cli/fixtures/load" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
testEnv *environment.Execution | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
var err error | ||
testEnv, err = environment.New() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
if testEnv.LocalDaemon() { | ||
fmt.Println("INFO: Testing against a local daemon") | ||
} else { | ||
fmt.Println("INFO: Testing against a remote daemon") | ||
} | ||
|
||
// TODO: ensure and protect images | ||
res := m.Run() | ||
os.Exit(res) | ||
} | ||
|
||
func TestAPICreateWithNotExistImage(t *testing.T) { | ||
defer setupTest(t)() | ||
clt := createClient(t) | ||
|
||
testCases := []struct { | ||
image string | ||
expectedError string | ||
}{ | ||
{ | ||
image: "test456:v1", | ||
expectedError: "No such image: test456:v1", | ||
}, | ||
{ | ||
image: "test456", | ||
expectedError: "No such image: test456", | ||
}, | ||
{ | ||
image: "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", | ||
expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", | ||
}, | ||
} | ||
|
||
for index, tc := range testCases { | ||
tc := tc | ||
t.Run(strconv.Itoa(index), func(t *testing.T) { | ||
t.Parallel() | ||
_, err := clt.ContainerCreate(context.Background(), | ||
&container.Config{ | ||
Image: tc.image, | ||
}, | ||
&container.HostConfig{}, | ||
&network.NetworkingConfig{}, | ||
"foo", | ||
) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), tc.expectedError) | ||
}) | ||
} | ||
} | ||
|
||
func TestAPICreateEmptyEnv(t *testing.T) { | ||
defer setupTest(t)() | ||
clt := createClient(t) | ||
|
||
testCases := []struct { | ||
env string | ||
expectedError string | ||
}{ | ||
{ | ||
env: "", | ||
expectedError: "invalid environment variable:", | ||
}, | ||
{ | ||
env: "=", | ||
expectedError: "invalid environment variable: =", | ||
}, | ||
{ | ||
env: "=foo", | ||
expectedError: "invalid environment variable: =foo", | ||
}, | ||
} | ||
|
||
for index, tc := range testCases { | ||
tc := tc | ||
t.Run(strconv.Itoa(index), func(t *testing.T) { | ||
t.Parallel() | ||
_, err := clt.ContainerCreate(context.Background(), | ||
&container.Config{ | ||
Image: "busybox", | ||
Env: []string{tc.env}, | ||
}, | ||
&container.HostConfig{}, | ||
&network.NetworkingConfig{}, | ||
"foo", | ||
) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), tc.expectedError) | ||
}) | ||
} | ||
} | ||
|
||
func createClient(t *testing.T) client.APIClient { | ||
clt, err := client.NewEnvClient() | ||
require.NoError(t, err) | ||
return clt | ||
} | ||
|
||
func setupTest(t *testing.T) func() { | ||
if testEnv.DaemonPlatform() == "linux" { | ||
images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"} | ||
err := load.FrozenImagesLinux(testEnv.DockerBinary(), images...) | ||
if err != nil { | ||
t.Fatalf("%+v", err) | ||
} | ||
defer testEnv.ProtectImage(t, images...) | ||
} | ||
return func() { | ||
testEnv.Clean(t, testEnv.DockerBinary()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package integration provides integrations tests for Moby (API). | ||
// These tests require a daemon (dockerd for now) to run. | ||
package integration |