github.com/jingleWang/moby@v1.13.1/integration-cli/docker_api_create_test.go (about)

     1  package main
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/docker/docker/pkg/integration/checker"
     7  	"github.com/go-check/check"
     8  )
     9  
    10  func (s *DockerSuite) TestAPICreateWithNotExistImage(c *check.C) {
    11  	name := "test"
    12  	config := map[string]interface{}{
    13  		"Image":   "test456:v1",
    14  		"Volumes": map[string]struct{}{"/tmp": {}},
    15  	}
    16  
    17  	status, body, err := sockRequest("POST", "/containers/create?name="+name, config)
    18  	c.Assert(err, check.IsNil)
    19  	c.Assert(status, check.Equals, http.StatusNotFound)
    20  	expected := "No such image: test456:v1"
    21  	c.Assert(getErrorMessage(c, body), checker.Contains, expected)
    22  
    23  	config2 := map[string]interface{}{
    24  		"Image":   "test456",
    25  		"Volumes": map[string]struct{}{"/tmp": {}},
    26  	}
    27  
    28  	status, body, err = sockRequest("POST", "/containers/create?name="+name, config2)
    29  	c.Assert(err, check.IsNil)
    30  	c.Assert(status, check.Equals, http.StatusNotFound)
    31  	expected = "No such image: test456:latest"
    32  	c.Assert(getErrorMessage(c, body), checker.Equals, expected)
    33  
    34  	config3 := map[string]interface{}{
    35  		"Image": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa",
    36  	}
    37  
    38  	status, body, err = sockRequest("POST", "/containers/create?name="+name, config3)
    39  	c.Assert(err, check.IsNil)
    40  	c.Assert(status, check.Equals, http.StatusNotFound)
    41  	expected = "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa"
    42  	c.Assert(getErrorMessage(c, body), checker.Equals, expected)
    43  
    44  }
    45  
    46  // Test for #25099
    47  func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) {
    48  	name := "test1"
    49  	config := map[string]interface{}{
    50  		"Image": "busybox",
    51  		"Env":   []string{"", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
    52  		"Cmd":   []string{"true"},
    53  	}
    54  
    55  	status, body, err := sockRequest("POST", "/containers/create?name="+name, config)
    56  	c.Assert(err, check.IsNil)
    57  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    58  	expected := "invalid environment variable:"
    59  	c.Assert(getErrorMessage(c, body), checker.Contains, expected)
    60  
    61  	name = "test2"
    62  	config = map[string]interface{}{
    63  		"Image": "busybox",
    64  		"Env":   []string{"=", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
    65  		"Cmd":   []string{"true"},
    66  	}
    67  	status, body, err = sockRequest("POST", "/containers/create?name="+name, config)
    68  	c.Assert(err, check.IsNil)
    69  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    70  	expected = "invalid environment variable: ="
    71  	c.Assert(getErrorMessage(c, body), checker.Contains, expected)
    72  
    73  	name = "test3"
    74  	config = map[string]interface{}{
    75  		"Image": "busybox",
    76  		"Env":   []string{"=foo", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
    77  		"Cmd":   []string{"true"},
    78  	}
    79  	status, body, err = sockRequest("POST", "/containers/create?name="+name, config)
    80  	c.Assert(err, check.IsNil)
    81  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    82  	expected = "invalid environment variable: =foo"
    83  	c.Assert(getErrorMessage(c, body), checker.Contains, expected)
    84  }