mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
move api test client setup to a package.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
5fa134b906
commit
c66c0447ef
4 changed files with 35 additions and 25 deletions
|
@ -10,7 +10,9 @@ source "$SCRIPTDIR/make/.go-autogen"
|
||||||
|
|
||||||
: ${TEST_REPEAT:=1}
|
: ${TEST_REPEAT:=1}
|
||||||
|
|
||||||
integration_api_dirs=("$(find ./integration -type d | grep -vE '^./integration$')")
|
integration_api_dirs=("$(
|
||||||
|
find ./integration -type d |
|
||||||
|
grep -vE '^(./integration$|./integration/util)')")
|
||||||
|
|
||||||
run_test_integration() {
|
run_test_integration() {
|
||||||
local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
||||||
|
|
|
@ -7,52 +7,54 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/docker/docker/integration/util/request"
|
||||||
|
"github.com/docker/docker/pkg/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAPICreateWithNotExistImage(t *testing.T) {
|
func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
clt := createClient(t)
|
client := request.NewAPIClient(t)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
doc string
|
||||||
image string
|
image string
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
doc: "image and tag",
|
||||||
image: "test456:v1",
|
image: "test456:v1",
|
||||||
expectedError: "No such image: test456:v1",
|
expectedError: "No such image: test456:v1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
doc: "image no tag",
|
||||||
image: "test456",
|
image: "test456",
|
||||||
expectedError: "No such image: test456",
|
expectedError: "No such image: test456",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
doc: "digest",
|
||||||
image: "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
|
image: "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
|
||||||
expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
|
expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(strconv.Itoa(index), func(t *testing.T) {
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
_, err := clt.ContainerCreate(context.Background(),
|
_, err := client.ContainerCreate(context.Background(),
|
||||||
&container.Config{
|
&container.Config{Image: tc.image},
|
||||||
Image: tc.image,
|
|
||||||
},
|
|
||||||
&container.HostConfig{},
|
&container.HostConfig{},
|
||||||
&network.NetworkingConfig{},
|
&network.NetworkingConfig{},
|
||||||
"foo",
|
"foo",
|
||||||
)
|
)
|
||||||
require.Error(t, err)
|
testutil.ErrorContains(t, err, tc.expectedError)
|
||||||
require.Contains(t, err.Error(), tc.expectedError)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPICreateEmptyEnv(t *testing.T) {
|
func TestCreateWithInvalidEnv(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
clt := createClient(t)
|
client := request.NewAPIClient(t)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
env string
|
env string
|
||||||
|
@ -76,7 +78,7 @@ func TestAPICreateEmptyEnv(t *testing.T) {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(strconv.Itoa(index), func(t *testing.T) {
|
t.Run(strconv.Itoa(index), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
_, err := clt.ContainerCreate(context.Background(),
|
_, err := client.ContainerCreate(context.Background(),
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Image: "busybox",
|
Image: "busybox",
|
||||||
Env: []string{tc.env},
|
Env: []string{tc.env},
|
||||||
|
@ -85,8 +87,7 @@ func TestAPICreateEmptyEnv(t *testing.T) {
|
||||||
&network.NetworkingConfig{},
|
&network.NetworkingConfig{},
|
||||||
"foo",
|
"foo",
|
||||||
)
|
)
|
||||||
require.Error(t, err)
|
testutil.ErrorContains(t, err, tc.expectedError)
|
||||||
require.Contains(t, err.Error(), tc.expectedError)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/integration-cli/environment"
|
"github.com/docker/docker/integration-cli/environment"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -33,12 +31,6 @@ func TestMain(m *testing.M) {
|
||||||
os.Exit(res)
|
os.Exit(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createClient(t *testing.T) client.APIClient {
|
|
||||||
clt, err := client.NewEnvClient()
|
|
||||||
require.NoError(t, err)
|
|
||||||
return clt
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupTest(t *testing.T) func() {
|
func setupTest(t *testing.T) func() {
|
||||||
environment.ProtectImages(t, testEnv)
|
environment.ProtectImages(t, testEnv)
|
||||||
return func() { testEnv.Clean(t, testEnv.DockerBinary()) }
|
return func() { testEnv.Clean(t, testEnv.DockerBinary()) }
|
||||||
|
|
15
integration/util/request/client.go
Normal file
15
integration/util/request/client.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package request
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewAPIClient returns a docker API client configured from environment variables
|
||||||
|
func NewAPIClient(t *testing.T) client.APIClient {
|
||||||
|
clt, err := client.NewEnvClient()
|
||||||
|
require.NoError(t, err)
|
||||||
|
return clt
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue