Skip to content

Commit b00b9dd

Browse files
author
mikatong
committed
add testcase
1 parent ad7323c commit b00b9dd

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

tencentcloud/data_source_tc_user_info.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,31 @@ func datasourceTencentCloudUserInfoRead(d *schema.ResourceData, meta interface{}
100100
appId := strconv.FormatUint(*result.AppId, 10)
101101
uin := *result.Uin
102102
ownerUin := *result.OwnerUin
103-
104-
d.SetId(fmt.Sprintf("user-%s-%s-%d", uin, appId, rand.Intn(10000)))
105-
106-
_ = d.Set("app_id", appId)
107-
_ = d.Set("uin", uin)
108-
_ = d.Set("owner_uin", ownerUin)
109103
accountInfoRequest := cam.NewDescribeSubAccountsRequest()
110104
accountInfoRequest.FilterSubAccountUin = []*uint64{helper.Uint64(helper.StrToUInt64(uin))}
111105
accountInfoResponse, err := client.UseCamClient().DescribeSubAccounts(accountInfoRequest)
112106
if err != nil {
113107
return err
114108
}
115109
subAccounts := accountInfoResponse.Response.SubAccounts
110+
var name string
116111
if len(subAccounts) > 0 {
117-
name := *subAccounts[0].Name
118-
_ = d.Set("name", name)
112+
name = *subAccounts[0].Name
119113
}
114+
d.SetId(fmt.Sprintf("user-%s-%s-%d", uin, appId, rand.Intn(10000)))
115+
116+
_ = d.Set("app_id", appId)
117+
_ = d.Set("uin", uin)
118+
_ = d.Set("owner_uin", ownerUin)
119+
_ = d.Set("name", name)
120+
120121
output, ok := d.GetOk("result_output_file")
121122
if ok && output.(string) != "" {
122123
if e := writeToFile(output.(string), map[string]interface{}{
123124
"app_id": appId,
124125
"uin": uin,
125126
"ownerUin": ownerUin,
127+
"name": name,
126128
}); e != nil {
127129
return e
128130
}

tencentcloud/data_source_tc_user_info_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9-
func TestAccTencentCloudDataSourceUserInfo(t *testing.T) {
9+
func TestAccTencentCloudDataSourceUserInfoBasic(t *testing.T) {
1010
t.Parallel()
1111
resource.Test(t, resource.TestCase{
12-
PreCheck: func() { testAccPreCheck(t) },
1312
Providers: testAccProviders,
1413
Steps: []resource.TestStep{
1514
{
16-
Config: testAccDataUserInfoBasic,
15+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
16+
Config: testAccDataUserInfoBasic,
1717
Check: resource.ComposeAggregateTestCheckFunc(
1818
resource.TestCheckResourceAttrSet("data.tencentcloud_user_info.info", "app_id"),
1919
resource.TestCheckResourceAttrSet("data.tencentcloud_user_info.info", "uin"),
@@ -24,6 +24,29 @@ func TestAccTencentCloudDataSourceUserInfo(t *testing.T) {
2424
})
2525
}
2626

27+
func TestAccTencentCloudDataSourceUserInfoSubAccount(t *testing.T) {
28+
t.Parallel()
29+
resource.Test(t, resource.TestCase{
30+
Providers: testAccProviders,
31+
Steps: []resource.TestStep{
32+
{
33+
// Need use subaccount aksk
34+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_SUB_ACCOUNT) },
35+
Config: testAccDataUserInfoSubAccount,
36+
Check: resource.ComposeAggregateTestCheckFunc(
37+
resource.TestCheckResourceAttrSet("data.tencentcloud_user_info.info_sub_account", "app_id"),
38+
resource.TestCheckResourceAttrSet("data.tencentcloud_user_info.info_sub_account", "uin"),
39+
resource.TestCheckResourceAttrSet("data.tencentcloud_user_info.info_sub_account", "owner_uin"),
40+
resource.TestCheckResourceAttrSet("data.tencentcloud_user_info.info_sub_account", "name"),
41+
),
42+
},
43+
},
44+
})
45+
}
46+
2747
const testAccDataUserInfoBasic = `
2848
data "tencentcloud_user_info" "info" {}
2949
`
50+
const testAccDataUserInfoSubAccount = `
51+
data "tencentcloud_user_info" "info_sub_account" {}
52+
`

tencentcloud/provider_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
ACCOUNT_TYPE_PREPAY = "PREPAY"
2020
ACCOUNT_TYPE_COMMON = "COMMON"
2121
ACCOUNT_TYPE_PRIVATE = "PRIVATE"
22+
ACCOUNT_TYPE_SUB_ACCOUNT = "SUB_ACCOUNT"
2223
INTERNATION_PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID_INTERNATION"
2324
INTERNATION_PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY_INTERNATION"
2425
PREPAY_PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID_PREPAY"
@@ -27,6 +28,8 @@ const (
2728
PRIVATE_PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY_PRIVATE"
2829
COMMON_PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID_COMMON"
2930
COMMON_PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY_COMMON"
31+
SUB_ACCOUNT_PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID_SUB_ACCOUNT"
32+
SUB_ACCOUNT_PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY_SUB_ACCOUNT"
3033
)
3134

3235
func init() {
@@ -109,6 +112,14 @@ func testAccPreCheckCommon(t *testing.T, accountType string) {
109112
}
110113
os.Setenv(PROVIDER_SECRET_ID, secretId)
111114
os.Setenv(PROVIDER_SECRET_KEY, secretKey)
115+
case accountType == ACCOUNT_TYPE_SUB_ACCOUNT:
116+
secretId := os.Getenv(SUB_ACCOUNT_PROVIDER_SECRET_ID)
117+
secretKey := os.Getenv(SUB_ACCOUNT_PROVIDER_SECRET_KEY)
118+
if secretId == "" || secretKey == "" {
119+
t.Fatalf("%v and %v must be set for acceptance tests\n", SUB_ACCOUNT_PROVIDER_SECRET_ID, SUB_ACCOUNT_PROVIDER_SECRET_KEY)
120+
}
121+
os.Setenv(PROVIDER_SECRET_ID, secretId)
122+
os.Setenv(PROVIDER_SECRET_KEY, secretKey)
112123
default:
113124
if v := os.Getenv(PROVIDER_SECRET_ID); v == "" {
114125
t.Fatalf("%v must be set for acceptance tests\n", PROVIDER_SECRET_ID)

0 commit comments

Comments
 (0)