github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/integration/container/create_test.go (about)

     1  package container // import "github.com/docker/docker/integration/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/internal/request"
    11  	"github.com/docker/docker/internal/testutil"
    12  	"github.com/gotestyourself/gotestyourself/skip"
    13  )
    14  
    15  func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
    16  	defer setupTest(t)()
    17  	client := request.NewAPIClient(t)
    18  
    19  	testCases := []struct {
    20  		doc           string
    21  		image         string
    22  		expectedError string
    23  	}{
    24  		{
    25  			doc:           "image and tag",
    26  			image:         "test456:v1",
    27  			expectedError: "No such image: test456:v1",
    28  		},
    29  		{
    30  			doc:           "image no tag",
    31  			image:         "test456",
    32  			expectedError: "No such image: test456",
    33  		},
    34  		{
    35  			doc:           "digest",
    36  			image:         "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
    37  			expectedError: "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
    38  		},
    39  	}
    40  
    41  	for _, tc := range testCases {
    42  		tc := tc
    43  		t.Run(tc.doc, func(t *testing.T) {
    44  			t.Parallel()
    45  			_, err := client.ContainerCreate(context.Background(),
    46  				&container.Config{Image: tc.image},
    47  				&container.HostConfig{},
    48  				&network.NetworkingConfig{},
    49  				"",
    50  			)
    51  			testutil.ErrorContains(t, err, tc.expectedError)
    52  		})
    53  	}
    54  }
    55  
    56  func TestCreateWithInvalidEnv(t *testing.T) {
    57  	defer setupTest(t)()
    58  	client := request.NewAPIClient(t)
    59  
    60  	testCases := []struct {
    61  		env           string
    62  		expectedError string
    63  	}{
    64  		{
    65  			env:           "",
    66  			expectedError: "invalid environment variable:",
    67  		},
    68  		{
    69  			env:           "=",
    70  			expectedError: "invalid environment variable: =",
    71  		},
    72  		{
    73  			env:           "=foo",
    74  			expectedError: "invalid environment variable: =foo",
    75  		},
    76  	}
    77  
    78  	for index, tc := range testCases {
    79  		tc := tc
    80  		t.Run(strconv.Itoa(index), func(t *testing.T) {
    81  			t.Parallel()
    82  			_, err := client.ContainerCreate(context.Background(),
    83  				&container.Config{
    84  					Image: "busybox",
    85  					Env:   []string{tc.env},
    86  				},
    87  				&container.HostConfig{},
    88  				&network.NetworkingConfig{},
    89  				"",
    90  			)
    91  			testutil.ErrorContains(t, err, tc.expectedError)
    92  		})
    93  	}
    94  }
    95  
    96  // Test case for #30166 (target was not validated)
    97  func TestCreateTmpfsMountsTarget(t *testing.T) {
    98  	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
    99  
   100  	defer setupTest(t)()
   101  	client := request.NewAPIClient(t)
   102  
   103  	testCases := []struct {
   104  		target        string
   105  		expectedError string
   106  	}{
   107  		{
   108  			target:        ".",
   109  			expectedError: "mount path must be absolute",
   110  		},
   111  		{
   112  			target:        "foo",
   113  			expectedError: "mount path must be absolute",
   114  		},
   115  		{
   116  			target:        "/",
   117  			expectedError: "destination can't be '/'",
   118  		},
   119  		{
   120  			target:        "//",
   121  			expectedError: "destination can't be '/'",
   122  		},
   123  	}
   124  
   125  	for _, tc := range testCases {
   126  		_, err := client.ContainerCreate(context.Background(),
   127  			&container.Config{
   128  				Image: "busybox",
   129  			},
   130  			&container.HostConfig{
   131  				Tmpfs: map[string]string{tc.target: ""},
   132  			},
   133  			&network.NetworkingConfig{},
   134  			"",
   135  		)
   136  		testutil.ErrorContains(t, err, tc.expectedError)
   137  	}
   138  }