github.com/afein/docker@v1.8.2/integration-cli/docker_api_test.go (about) 1 package main 2 3 import ( 4 "net/http" 5 "net/http/httputil" 6 "strconv" 7 "strings" 8 "time" 9 10 "github.com/docker/docker/api" 11 "github.com/go-check/check" 12 ) 13 14 func (s *DockerSuite) TestApiOptionsRoute(c *check.C) { 15 status, _, err := sockRequest("OPTIONS", "/", nil) 16 c.Assert(err, check.IsNil) 17 c.Assert(status, check.Equals, http.StatusOK) 18 } 19 20 func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) { 21 res, body, err := sockRequestRaw("GET", "/version", nil, "") 22 c.Assert(err, check.IsNil) 23 c.Assert(res.StatusCode, check.Equals, http.StatusOK) 24 body.Close() 25 // TODO: @runcom incomplete tests, why old integration tests had this headers 26 // and here none of the headers below are in the response? 27 //c.Log(res.Header) 28 //c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*") 29 //c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth") 30 } 31 32 func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) { 33 conn, err := sockConn(time.Duration(10 * time.Second)) 34 c.Assert(err, check.IsNil) 35 36 client := httputil.NewClientConn(conn, nil) 37 defer client.Close() 38 39 req, err := http.NewRequest("GET", "/v999.0/version", nil) 40 c.Assert(err, check.IsNil) 41 req.Header.Set("User-Agent", "Docker-Client/999.0 (os)") 42 43 res, err := client.Do(req) 44 c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest) 45 } 46 47 func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) { 48 v := strings.Split(string(api.Version), ".") 49 vMinInt, err := strconv.Atoi(v[1]) 50 c.Assert(err, check.IsNil) 51 vMinInt++ 52 v[1] = strconv.Itoa(vMinInt) 53 version := strings.Join(v, ".") 54 55 status, body, err := sockRequest("GET", "/v"+version+"/version", nil) 56 c.Assert(err, check.IsNil) 57 c.Assert(status, check.Equals, http.StatusBadRequest) 58 c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body 59 } 60 61 func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) { 62 v := strings.Split(string(api.MinVersion), ".") 63 vMinInt, err := strconv.Atoi(v[1]) 64 c.Assert(err, check.IsNil) 65 vMinInt-- 66 v[1] = strconv.Itoa(vMinInt) 67 version := strings.Join(v, ".") 68 69 status, body, err := sockRequest("GET", "/v"+version+"/version", nil) 70 c.Assert(err, check.IsNil) 71 c.Assert(status, check.Equals, http.StatusBadRequest) 72 c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body 73 }