Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package integeration |
||
2 | |||
3 | import ( |
||
4 | "os" |
||
5 | "strconv" |
||
6 | "testing" |
||
7 | |||
8 | "github.com/aliyun/credentials-go/credentials" |
||
9 | "github.com/stretchr/testify/assert" |
||
10 | ) |
||
11 | |||
12 | const ( |
||
13 | EnvVarSubAccessKeyID = "SUB_ALICLOUD_ACCESS_KEY" |
||
14 | EnvVarSubAccessKeySecret = "SUB_ALICLOUD_SECRET_KEY" |
||
15 | EnvVarRoleArn = "ALICLOUD_ROLE_ARN" |
||
16 | EnvVarRoleSessionName = "ALICLOUD_ROLE_SESSION_NAME" |
||
17 | EnvVarRoleSessionExpiration = "ALICLOUD_ROLE_SESSION_EXPIRATION" |
||
18 | ) |
||
19 | |||
20 | func Test_Arn(t *testing.T) { |
||
21 | rawexpiration := os.Getenv(EnvVarRoleSessionExpiration) |
||
22 | expiration := 0 |
||
23 | if rawexpiration != "" { |
||
24 | expiration, _ = strconv.Atoi(rawexpiration) |
||
25 | } |
||
26 | config := &credentials.Configuration{ |
||
27 | Type: "ram_role_arn", |
||
28 | AccessKeyID: os.Getenv(EnvVarSubAccessKeyID), |
||
29 | AccessKeySecret: os.Getenv(EnvVarSubAccessKeySecret), |
||
30 | RoleArn: os.Getenv(EnvVarRoleArn), |
||
31 | RoleSessionName: os.Getenv(EnvVarRoleSessionName), |
||
32 | RoleSessionExpiration: expiration, |
||
33 | } |
||
34 | cred, err := credentials.NewCredential(config) |
||
35 | assert.Nil(t, err) |
||
36 | assert.NotNil(t, cred) |
||
37 | accesskey, err := cred.GetAccessKeyID() |
||
38 | assert.Nil(t, err) |
||
39 | assert.NotNil(t, accesskey) |
||
40 | } |
||
41 |