Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -10,7 +10,9 @@ source "$SCRIPTDIR/make/.go-autogen" |
| 10 | 10 |
|
| 11 | 11 |
: ${TEST_REPEAT:=1}
|
| 12 | 12 |
|
| 13 |
-integration_api_dirs=("$(find ./integration -type d | grep -vE '^./integration$')")
|
|
| 13 |
+integration_api_dirs=("$(
|
|
| 14 |
+ find ./integration -type d | |
|
| 15 |
+ grep -vE '^(./integration$|./integration/util)')") |
|
| 14 | 16 |
|
| 15 | 17 |
run_test_integration() {
|
| 16 | 18 |
local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
| ... | ... |
@@ -7,52 +7,54 @@ import ( |
| 7 | 7 |
|
| 8 | 8 |
"github.com/docker/docker/api/types/container" |
| 9 | 9 |
"github.com/docker/docker/api/types/network" |
| 10 |
- "github.com/stretchr/testify/require" |
|
| 10 |
+ "github.com/docker/docker/integration/util/request" |
|
| 11 |
+ "github.com/docker/docker/pkg/testutil" |
|
| 11 | 12 |
) |
| 12 | 13 |
|
| 13 |
-func TestAPICreateWithNotExistImage(t *testing.T) {
|
|
| 14 |
+func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
|
|
| 14 | 15 |
defer setupTest(t)() |
| 15 |
- clt := createClient(t) |
|
| 16 |
+ client := request.NewAPIClient(t) |
|
| 16 | 17 |
|
| 17 | 18 |
testCases := []struct {
|
| 19 |
+ doc string |
|
| 18 | 20 |
image string |
| 19 | 21 |
expectedError string |
| 20 | 22 |
}{
|
| 21 | 23 |
{
|
| 24 |
+ doc: "image and tag", |
|
| 22 | 25 |
image: "test456:v1", |
| 23 | 26 |
expectedError: "No such image: test456:v1", |
| 24 | 27 |
}, |
| 25 | 28 |
{
|
| 29 |
+ doc: "image no tag", |
|
| 26 | 30 |
image: "test456", |
| 27 | 31 |
expectedError: "No such image: test456", |
| 28 | 32 |
}, |
| 29 | 33 |
{
|
| 34 |
+ doc: "digest", |
|
| 30 | 35 |
image: "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", |
| 31 | 36 |
expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", |
| 32 | 37 |
}, |
| 33 | 38 |
} |
| 34 | 39 |
|
| 35 |
- for index, tc := range testCases {
|
|
| 40 |
+ for _, tc := range testCases {
|
|
| 36 | 41 |
tc := tc |
| 37 |
- t.Run(strconv.Itoa(index), func(t *testing.T) {
|
|
| 42 |
+ t.Run(tc.doc, func(t *testing.T) {
|
|
| 38 | 43 |
t.Parallel() |
| 39 |
- _, err := clt.ContainerCreate(context.Background(), |
|
| 40 |
- &container.Config{
|
|
| 41 |
- Image: tc.image, |
|
| 42 |
- }, |
|
| 44 |
+ _, err := client.ContainerCreate(context.Background(), |
|
| 45 |
+ &container.Config{Image: tc.image},
|
|
| 43 | 46 |
&container.HostConfig{},
|
| 44 | 47 |
&network.NetworkingConfig{},
|
| 45 | 48 |
"foo", |
| 46 | 49 |
) |
| 47 |
- require.Error(t, err) |
|
| 48 |
- require.Contains(t, err.Error(), tc.expectedError) |
|
| 50 |
+ testutil.ErrorContains(t, err, tc.expectedError) |
|
| 49 | 51 |
}) |
| 50 | 52 |
} |
| 51 | 53 |
} |
| 52 | 54 |
|
| 53 |
-func TestAPICreateEmptyEnv(t *testing.T) {
|
|
| 55 |
+func TestCreateWithInvalidEnv(t *testing.T) {
|
|
| 54 | 56 |
defer setupTest(t)() |
| 55 |
- clt := createClient(t) |
|
| 57 |
+ client := request.NewAPIClient(t) |
|
| 56 | 58 |
|
| 57 | 59 |
testCases := []struct {
|
| 58 | 60 |
env string |
| ... | ... |
@@ -76,7 +78,7 @@ func TestAPICreateEmptyEnv(t *testing.T) {
|
| 76 | 76 |
tc := tc |
| 77 | 77 |
t.Run(strconv.Itoa(index), func(t *testing.T) {
|
| 78 | 78 |
t.Parallel() |
| 79 |
- _, err := clt.ContainerCreate(context.Background(), |
|
| 79 |
+ _, err := client.ContainerCreate(context.Background(), |
|
| 80 | 80 |
&container.Config{
|
| 81 | 81 |
Image: "busybox", |
| 82 | 82 |
Env: []string{tc.env},
|
| ... | ... |
@@ -85,8 +87,7 @@ func TestAPICreateEmptyEnv(t *testing.T) {
|
| 85 | 85 |
&network.NetworkingConfig{},
|
| 86 | 86 |
"foo", |
| 87 | 87 |
) |
| 88 |
- require.Error(t, err) |
|
| 89 |
- require.Contains(t, err.Error(), tc.expectedError) |
|
| 88 |
+ testutil.ErrorContains(t, err, tc.expectedError) |
|
| 90 | 89 |
}) |
| 91 | 90 |
} |
| 92 | 91 |
} |
| ... | ... |
@@ -5,9 +5,7 @@ import ( |
| 5 | 5 |
"os" |
| 6 | 6 |
"testing" |
| 7 | 7 |
|
| 8 |
- "github.com/docker/docker/client" |
|
| 9 | 8 |
"github.com/docker/docker/integration-cli/environment" |
| 10 |
- "github.com/stretchr/testify/require" |
|
| 11 | 9 |
) |
| 12 | 10 |
|
| 13 | 11 |
var ( |
| ... | ... |
@@ -33,12 +31,6 @@ func TestMain(m *testing.M) {
|
| 33 | 33 |
os.Exit(res) |
| 34 | 34 |
} |
| 35 | 35 |
|
| 36 |
-func createClient(t *testing.T) client.APIClient {
|
|
| 37 |
- clt, err := client.NewEnvClient() |
|
| 38 |
- require.NoError(t, err) |
|
| 39 |
- return clt |
|
| 40 |
-} |
|
| 41 |
- |
|
| 42 | 36 |
func setupTest(t *testing.T) func() {
|
| 43 | 37 |
environment.ProtectImages(t, testEnv) |
| 44 | 38 |
return func() { testEnv.Clean(t, testEnv.DockerBinary()) }
|
| 45 | 39 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,15 @@ |
| 0 |
+package request |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "testing" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/docker/docker/client" |
|
| 6 |
+ "github.com/stretchr/testify/require" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+// NewAPIClient returns a docker API client configured from environment variables |
|
| 10 |
+func NewAPIClient(t *testing.T) client.APIClient {
|
|
| 11 |
+ clt, err := client.NewEnvClient() |
|
| 12 |
+ require.NoError(t, err) |
|
| 13 |
+ return clt |
|
| 14 |
+} |