Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create go.yml #562

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
runs-on: ubuntu-latest
environment: ci
strategy:
fail-fast: false
matrix:
go-version: [
#'1.10', '1.11', '1.12',
'1.13', '1.14',
# '1.15', '1.16', '1.17', '1.18', '1.19', '1.20'
]

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Test
env:
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}
REGION_ID: ${{ secrets.REGION_ID }}
USER_ID: ${{ secrets.USER_ID }}
PUBLIC_KEY_ID: ${{ secrets.PUBLIC_KEY_ID }}
RSA_FILE_AES_KEY: ${{ secrets.RSA_FILE_AES_KEY }}
CONCURRENT_ID: "${{ github.run_number }}-${{ strategy.job-index }}"
run: |
go test -race -coverprofile=coverage.txt -covermode=atomic ./sdk/...
test -z $ACCESS_KEY_ID -a -z $ACCESS_KEY_SECRET || go test -v -timeout 120s ./integration/...
4 changes: 1 addition & 3 deletions integration/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Test_DeleteClusterWithROArequestWithJSONWithDelete(t *testing.T) {
response, err := client.DeleteCluster(request)
assert.NotNil(t, err)
assert.Equal(t, 400, response.GetHttpStatus())
assert.Contains(t, err.Error(), "ErrorCheckAcl")
assert.Contains(t, err.Error(), "ErrorClusterNotFound")
}

func Test_CreateSecurityGroupWithRPCrequestWithJSONWithNestingparametersWithPOST(t *testing.T) {
Expand Down Expand Up @@ -97,7 +97,6 @@ func Test_ECS_DescribeSecurityGroupsWithRPCrequestWithJSONWithNestingparametersW
assert.Equal(t, 36, len(response.RequestId))
assert.True(t, flag)
flag = false

}

