Skip to content

Commit e05851d

Browse files
WeiMengXSWeiMengXS
andauthored
env testing case (#2318)
* feat: add operation * feat: cdb testing * feat: cdb testing * feat: cdb testing --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent c259de5 commit e05851d

8 files changed

+462
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudTestingTeoZoneAvailablePlansDataSource -v
10+
func TestAccTencentCloudTestingTeoZoneAvailablePlansDataSource(t *testing.T) {
11+
t.Parallel()
12+
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheck(t) },
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccDataSourceTestingTeoZoneAvailablePlans,
19+
Check: resource.ComposeTestCheckFunc(
20+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_teo_zone_available_plans.zone_available_plans"),
21+
),
22+
},
23+
},
24+
})
25+
}
26+
27+
const testAccDataSourceTestingTeoZoneAvailablePlans = `
28+
29+
data "tencentcloud_teo_zone_available_plans" "zone_available_plans" {
30+
}
31+
32+
`
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccTencentCloudTestingCbsStorageResource_basic(t *testing.T) {
9+
t.Parallel()
10+
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
CheckDestroy: testAccCheckCbsStorageDestroy,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccTestingCbsStorage_basic,
18+
Check: resource.ComposeTestCheckFunc(
19+
testAccCheckStorageExists("tencentcloud_cbs_storage.storage_basic"),
20+
resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "storage_name", "tf-storage-basic"),
21+
resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "storage_type", "CLOUD_PREMIUM"),
22+
resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "storage_size", "50"),
23+
resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "availability_zone", "ap-guangzhou-3"),
24+
),
25+
},
26+
{
27+
ResourceName: "tencentcloud_cbs_storage.storage_basic",
28+
ImportState: true,
29+
ImportStateVerify: true,
30+
ImportStateVerifyIgnore: []string{"force_delete"},
31+
},
32+
},
33+
})
34+
}
35+
36+
const testAccTestingCbsStorage_basic = `
37+
resource "tencentcloud_cbs_storage" "storage_basic" {
38+
storage_type = "CLOUD_PREMIUM"
39+
storage_name = "tf-storage-basic"
40+
storage_size = 50
41+
availability_zone = "ap-guangzhou-3"
42+
}
43+
`
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package tencentcloud
2+
3+
import (
4+
"fmt"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
6+
"testing"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudTestingMysqlAccountResource_basic -v
10+
func TestAccTencentCloudTestingMysqlAccountResource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() { testAccPreCheck(t) },
14+
Providers: testAccProviders,
15+
CheckDestroy: testAccCheckMysqlAccountDestroy,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccTestingMysqlAccount(),
19+
Check: resource.ComposeAggregateTestCheckFunc(
20+
testAccCheckMysqlAccountExists("tencentcloud_mysql_account.mysql_account"),
21+
resource.TestCheckResourceAttrSet("tencentcloud_mysql_account.mysql_account", "mysql_id"),
22+
resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "name", "terraform_test"),
23+
resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "description", "test from terraform"),
24+
resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "max_user_connections", "10"),
25+
),
26+
},
27+
{
28+
Config: testAccTestingMysqlAccountUp(),
29+
Check: resource.ComposeAggregateTestCheckFunc(
30+
testAccCheckMysqlAccountExists("tencentcloud_mysql_account.mysql_account"),
31+
resource.TestCheckResourceAttrSet("tencentcloud_mysql_account.mysql_account", "mysql_id"),
32+
resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "name", "terraform_test"),
33+
resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "description", "test from terraform"),
34+
resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "max_user_connections", "10"),
35+
),
36+
},
37+
},
38+
})
39+
}
40+
41+
func testAccTestingMysqlAccount() string {
42+
return fmt.Sprintf(`
43+
%s
44+
45+
resource "tencentcloud_mysql_account" "mysql_account" {
46+
mysql_id = local.mysql_id
47+
name = "terraform_test"
48+
host = "192.168.0.%%"
49+
password = "Test@123456#"
50+
description = "test from terraform"
51+
max_user_connections = 10
52+
}
53+
`, CommonPresetMysql)
54+
}
55+
56+
func testAccTestingMysqlAccountUp() string {
57+
return fmt.Sprintf(`
58+
%s
59+
60+
resource "tencentcloud_mysql_account" "mysql_account" {
61+
mysql_id = local.mysql_id
62+
name = "terraform_test"
63+
host = "192.168.1.%%"
64+
password = "Test@123456#"
65+
description = "test from terraform"
66+
max_user_connections = 10
67+
}
68+
`, CommonPresetMysql)
69+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudTestingVpcAclRulesResource_Update(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccTestingVpcACLConfig,
17+
Check: resource.ComposeTestCheckFunc(
18+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "name", "test_acl"),
19+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.0", "ACCEPT#192.168.1.0/24#80#TCP"),
20+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.1", "ACCEPT#192.168.1.0/24#80-90#TCP"),
21+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.0", "ACCEPT#192.168.1.0/24#80#TCP"),
22+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.1", "ACCEPT#192.168.1.0/24#80-90#TCP"),
23+
),
24+
},
25+
{
26+
Config: testAccTestingVpcACLConfigUpdate,
27+
Check: resource.ComposeTestCheckFunc(
28+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "name", "test_acl"),
29+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.0", "ACCEPT#192.168.1.0/24#800#TCP"),
30+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.1", "ACCEPT#192.168.1.0/24#800-900#TCP"),
31+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.0", "ACCEPT#192.168.1.0/24#800#TCP"),
32+
resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.1", "ACCEPT#192.168.1.0/24#800-900#TCP"),
33+
),
34+
},
35+
},
36+
})
37+
}
38+
39+
const testAccTestingVpcACLConfig = defaultVpcVariable + `
40+
resource "tencentcloud_vpc" "foo" {
41+
name = var.instance_name
42+
cidr_block = var.vpc_cidr
43+
}
44+
resource "tencentcloud_vpc_acl" "foo" {
45+
vpc_id = tencentcloud_vpc.foo.id
46+
name = "test_acl"
47+
ingress = [
48+
"ACCEPT#192.168.1.0/24#80#TCP",
49+
"ACCEPT#192.168.1.0/24#80-90#TCP",
50+
]
51+
egress = [
52+
"ACCEPT#192.168.1.0/24#80#TCP",
53+
"ACCEPT#192.168.1.0/24#80-90#TCP",
54+
]
55+
}
56+
`
57+
58+
const testAccTestingVpcACLConfigUpdate = defaultVpcVariable + `
59+
resource "tencentcloud_vpc" "foo" {
60+
name = var.instance_name
61+
cidr_block = var.vpc_cidr
62+
}
63+
64+
resource "tencentcloud_vpc_acl" "foo" {
65+
vpc_id = tencentcloud_vpc.foo.id
66+
name = "test_acl"
67+
ingress = [
68+
"ACCEPT#192.168.1.0/24#800#TCP",
69+
"ACCEPT#192.168.1.0/24#800-900#TCP",
70+
]
71+
egress = [
72+
"ACCEPT#192.168.1.0/24#800#TCP",
73+
"ACCEPT#192.168.1.0/24#800-900#TCP",
74+
]
75+
}
76+
`
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudTestingVpcDhcpIpResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccTestingVpcDhcpIp,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpc_dhcp_ip.example", "id")),
20+
},
21+
{
22+
ResourceName: "tencentcloud_vpc_dhcp_ip.example",
23+
ImportState: true,
24+
ImportStateVerify: true,
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccTestingVpcDhcpIp = `
31+
32+
resource "tencentcloud_vpc" "vpc" {
33+
name = "vpc-example"
34+
cidr_block = "10.0.0.0/16"
35+
}
36+
37+
resource "tencentcloud_subnet" "subnet" {
38+
availability_zone = "ap-guangzhou-2"
39+
name = "subnet-example"
40+
vpc_id = tencentcloud_vpc.vpc.id
41+
cidr_block = "10.0.0.0/16"
42+
is_multicast = false
43+
}
44+
45+
resource "tencentcloud_vpc_dhcp_ip" "example" {
46+
vpc_id = tencentcloud_vpc.vpc.id
47+
subnet_id = tencentcloud_subnet.subnet.id
48+
dhcp_ip_name = "tf-example"
49+
}
50+
`
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccTencentCloudTestingVpcFlowLogResource_basic(t *testing.T) {
9+
t.Parallel()
10+
resource.Test(t, resource.TestCase{
11+
PreCheck: func() {
12+
testAccPreCheck(t)
13+
},
14+
Providers: testAccProviders,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccTestingVpcFlowLog,
18+
Check: resource.ComposeTestCheckFunc(
19+
resource.TestCheckResourceAttrSet("tencentcloud_vpc_flow_log.flow_log", "id"),
20+
resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_name", "iac-test-1"),
21+
resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_description", "this is a testing flow log"),
22+
),
23+
},
24+
{
25+
ResourceName: "tencentcloud_vpc_flow_log.flow_log",
26+
ImportState: true,
27+
ImportStateVerify: true,
28+
ImportStateVerifyIgnore: []string{
29+
"cloud_log_region",
30+
"flow_log_storage",
31+
},
32+
},
33+
{
34+
Config: testAccTestingVpcFlowLogUpdate,
35+
Check: resource.ComposeTestCheckFunc(
36+
resource.TestCheckResourceAttrSet("tencentcloud_vpc_flow_log.flow_log", "id"),
37+
resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_name", "iac-test-2"),
38+
resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_description", "updated"),
39+
),
40+
},
41+
},
42+
})
43+
}
44+
45+
const testAccTestingVpcFlowLog = `
46+
47+
resource "tencentcloud_vpc_flow_log" "flow_log" {
48+
flow_log_name = "iac-test-1"
49+
resource_type = "NETWORKINTERFACE"
50+
resource_id = "eni-qz9wxgmd"
51+
traffic_type = "ACCEPT"
52+
vpc_id = "vpc-humgpppd"
53+
flow_log_description = "this is a testing flow log"
54+
cloud_log_id = "e6acd27c-365c-4959-8257-751d86657439" # FIXME use data.logsets (not supported) instead
55+
storage_type = "cls"
56+
}
57+
`
58+
59+
const testAccTestingVpcFlowLogUpdate = `
60+
resource "tencentcloud_vpc_flow_log" "flow_log" {
61+
flow_log_name = "iac-test-2"
62+
resource_type = "NETWORKINTERFACE"
63+
resource_id = "eni-qz9wxgmd"
64+
traffic_type = "ACCEPT"
65+
vpc_id = "vpc-humgpppd"
66+
flow_log_description = "updated"
67+
cloud_log_id = "e6acd27c-365c-4959-8257-751d86657439" # FIXME use data.logsets (not supported) instead
68+
storage_type = "cls"
69+
}
70+
`

0 commit comments

Comments
 (0)