forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_version_parameter_test.go
60 lines (44 loc) · 1.47 KB
/
api_version_parameter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bytes"
"encoding/json"
"net/http"
"net/url"
"github.com/alibaba/pouch/client"
"github.com/alibaba/pouch/test/environment"
"github.com/go-check/check"
)
// APIVersionSuite is the test suit for all about pouch API Version.
type APIVersionSuite struct{}
func init() {
check.Suite(&APIVersionSuite{})
}
// SetupTest does common setup in the beginning of each test.
func (suite *APIVersionSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
}
// TestNoVersionParamsInURL test api url not contains version info.
// Pouch api url support with or without version info.
func (suite *APIVersionSuite) TestNoVersionParamsInURL(c *check.C) {
cname := "TestCreateURLNoVersionInfo"
commonAPIClient, err := client.NewAPIClient(environment.PouchdAddress, environment.TLSConfig)
c.Assert(err, check.IsNil)
apiClient := commonAPIClient.(*client.APIClient)
// set version to "", let request url not contains version info.
apiClient.UpdateClientVersion("")
q := url.Values{}
q.Add("name", cname)
obj := map[string]interface{}{
"Image": busyboxImage,
"HostConfig": map[string]interface{}{},
}
b, err := json.Marshal(obj)
c.Assert(err, check.IsNil)
body := bytes.NewReader(b)
fullPath := apiClient.BaseURL() + apiClient.GetAPIPath("/containers/create", q)
req, err := http.NewRequest("POST", fullPath, body)
c.Assert(err, check.IsNil)
resp, err := apiClient.HTTPCli.Do(req)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 201)
}