func Test_ECS_DeleteSecurityGroupWithRPCrequestWithJSONWithPOST(t *testing.T) {
Expand Down Expand Up @@ -173,7 +172,6 @@ func mockServer(status int, json string) (server *httptest.Server) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(status)
w.Write([]byte(json))
return
}))
return ts
}
Expand Down
85 changes: 43 additions & 42 deletions integration/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,39 @@ import (

var role_doc = `{
"Statement": [{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"RAM": [
"acs:ram::%s:root"
]
}
}],
"Version": "1"
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"RAM": [
"acs:ram::%s:root"
]
}
}],
"Version": "1"
}`

var (
travisValue = strings.Split(os.Getenv("TRAVIS_JOB_NUMBER"), ".")
username = "test-user" + travisValue[len(travisValue)-1]
rolename = "test-role" + travisValue[len(travisValue)-1]
rolearn = fmt.Sprintf("acs:ram::%s:role/%s", os.Getenv("USER_ID"), rolename)
username = "test-user-" + os.Getenv("CONCURRENT_ID")
rolename = "test-role-" + os.Getenv("CONCURRENT_ID")
rolearn = fmt.Sprintf("acs:ram::%s:role/%s", os.Getenv("USER_ID"), rolename)
)

func createRole(userid string) (string, string, error) {
func createRole(userid string) (name string, arn string, err error) {
listRequest := ram.CreateListRolesRequest()
listRequest.Scheme = "HTTPS"
client, err := ram.NewClientWithAccessKey(os.Getenv("REGION_ID"), os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
if err != nil {
return "", "", err
return
}
listResponse, err := client.ListRoles(listRequest)
if err != nil {
return "", "", err
return
}
for _, role := range listResponse.Roles.Role {
if strings.ToLower(role.RoleName) == rolename {
return role.RoleName, role.Arn, nil
name = role.RoleName
arn = role.Arn
return
}
}
createRequest := ram.CreateCreateRoleRequest()
Expand All @@ -51,35 +52,34 @@ func createRole(userid string) (string, string, error) {
createRequest.AssumeRolePolicyDocument = fmt.Sprintf(role_doc, userid)
res, err := client.CreateRole(createRequest)
if err != nil {
return "", "", err
return
}
return res.Role.RoleName, res.Role.Arn, nil
name = res.Role.RoleName
arn = res.Role.Arn
return
}

func createUser() error {
func createUser() (err error) {
listRequest := ram.CreateListUsersRequest()
listRequest.Scheme = "HTTPS"
client, err := ram.NewClientWithAccessKey(os.Getenv("REGION_ID"), os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
if err != nil {
return err
return
}
listResponse, err := client.ListUsers(listRequest)
if err != nil {
return err
return
}
for _, user := range listResponse.Users.User {
if user.UserName == username {
return nil
return
}
}
createRequest := ram.CreateCreateUserRequest()
createRequest.Scheme = "HTTPS"
createRequest.UserName = username
_, err = client.CreateUser(createRequest)
if err != nil {
return err
}
return nil
return
}

func createAttachPolicyToUser() error {
Expand Down Expand Up @@ -140,17 +140,17 @@ func createAttachPolicyToRole() error {
return nil
}

func createAccessKey() (string, string, error) {
func createAccessKey() (id string, secret string, err error) {
client, err := ram.NewClientWithAccessKey(os.Getenv("REGION_ID"), os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
if err != nil {
return "", "", err
return
}
listrequest := ram.CreateListAccessKeysRequest()
listrequest.UserName = username
listrequest.Scheme = "HTTPS"
listresponse, err := client.ListAccessKeys(listrequest)
if err != nil {
return "", "", err
return
}
if listresponse.AccessKeys.AccessKey != nil {
if len(listresponse.AccessKeys.AccessKey) >= 2 {
Expand All @@ -159,9 +159,9 @@ func createAccessKey() (string, string, error) {
deleterequest.UserAccessKeyId = accesskey.AccessKeyId
deleterequest.UserName = username
deleterequest.Scheme = "HTTPS"
_, err := client.DeleteAccessKey(deleterequest)
_, err = client.DeleteAccessKey(deleterequest)
if err != nil {
return "", "", err
return
}
}
}
Expand All @@ -170,21 +170,25 @@ func createAccessKey() (string, string, error) {
request.UserName = username
response, err := client.CreateAccessKey(request)
if err != nil {
return "", "", err
return
}

return response.AccessKey.AccessKeyId, response.AccessKey.AccessKeySecret, nil
id = response.AccessKey.AccessKeyId
secret = response.AccessKey.AccessKeySecret
return
}

func createAssumeRole() (*sts.AssumeRoleResponse, error) {
subaccesskeyid, subaccesskeysecret, err := createAccessKey()
func createAssumeRole() (response *sts.AssumeRoleResponse, err error) {
err = createUser()
if err != nil {
return nil, err
}
err = createUser()

subaccesskeyid, subaccesskeysecret, err := createAccessKey()
if err != nil {
return nil, err
}

_, _, err = createRole(os.Getenv("USER_ID"))
if err != nil {
return nil, err
Expand All @@ -201,9 +205,6 @@ func createAssumeRole() (*sts.AssumeRoleResponse, error) {
if err != nil {
return nil, err
}
response, err := client.AssumeRole(request)
if err != nil {
return nil, err
}
return response, nil
response, err = client.AssumeRole(request)
return
}
23 changes: 10 additions & 13 deletions integration/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Test_AddTagsWithCommonRequestWithError(t *testing.T) {
assert.Equal(t, "The input parameter \"ResourceType\" that is mandatory for processing this request is not supplied.", realerr.Message())
}

func Test_DescribeRegionsWithCommonRequestWithIncompleteSignature(t *testing.T) {
func SkipTest_DescribeRegionsWithCommonRequestWithIncompleteSignature(t *testing.T) {
request := requests.NewCommonRequest()
request.Version = "2014-05-26"
request.AcceptFormat = "json"
Expand All @@ -119,7 +119,7 @@ func Test_DescribeClustersWithCommonRequestWithROA(t *testing.T) {
assert.Nil(t, err)
request := requests.NewCommonRequest()
request.Method = "GET"
request.Domain = "cs.aliyuncs.com"
request.Domain = fmt.Sprintf("cs.%s.aliyuncs.com", os.Getenv("REGION_ID"))
request.Version = "2015-12-15"
request.PathPattern = "/clusters"
request.ApiName = "DescribeClusters"
Expand All @@ -136,14 +136,15 @@ func Test_DescribeClustersWithCommonRequestWithSignatureDostNotMatch(t *testing.
assert.Nil(t, err)
request := requests.NewCommonRequest()
request.Method = "GET"
request.Domain = "cs.aliyuncs.com"
request.Domain = fmt.Sprintf("cs.%s.aliyuncs.com", os.Getenv("REGION_ID"))
request.Version = "2015-12-15"
request.PathPattern = "/clusters/[ClusterId]"
request.QueryParams["RegionId"] = os.Getenv("REGION_ID")
request.TransToAcsRequest()
_, err = client.ProcessCommonRequest(request)
assert.NotNil(t, err)
real, _ := err.(*errors.ServerError)
real, ok := err.(*errors.ServerError)
assert.True(t, ok)
assert.Contains(t, real.Recommend(), "InvalidAccessKeySecret: Please check you AccessKeySecret")
assert.Equal(t, real.ErrorCode(), "SignatureDoesNotMatch")
}
Expand All @@ -156,7 +157,7 @@ func Test_DescribeClustersWithCommonRequestWithROAWithSTStoken(t *testing.T) {
assert.Nil(t, err)
request := requests.NewCommonRequest()
request.Method = "GET"
request.Domain = "cs.aliyuncs.com"
request.Domain = fmt.Sprintf("cs.%s.aliyuncs.com", os.Getenv("REGION_ID"))
request.Version = "2015-12-15"
request.PathPattern = "/clusters/[ClusterId]"
request.QueryParams["RegionId"] = os.Getenv("REGION_ID")
Expand All @@ -168,7 +169,7 @@ func Test_DescribeClustersWithCommonRequestWithROAWithSTStoken(t *testing.T) {
client.SetLogger("error", "Alibaba", f1, templete)
_, err = client.ProcessCommonRequest(request)
assert.NotNil(t, err)
assert.Contains(t, client.GetLoggerMsg(), `1.1, cs.aliyuncs.com`)
assert.Contains(t, client.GetLoggerMsg(), "1.1, "+"cs."+os.Getenv("REGION_ID")+".aliyuncs.com")
assert.Contains(t, err.Error(), "ErrorClusterNotFound")
}

Expand All @@ -177,7 +178,7 @@ func Test_DescribeClusterDetailWithCommonRequestWithROAWithHTTPS(t *testing.T) {
assert.Nil(t, err)
request := requests.NewCommonRequest()
request.Method = "GET"
request.Domain = "cs.aliyuncs.com"
request.Domain = fmt.Sprintf("cs.%s.aliyuncs.com", os.Getenv("REGION_ID"))
request.Version = "2015-12-15"
request.SetScheme("HTTPS")
request.PathPattern = "/clusters/[ClusterId]"
Expand All @@ -193,7 +194,7 @@ func Test_DescribeClusterDetailWithCommonRequestWithTimeout(t *testing.T) {
client, err := sdk.NewClientWithAccessKey(os.Getenv("REGION_ID"), os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))
assert.Nil(t, err)
request := requests.NewCommonRequest()
request.Domain = "cs.aliyuncs.com"
request.Domain = fmt.Sprintf("cs.%s.aliyuncs.com", os.Getenv("REGION_ID"))
request.Version = "2015-12-15"
request.SetScheme("HTTPS")
request.PathPattern = "/clusters/[ClusterId]"
Expand Down Expand Up @@ -257,7 +258,6 @@ func Test_CreateInstanceWithCommonRequestWithPolicy(t *testing.T) {
func handlerTrue(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("test"))
return
}

func handlerFake(w http.ResponseWriter, r *http.Request) {
Expand All @@ -269,8 +269,6 @@ func handlerFake(w http.ResponseWriter, r *http.Request) {
proxy := httputil.NewSingleHostReverseProxy(url)
w.Write([]byte("sdk"))
proxy.ServeHTTP(w, r)

return
}

func handlerFakeServer() (server *httptest.Server) {
Expand All @@ -286,8 +284,7 @@ func handlerTrueServer() (server *httptest.Server) {
return server
}

func Test_HTTPProxy(t *testing.T) {

func SkipTest_HTTPProxy(t *testing.T) {
ts := handlerFakeServer()
ts1 := handlerTrueServer()
defer func() {
Expand Down
Loading