Prechádzať zdrojové kódy

add simple test

Signed-off-by: 高汝彤 <rutong.grt@alibaba-inc.com>
高汝彤 8 rokov pred
rodič
commit
d7b1f219bb
2 zmenil súbory, kde vykonal 52 pridanie a 0 odobranie
  1. 1 0
      .travis.yml
  2. 51 0
      sdk/test/simple_test.go

+ 1 - 0
.travis.yml

@@ -23,3 +23,4 @@ script:
   - go vet ./services/...
   - go build ./sdk
   - go build ./services/...
+  - go test alibaba-cloud-sdk-go/sdk/test/simple_test.go

+ 51 - 0
sdk/test/simple_test.go

@@ -0,0 +1,51 @@
+package test
+
+import (
+	"testing"
+	"github.com/stretchr/testify/assert"
+	"os"
+	"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
+	"fmt"
+)
+
+type TestConfig struct {
+	AccessKeyId     string
+	AccessKeySecret string
+	PublicKeyId     string
+	PrivateKey      string
+	RoleArn         string
+	ChildAK         string
+	ChildSecret     string
+}
+
+func getConfigFromEnv() *TestConfig {
+	config := &TestConfig{
+		AccessKeyId:     os.Getenv("ACCESS_KEY_ID"),
+		AccessKeySecret: os.Getenv("ACCESS_KEY_SECRET"),
+		PublicKeyId:     os.Getenv("PUBLIC_KEY_ID"),
+		PrivateKey:      os.Getenv("PRIVATE_KEY"),
+		RoleArn:         os.Getenv("ROLE_ARN"),
+		ChildAK:         os.Getenv("CHILD_AK"),
+		ChildSecret:     os.Getenv("CHILD_SECRET"),
+	}
+	if config.AccessKeyId == "" {
+		return nil
+	} else {
+		return config
+	}
+}
+
+func TestSimple(t *testing.T){
+	config := getConfigFromEnv()
+	ecsClient, err := ecs.NewClientWithAccessKey("cn-hangzhou", config.AccessKeyId, config.AccessKeySecret)
+	if err != nil {
+		panic(err)
+	}
+	request := ecs.CreateDescribeRegionsRequest()
+	response, err := ecsClient.DescribeRegions(request)
+	if err != nil {
+		panic(err)
+	}
+	assert.Equal(t, 200, response.GetHttpStatus())
+	fmt.Print(response.GetHttpContentString())
+}