github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/integration/container/create_test.go (about) 1 package container 2 3 import ( 4 "context" 5 "strconv" 6 "testing" 7 8 "github.com/docker/docker/api/types/container" 9 "github.com/docker/docker/api/types/network" 10 "github.com/docker/docker/integration/util/request" 11 "github.com/docker/docker/internal/testutil" 12 ) 13 14 func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) { 15 defer setupTest(t)() 16 client := request.NewAPIClient(t) 17 18 testCases := []struct { 19 doc string 20 image string 21 expectedError string 22 }{ 23 { 24 doc: "image and tag", 25 image: "test456:v1", 26 expectedError: "No such image: test456:v1", 27 }, 28 { 29 doc: "image no tag", 30 image: "test456", 31 expectedError: "No such image: test456", 32 }, 33 { 34 doc: "digest", 35 image: "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", 36 expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", 37 }, 38 } 39 40 for _, tc := range testCases { 41 tc := tc 42 t.Run(tc.doc, func(t *testing.T) { 43 t.Parallel() 44 _, err := client.ContainerCreate(context.Background(), 45 &container.Config{Image: tc.image}, 46 &container.HostConfig{}, 47 &network.NetworkingConfig{}, 48 "foo", 49 ) 50 testutil.ErrorContains(t, err, tc.expectedError) 51 }) 52 } 53 } 54 55 func TestCreateWithInvalidEnv(t *testing.T) { 56 defer setupTest(t)() 57 client := request.NewAPIClient(t) 58 59 testCases := []struct { 60 env string 61 expectedError string 62 }{ 63 { 64 env: "", 65 expectedError: "invalid environment variable:", 66 }, 67 { 68 env: "=", 69 expectedError: "invalid environment variable: =", 70 }, 71 { 72 env: "=foo", 73 expectedError: "invalid environment variable: =foo", 74 }, 75 } 76 77 for index, tc := range testCases { 78 tc := tc 79 t.Run(strconv.Itoa(index), func(t *testing.T) { 80 t.Parallel() 81 _, err := client.ContainerCreate(context.Background(), 82 &container.Config{ 83 Image: "busybox", 84 Env: []string{tc.env}, 85 }, 86 &container.HostConfig{}, 87 &network.NetworkingConfig{}, 88 "foo", 89 ) 90 testutil.ErrorContains(t, err, tc.expectedError) 91 }) 92 } 93 }