|
|
@@ -26,6 +26,7 @@ import (
|
|
|
"os"
|
|
|
"os/user"
|
|
|
"testing"
|
|
|
+ // "fmt"
|
|
|
)
|
|
|
|
|
|
var client, clientKeyPair, clientEcs, clientRoleArn, clientSts *Client
|
|
|
@@ -88,7 +89,7 @@ func getConfigFromEnv() *TestConfig {
|
|
|
StsAk: os.Getenv("STS_AK"),
|
|
|
StsSecret: os.Getenv("STS_SECRET"),
|
|
|
}
|
|
|
- if config.AccessKeyId == "" || os.Getenv("ENV_TYPE") != "CI" {
|
|
|
+ if config.AccessKeyId == "" {
|
|
|
return nil
|
|
|
} else {
|
|
|
return config
|
|
|
@@ -157,154 +158,166 @@ func TestNewClientWithAccessKey(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRoaGet(t *testing.T) {
|
|
|
- request := getFtTestRoaRequest()
|
|
|
+ request := &requests.RoaRequest{}
|
|
|
+ request.InitWithApiInfo("Ros", "2015-09-01", "", "/regions", "", "")
|
|
|
+ request.Domain = "ros.aliyuncs.com"
|
|
|
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRoaPostForm(t *testing.T) {
|
|
|
- request := getFtTestRoaRequest()
|
|
|
- request.Method = requests.POST
|
|
|
- request.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
+ request.QueryParams["key"] = "value"
|
|
|
+ request.QueryParams["QueryParam"] = "http://domain/?key=value&key2=value2"
|
|
|
|
|
|
response := &responses.BaseResponse{}
|
|
|
err := client.DoAction(request, response)
|
|
|
assert.Nil(t, err)
|
|
|
assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
- assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRoaPostStream(t *testing.T) {
|
|
|
- request := getFtTestRoaRequest()
|
|
|
- request.Method = requests.POST
|
|
|
- request.Content = []byte("TestContent")
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
- assert.Equal(t, "TestContent", responseBean.Body)
|
|
|
-}
|
|
|
-
|
|
|
-func TestRoaPostJson(t *testing.T) {
|
|
|
- request := getFtTestRoaRequest()
|
|
|
- request.Method = requests.POST
|
|
|
- dataMap := map[string]string{"key": "value"}
|
|
|
- data, err := json.Marshal(dataMap)
|
|
|
- assert.Nil(t, err)
|
|
|
- request.Content = data
|
|
|
- request.SetContentType(requests.Json)
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err = client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
- assert.Equal(t, requests.Json, responseBean.Headers["Content-Type"])
|
|
|
- assert.Equal(t, string(data), responseBean.Body)
|
|
|
-}
|
|
|
-
|
|
|
-func TestRpcGet(t *testing.T) {
|
|
|
- request := getFtTestRpcRequest()
|
|
|
- request.Method = requests.GET
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRpcGetForHttps(t *testing.T) {
|
|
|
- request := getFtTestRpcRequest()
|
|
|
- request.Method = requests.GET
|
|
|
- request.Scheme = requests.HTTPS
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRoaGetForHttps(t *testing.T) {
|
|
|
- request := getFtTestRoaRequest()
|
|
|
- request.Scheme = requests.HTTPS
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
+ var responseBean struct{
|
|
|
+ Regions[] struct{
|
|
|
+ LocalName string;
|
|
|
+ RegionId string;
|
|
|
+ };
|
|
|
+ }
|
|
|
json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
+ assert.NotNil(t, responseBean.Regions)
|
|
|
}
|
|
|
|
|
|
-func TestRpcPost(t *testing.T) {
|
|
|
- request := getFtTestRpcRequest()
|
|
|
- request.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
-}
|
|
|
+// func TestRoaPostForm(t *testing.T) {
|
|
|
+// request := &requests.RoaRequest{}
|
|
|
+// request.InitWithApiInfo("Ros", "2015-09-01", "", "/regions", "", "")
|
|
|
+// request.Domain = "ros.aliyuncs.com"
|
|
|
+
|
|
|
+// request.Headers["Header-Param"] = "HeaderParamValue"
|
|
|
+// request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
+// request.Method = requests.POST
|
|
|
+// request.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
+// assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRoaPostStream(t *testing.T) {
|
|
|
+// request := getFtTestRoaRequest()
|
|
|
+// request.Method = requests.POST
|
|
|
+// request.Content = []byte("TestContent")
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
+// assert.Equal(t, "TestContent", responseBean.Body)
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRoaPostJson(t *testing.T) {
|
|
|
+// request := getFtTestRoaRequest()
|
|
|
+// request.Method = requests.POST
|
|
|
+// dataMap := map[string]string{"key": "value"}
|
|
|
+// data, err := json.Marshal(dataMap)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// request.Content = data
|
|
|
+// request.SetContentType(requests.Json)
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err = client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
+// assert.Equal(t, requests.Json, responseBean.Headers["Content-Type"])
|
|
|
+// assert.Equal(t, string(data), responseBean.Body)
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRpcGet(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequest()
|
|
|
+// request.Method = requests.GET
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRpcGetForHttps(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequest()
|
|
|
+// request.Method = requests.GET
|
|
|
+// request.Scheme = requests.HTTPS
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRoaGetForHttps(t *testing.T) {
|
|
|
+// request := getFtTestRoaRequest()
|
|
|
+// request.Scheme = requests.HTTPS
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "HeaderParamValue", responseBean.Headers["Header-Param"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRpcPost(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequest()
|
|
|
+// request.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
+// }
|
|
|
|
|
|
func getFtTestRoaRequest() (request *requests.RoaRequest) {
|
|
|
request = &requests.RoaRequest{}
|
|
|
- request.InitWithApiInfo("Ft", "2016-01-02", "TestRoaApi", "/web/cloudapi", "", "")
|
|
|
- request.Domain = "ft.aliyuncs.com"
|
|
|
+ request.InitWithApiInfo("Ros", "2015-09-01", "", "/regions", "", "")
|
|
|
+ request.Domain = "ros.aliyuncs.com"
|
|
|
|
|
|
request.Headers["Header-Param"] = "HeaderParamValue"
|
|
|
request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
@@ -312,262 +325,262 @@ func getFtTestRoaRequest() (request *requests.RoaRequest) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func getFtTestRpcRequest() (request *requests.RpcRequest) {
|
|
|
- request = &requests.RpcRequest{}
|
|
|
- request.InitWithApiInfo("Ft", "2016-01-01", "TestRpcApi", "", "")
|
|
|
- request.Domain = "ft.aliyuncs.com"
|
|
|
- request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func getFtTestRpcRequestForEndpointLocation() (request *requests.RpcRequest) {
|
|
|
- request = &requests.RpcRequest{}
|
|
|
- request.InitWithApiInfo("Ft", "2016-01-01", "TestRpcApi", "ft", "openAPI")
|
|
|
- request.RegionId = "ft-cn-hangzhou"
|
|
|
- request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
- request.Domain = "ft.aliyuncs.com"
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func getFtTestRpcRequestForEndpointXml() (request *requests.RpcRequest) {
|
|
|
- request = &requests.RpcRequest{}
|
|
|
- request.InitWithApiInfo("Ft", "2016-01-01", "TestRpcApi", "", "")
|
|
|
- request.RegionId = "cn-hangzhou"
|
|
|
- request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
- request.Domain = "ft.aliyuncs.com"
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func TestCommonRpcRequest(t *testing.T) {
|
|
|
- rpcRequest := requests.NewCommonRequest()
|
|
|
- rpcRequest.Product = "Ft"
|
|
|
- rpcRequest.Version = "2016-01-01"
|
|
|
- rpcRequest.Domain = "ft.aliyuncs.com"
|
|
|
- rpcRequest.ApiName = "TestRpcApi"
|
|
|
- rpcRequest.Method = "POST"
|
|
|
-
|
|
|
- rpcRequest.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
- rpcRequest.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
-
|
|
|
- response, err := client.ProcessCommonRequest(rpcRequest)
|
|
|
-
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestCommonRoaRequest(t *testing.T) {
|
|
|
- roaRequest := requests.NewCommonRequest()
|
|
|
- roaRequest.Product = "Ft"
|
|
|
- roaRequest.Version = "2016-01-02"
|
|
|
- roaRequest.PathPattern = "/web/cloudapi"
|
|
|
- roaRequest.Domain = "ft.aliyuncs.com"
|
|
|
- roaRequest.Method = "POST"
|
|
|
-
|
|
|
- roaRequest.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
- roaRequest.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
-
|
|
|
- response, err := client.ProcessCommonRequest(roaRequest)
|
|
|
-
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
- assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRpcGetForEndpointXml(t *testing.T) {
|
|
|
- request := getFtTestRpcRequestForEndpointXml()
|
|
|
- request.Method = requests.GET
|
|
|
- request.RegionId = "cn-shanghai"
|
|
|
+// func getFtTestRpcRequest() (request *requests.RpcRequest) {
|
|
|
+// request = &requests.RpcRequest{}
|
|
|
+// request.InitWithApiInfo("Ft", "2016-01-01", "TestRpcApi", "", "")
|
|
|
+// request.Domain = "ft.aliyuncs.com"
|
|
|
+// request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
+// return
|
|
|
+// }
|
|
|
+
|
|
|
+// func getFtTestRpcRequestForEndpointLocation() (request *requests.RpcRequest) {
|
|
|
+// request = &requests.RpcRequest{}
|
|
|
+// request.InitWithApiInfo("Ft", "2016-01-01", "TestRpcApi", "ft", "openAPI")
|
|
|
+// request.RegionId = "ft-cn-hangzhou"
|
|
|
+// request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
+// request.Domain = "ft.aliyuncs.com"
|
|
|
+// return
|
|
|
+// }
|
|
|
+
|
|
|
+// func getFtTestRpcRequestForEndpointXml() (request *requests.RpcRequest) {
|
|
|
+// request = &requests.RpcRequest{}
|
|
|
+// request.InitWithApiInfo("Ft", "2016-01-01", "TestRpcApi", "", "")
|
|
|
+// request.RegionId = "cn-hangzhou"
|
|
|
+// request.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
+// request.Domain = "ft.aliyuncs.com"
|
|
|
+// return
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestCommonRpcRequest(t *testing.T) {
|
|
|
+// rpcRequest := requests.NewCommonRequest()
|
|
|
+// rpcRequest.Product = "Ft"
|
|
|
+// rpcRequest.Version = "2016-01-01"
|
|
|
+// rpcRequest.Domain = "ft.aliyuncs.com"
|
|
|
+// rpcRequest.ApiName = "TestRpcApi"
|
|
|
+// rpcRequest.Method = "POST"
|
|
|
+
|
|
|
+// rpcRequest.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
+// rpcRequest.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
+
|
|
|
+// response, err := client.ProcessCommonRequest(rpcRequest)
|
|
|
+
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestCommonRoaRequest(t *testing.T) {
|
|
|
+// roaRequest := requests.NewCommonRequest()
|
|
|
+// roaRequest.Product = "Ft"
|
|
|
+// roaRequest.Version = "2016-01-02"
|
|
|
+// roaRequest.PathPattern = "/web/cloudapi"
|
|
|
+// roaRequest.Domain = "ft.aliyuncs.com"
|
|
|
+// roaRequest.Method = "POST"
|
|
|
+
|
|
|
+// roaRequest.QueryParams["QueryParam"] = "QueryParamValue"
|
|
|
+// roaRequest.FormParams["BodyParam"] = "BodyParamValue"
|
|
|
+
|
|
|
+// response, err := client.ProcessCommonRequest(roaRequest)
|
|
|
+
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// assert.Equal(t, "BodyParamValue", responseBean.Params["BodyParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRpcGetForEndpointXml(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequestForEndpointXml()
|
|
|
+// request.Method = requests.GET
|
|
|
+// request.RegionId = "cn-shanghai"
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRpcGetForLocation(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequestForEndpointLocation()
|
|
|
+// request.Method = requests.GET
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRpcGetForLocationCache(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequestForEndpointLocation()
|
|
|
+// request.Method = requests.GET
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := client.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
+// request2 := getFtTestRpcRequestForEndpointLocation()
|
|
|
+// request2.Method = requests.GET
|
|
|
+// err = client.DoAction(request2, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
|
|
|
-func TestRpcGetForLocation(t *testing.T) {
|
|
|
- request := getFtTestRpcRequestForEndpointLocation()
|
|
|
- request.Method = requests.GET
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+// func TestRpcGetForKeyPair(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequest()
|
|
|
+// request.Method = requests.GET
|
|
|
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRpcGetForLocationCache(t *testing.T) {
|
|
|
- request := getFtTestRpcRequestForEndpointLocation()
|
|
|
- request.Method = requests.GET
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := client.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-
|
|
|
- request2 := getFtTestRpcRequestForEndpointLocation()
|
|
|
- request2.Method = requests.GET
|
|
|
- err = client.DoAction(request2, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRpcGetForKeyPair(t *testing.T) {
|
|
|
- request := getFtTestRpcRequest()
|
|
|
- request.Method = requests.GET
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := clientKeyPair.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-/*func TestRpcGetForEcs(t *testing.T) {
|
|
|
- //测试接口,想测试的时候,要替换掉singer_ecs_instance中对应的变量,并且还要提供一个mock服务
|
|
|
- //requestUrl := "http://localhost:3500/latest/meta-data/ram/security-credentials/roleNameTest.json"
|
|
|
- request := getFtTestRpcRequest()
|
|
|
- request.Method = requests.GET
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := clientEcs.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-
|
|
|
- err = clientEcs.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}*/
|
|
|
-
|
|
|
-func TestRpcGetForRoleArn(t *testing.T) {
|
|
|
- request := getFtTestRpcRequest()
|
|
|
- request.Method = requests.GET
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := clientRoleArn.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-
|
|
|
- err = clientRoleArn.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-func TestRoaGetForRoleArn(t *testing.T) {
|
|
|
- request := getFtTestRoaRequest()
|
|
|
- request.Method = requests.GET
|
|
|
-
|
|
|
- response := &responses.BaseResponse{}
|
|
|
- err := clientRoleArn.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- var responseBean MockResponse
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-
|
|
|
- err = clientRoleArn.DoAction(request, response)
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-
|
|
|
- json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-
|
|
|
- assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-}
|
|
|
-
|
|
|
-//测试Sts的时候要先获取一套stsToken和ak,由于有时效性,所以先把代码注释掉,测试的时候先获取stsToken完成后再调用
|
|
|
-//func TestRpcGetForSts(t *testing.T) {
|
|
|
-// request := getFtTestRpcRequest()
|
|
|
-// request.Method = requests.GET
|
|
|
-//
|
|
|
-// response := &responses.BaseResponse{}
|
|
|
-// err := clientSts.DoAction(request, response)
|
|
|
-// assert.Nil(t, err)
|
|
|
-// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
-// assert.NotNil(t, response.GetHttpContentString())
|
|
|
-//
|
|
|
-// var responseBean MockResponse
|
|
|
-// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
-//
|
|
|
-// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
-//}
|
|
|
-
|
|
|
-func TestCommonRoaRequestForAcceptXML(t *testing.T) {
|
|
|
- roaRequest := requests.NewCommonRequest()
|
|
|
- roaRequest.Product = "Acs"
|
|
|
- roaRequest.Version = "2015-01-01"
|
|
|
- roaRequest.ApiName = "GetGlobal"
|
|
|
- roaRequest.PathPattern = "/"
|
|
|
- roaRequest.Domain = "acs.aliyuncs.com"
|
|
|
- roaRequest.AcceptFormat = "XML"
|
|
|
-
|
|
|
- response, err := client.ProcessCommonRequest(roaRequest)
|
|
|
-
|
|
|
- assert.Nil(t, err)
|
|
|
- assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- assert.NotNil(t, response.GetHttpContentString())
|
|
|
-}
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := clientKeyPair.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// /*func TestRpcGetForEcs(t *testing.T) {
|
|
|
+// //测试接口,想测试的时候,要替换掉singer_ecs_instance中对应的变量,并且还要提供一个mock服务
|
|
|
+// //requestUrl := "http://localhost:3500/latest/meta-data/ram/security-credentials/roleNameTest.json"
|
|
|
+// request := getFtTestRpcRequest()
|
|
|
+// request.Method = requests.GET
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := clientEcs.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+
|
|
|
+// err = clientEcs.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }*/
|
|
|
+
|
|
|
+// func TestRpcGetForRoleArn(t *testing.T) {
|
|
|
+// request := getFtTestRpcRequest()
|
|
|
+// request.Method = requests.GET
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := clientRoleArn.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+
|
|
|
+// err = clientRoleArn.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// func TestRoaGetForRoleArn(t *testing.T) {
|
|
|
+// request := getFtTestRoaRequest()
|
|
|
+// request.Method = requests.GET
|
|
|
+
|
|
|
+// response := &responses.BaseResponse{}
|
|
|
+// err := clientRoleArn.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// var responseBean MockResponse
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+
|
|
|
+// err = clientRoleArn.DoAction(request, response)
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+
|
|
|
+// json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+
|
|
|
+// assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// }
|
|
|
+
|
|
|
+// //测试Sts的时候要先获取一套stsToken和ak,由于有时效性,所以先把代码注释掉,测试的时候先获取stsToken完成后再调用
|
|
|
+// //func TestRpcGetForSts(t *testing.T) {
|
|
|
+// // request := getFtTestRpcRequest()
|
|
|
+// // request.Method = requests.GET
|
|
|
+// //
|
|
|
+// // response := &responses.BaseResponse{}
|
|
|
+// // err := clientSts.DoAction(request, response)
|
|
|
+// // assert.Nil(t, err)
|
|
|
+// // assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// // assert.NotNil(t, response.GetHttpContentString())
|
|
|
+// //
|
|
|
+// // var responseBean MockResponse
|
|
|
+// // json.Unmarshal([]byte(response.GetHttpContentString()), &responseBean)
|
|
|
+// //
|
|
|
+// // assert.Equal(t, "QueryParamValue", responseBean.Params["QueryParam"])
|
|
|
+// //}
|
|
|
+
|
|
|
+// func TestCommonRoaRequestForAcceptXML(t *testing.T) {
|
|
|
+// roaRequest := requests.NewCommonRequest()
|
|
|
+// roaRequest.Product = "Acs"
|
|
|
+// roaRequest.Version = "2015-01-01"
|
|
|
+// roaRequest.ApiName = "GetGlobal"
|
|
|
+// roaRequest.PathPattern = "/"
|
|
|
+// roaRequest.Domain = "acs.aliyuncs.com"
|
|
|
+// roaRequest.AcceptFormat = "XML"
|
|
|
+
|
|
|
+// response, err := client.ProcessCommonRequest(roaRequest)
|
|
|
+
|
|
|
+// assert.Nil(t, err)
|
|
|
+// assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
+// assert.NotNil(t, response.GetHttpContentString())
|
|
|
+// }
|