|
|
@@ -2,9 +2,10 @@ package integration
|
|
|
|
|
|
import (
|
|
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
|
|
|
+ "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
|
|
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
|
|
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
|
|
-
|
|
|
+ "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
"os"
|
|
|
@@ -27,7 +28,6 @@ func Test_DescribeRegionsWithParameterError(t *testing.T) {
|
|
|
assert.Equal(t, "The specified parameter \"Action or Version\" is not valid.", realerr.Message())
|
|
|
}
|
|
|
|
|
|
-
|
|
|
func Test_DescribeRegionsWithUnreachableError(t *testing.T) {
|
|
|
request := requests.NewCommonRequest()
|
|
|
request.Version = "2014-05-26"
|
|
|
@@ -39,22 +39,54 @@ func Test_DescribeRegionsWithUnreachableError(t *testing.T) {
|
|
|
assert.Nil(t, err)
|
|
|
response, err := client.ProcessCommonRequest(request)
|
|
|
assert.Equal(t, 0, response.GetHttpStatus())
|
|
|
- assert.True(t, strings.Contains(err.Error(), "www.ecs.ali.com"))
|
|
|
+ realerr := err.(errors.Error)
|
|
|
+ assert.True(t, strings.Contains(realerr.OriginError().Error(), "dial tcp: lookup www.ecs.ali.com: no such host"))
|
|
|
+}
|
|
|
+
|
|
|
+func Test_DescribeRegionsWithTimeout(t *testing.T) {
|
|
|
+ credentail := credentials.NewAccessKeyCredential(os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
|
|
|
+ config := &sdk.Config{
|
|
|
+ Timeout: 100,
|
|
|
+ }
|
|
|
+ request := ecs.CreateDescribeRegionsRequest()
|
|
|
+ request.Scheme = "https"
|
|
|
+ client, err := ecs.NewClientWithOptions("cn-hangzhou", config, credentail)
|
|
|
+ response, err := client.DescribeRegions(request)
|
|
|
+ assert.Equal(t, 0, response.GetHttpStatus())
|
|
|
+ assert.Contains(t, err.Error(), "https://ecs-cn-hangzhou.aliyuncs.com")
|
|
|
+ assert.Contains(t, err.Error(), "Client.Timeout exceeded while awaiting headers")
|
|
|
}
|
|
|
|
|
|
-//func Test_DescribeRegionsWithTimeout(t *testing.T) {
|
|
|
-// rolename, _, err := createRole(os.Getenv("USER_ID"))
|
|
|
-// credentail := credentials.NewEcsRamRoleCredential(rolename)
|
|
|
-// request := ecs.CreateDescribeRegionsRequest()
|
|
|
-// request.SetDomain("www.aliyun-hangzhou.com")
|
|
|
-// config := &sdk.Config{
|
|
|
-// Timeout: 1,
|
|
|
-// }
|
|
|
-// client, err := ecs.NewClientWithOptions("cn-hangzhou", config, credentail)
|
|
|
-// assert.Nil(t, err)
|
|
|
-// _, err = client.DescribeRegions(request)
|
|
|
-//}
|
|
|
+func Test_DescribeRegionsWithNilbody(t *testing.T) {
|
|
|
+ request := requests.NewCommonRequest()
|
|
|
+ request.Version = "2014-05-26"
|
|
|
+ request.Product = "Ecs"
|
|
|
+ request.ApiName = "DescribeRegions"
|
|
|
+ ts := mockServer(400, ``)
|
|
|
+ defer ts.Close()
|
|
|
+ domain := strings.Replace(ts.URL, "http://", "", 1)
|
|
|
+ request.Domain = domain
|
|
|
+ request.TransToAcsRequest()
|
|
|
+ client, err := sdk.NewClientWithAccessKey("cn-hangzhou", os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
|
|
|
+ assert.Nil(t, err)
|
|
|
+ response, err := client.ProcessCommonRequest(request)
|
|
|
+ assert.Equal(t, 400, response.GetHttpStatus())
|
|
|
+ assert.NotNil(t, err)
|
|
|
+}
|
|
|
|
|
|
-//func Test_DescribeRegionsWithTimeOutError(t *testing.T) {
|
|
|
-//
|
|
|
-//}
|
|
|
+func Test_DescribeRegionsWithFormatError(t *testing.T) {
|
|
|
+ request := requests.NewCommonRequest()
|
|
|
+ request.Version = "2014-05-26"
|
|
|
+ request.Product = "Ecs"
|
|
|
+ request.ApiName = "DescribeRegions"
|
|
|
+ ts := mockServer(400, `bad json`)
|
|
|
+ defer ts.Close()
|
|
|
+ domain := strings.Replace(ts.URL, "http://", "", 1)
|
|
|
+ request.Domain = domain
|
|
|
+ request.TransToAcsRequest()
|
|
|
+ client, err := sdk.NewClientWithAccessKey("cn-hangzhou", os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
|
|
|
+ assert.Nil(t, err)
|
|
|
+ response, err := client.ProcessCommonRequest(request)
|
|
|
+ assert.Equal(t, 400, response.GetHttpStatus())
|
|
|
+ assert.Contains(t, err.Error(), "bad json")
|
|
|
+}
|