2017-05-23 16:32:34 -04:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
2017-07-12 17:51:46 -04:00
|
|
|
"testing"
|
2017-05-23 16:32:34 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/api/types/network"
|
2017-07-12 18:26:09 -04:00
|
|
|
"github.com/docker/docker/integration/util/request"
|
2017-08-23 17:35:09 -04:00
|
|
|
"github.com/docker/docker/internal/testutil"
|
2017-05-23 16:32:34 -04:00
|
|
|
)
|
|
|
|
|
2017-07-12 18:26:09 -04:00
|
|
|
func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
|
2017-05-23 16:32:34 -04:00
|
|
|
defer setupTest(t)()
|
2017-07-12 18:26:09 -04:00
|
|
|
client := request.NewAPIClient(t)
|
2017-05-23 16:32:34 -04:00
|
|
|
|
|
|
|
testCases := []struct {
|
2017-07-12 18:26:09 -04:00
|
|
|
doc string
|
2017-05-23 16:32:34 -04:00
|
|
|
image string
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
2017-07-12 18:26:09 -04:00
|
|
|
doc: "image and tag",
|
2017-05-23 16:32:34 -04:00
|
|
|
image: "test456:v1",
|
|
|
|
expectedError: "No such image: test456:v1",
|
|
|
|
},
|
|
|
|
{
|
2017-07-12 18:26:09 -04:00
|
|
|
doc: "image no tag",
|
2017-05-23 16:32:34 -04:00
|
|
|
image: "test456",
|
|
|
|
expectedError: "No such image: test456",
|
|
|
|
},
|
|
|
|
{
|
2017-07-12 18:26:09 -04:00
|
|
|
doc: "digest",
|
2017-05-23 16:32:34 -04:00
|
|
|
image: "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
|
|
|
|
expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-07-12 18:26:09 -04:00
|
|
|
for _, tc := range testCases {
|
2017-05-23 16:32:34 -04:00
|
|
|
tc := tc
|
2017-07-12 18:26:09 -04:00
|
|
|
t.Run(tc.doc, func(t *testing.T) {
|
2017-05-23 16:32:34 -04:00
|
|
|
t.Parallel()
|
2017-07-12 18:26:09 -04:00
|
|
|
_, err := client.ContainerCreate(context.Background(),
|
|
|
|
&container.Config{Image: tc.image},
|
2017-05-23 16:32:34 -04:00
|
|
|
&container.HostConfig{},
|
|
|
|
&network.NetworkingConfig{},
|
|
|
|
"foo",
|
|
|
|
)
|
2017-07-12 18:26:09 -04:00
|
|
|
testutil.ErrorContains(t, err, tc.expectedError)
|
2017-05-23 16:32:34 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 18:26:09 -04:00
|
|
|
func TestCreateWithInvalidEnv(t *testing.T) {
|
2017-05-23 16:32:34 -04:00
|
|
|
defer setupTest(t)()
|
2017-07-12 18:26:09 -04:00
|
|
|
client := request.NewAPIClient(t)
|
2017-05-23 16:32:34 -04:00
|
|
|
|
|
|
|
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()
|
2017-07-12 18:26:09 -04:00
|
|
|
_, err := client.ContainerCreate(context.Background(),
|
2017-05-23 16:32:34 -04:00
|
|
|
&container.Config{
|
|
|
|
Image: "busybox",
|
|
|
|
Env: []string{tc.env},
|
|
|
|
},
|
|
|
|
&container.HostConfig{},
|
|
|
|
&network.NetworkingConfig{},
|
|
|
|
"foo",
|
|
|
|
)
|
2017-07-12 18:26:09 -04:00
|
|
|
testutil.ErrorContains(t, err, tc.expectedError)
|
2017-05-23 16:32:34 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|