Skip to content

Commit a539d9f

Browse files
tongyimingmikatong
andauthored
add unit test (#2423)
* add unit test * add unit test2 --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent d25cba6 commit a539d9f

22 files changed

+1740
-16
lines changed

tencentcloud/basic_test.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ const (
6262
defaultVpcCidr = "172.16.0.0/16"
6363
defaultVpcCidrLess = "172.16.0.0/18"
6464

65-
defaultCvmAZone = "ap-guangzhou-7"
66-
defaultCvmVpcId = "vpc-l0dw94uh"
67-
defaultCvmSubnetId = "subnet-ccj2qg0m"
68-
defaultCvmTestingAZone = "ap-guangzhou-2"
69-
defaultCvmTestingVpcId = "vpc-701bm52d"
70-
defaultCvmTestingSubnetId = "subnet-1q62lj3m"
71-
defaultCvmTestingImgId = "img-eb30mz89"
65+
defaultCvmAZone = "ap-guangzhou-7"
66+
defaultCvmInternationalZone = "ap-guangzhou-3"
67+
defaultCvmVpcId = "vpc-l0dw94uh"
68+
defaultCvmSubnetId = "subnet-ccj2qg0m"
69+
defaultCvmTestingAZone = "ap-guangzhou-2"
70+
defaultCvmTestingVpcId = "vpc-701bm52d"
71+
defaultCvmTestingSubnetId = "subnet-1q62lj3m"
72+
defaultCvmTestingImgId = "img-eb30mz89"
73+
defaultCvmInternationalVpcId = "vpc-m7ryq37p"
74+
defaultCvmInternationalSubnetId = "subnet-lwrsb7a0"
7275

7376
defaultAZone = "ap-guangzhou-3"
7477
defaultSubnetId = "subnet-enm92y0m"
@@ -183,9 +186,11 @@ data "tencentcloud_instance_types" "default" {
183186

184187
// ckafka
185188
const (
186-
defaultKafkaInstanceId = "ckafka-vv7wpvae"
187-
defaultKafkaVpcId = "vpc-njbzmzyd"
188-
defaultKafkaSubnetId = "subnet-2txtpql8"
189+
defaultKafkaInstanceId = "ckafka-vv7wpvae"
190+
defaultKafkaVpcId = "vpc-njbzmzyd"
191+
defaultKafkaSubnetId = "subnet-2txtpql8"
192+
defaultKafkaInternationalVpcId = "vpc-ereuklyj"
193+
defaultKafkaInternationalSubnetId = "subnet-e7rvxfx2"
189194
)
190195

191196
const defaultKafkaVariable = `
@@ -198,6 +203,12 @@ variable "vpc_id" {
198203
variable "subnet_id" {
199204
default = "` + defaultKafkaSubnetId + `"
200205
}
206+
variable "international_vpc_id" {
207+
default = "` + defaultKafkaInternationalVpcId + `"
208+
}
209+
variable "international_subnet_id" {
210+
default = "` + defaultKafkaInternationalSubnetId + `"
211+
}
201212
`
202213

203214
// Tke Exclusive Network Environment
@@ -216,12 +227,14 @@ const (
216227

217228
// Cloud monitoring grafana visualization
218229
const (
219-
defaultGrafanaVpcId = "vpc-391sv4w3"
220-
defaultGrafanaSubnetId = "subnet-ljyn7h30"
221-
defaultGrafanaInstanceId = "grafana-dp2hnnfa"
222-
defaultGrafanaReceiver = "Consumer-nfyxuzmbmq"
223-
defaultGrafanaPlugin = "grafana-clock-panel"
224-
defaultGrafanaVersion = "1.2.0"
230+
defaultGrafanaVpcId = "vpc-391sv4w3"
231+
defaultGrafanaSubnetId = "subnet-ljyn7h30"
232+
defaultInternationalGrafanaVpcId = "vpc-dg21ckzx"
233+
defaultInternationalGrafanaSubnetId = "subnet-i5lq9vy4"
234+
defaultGrafanaInstanceId = "grafana-dp2hnnfa"
235+
defaultGrafanaReceiver = "Consumer-nfyxuzmbmq"
236+
defaultGrafanaPlugin = "grafana-clock-panel"
237+
defaultGrafanaVersion = "1.2.0"
225238
)
226239

227240
/*
@@ -251,6 +264,10 @@ variable "availability_cvm_zone" {
251264
default = "` + defaultCvmAZone + `"
252265
}
253266
267+
variable "availability_cvm_international_zone" {
268+
default = "` + defaultCvmInternationalZone + `"
269+
}
270+
254271
variable "availability_cvm_testing_zone" {
255272
default = "` + defaultCvmTestingAZone + `"
256273
}
@@ -275,6 +292,15 @@ variable "cvm_subnet_id" {
275292
default = "` + defaultCvmSubnetId + `"
276293
}
277294
295+
variable "cvm_international_vpc_id" {
296+
default = "` + defaultCvmInternationalVpcId + `"
297+
}
298+
299+
variable "cvm_international_subnet_id" {
300+
default = "` + defaultCvmInternationalSubnetId + `"
301+
}
302+
303+
278304
variable "vpc_id" {
279305
default = "` + defaultVpcId + `"
280306
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudInternationalGaapResource_listener4(t *testing.T) {
10+
t.Parallel()
11+
id := new(string)
12+
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccInternationalGaapLayer4ListenerBasic,
19+
Check: resource.ComposeTestCheckFunc(
20+
testAccCheckGaapLayer4ListenerExists("tencentcloud_gaap_layer4_listener.foo", id, "TCP"),
21+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "protocol", "TCP"),
22+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "name", "ci-test-gaap-4-listener"),
23+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "port", "9090"),
24+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "realserver_type", "IP"),
25+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "proxy_id"),
26+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "health_check", "true"),
27+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "interval", "5"),
28+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "connect_timeout", "2"),
29+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "realserver_bind_set.#", "2"),
30+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "status"),
31+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "create_time"),
32+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "proxy_id"),
33+
),
34+
},
35+
{
36+
ResourceName: "tencentcloud_gaap_layer4_listener.foo",
37+
ImportState: true,
38+
ImportStateVerify: true,
39+
},
40+
},
41+
})
42+
}
43+
44+
var testAccInternationalGaapLayer4ListenerBasic = `
45+
resource tencentcloud_gaap_layer4_listener "foo" {
46+
protocol = "TCP"
47+
name = "ci-test-gaap-4-listener"
48+
port = 9090
49+
realserver_type = "IP"
50+
proxy_id = "link-092unjav"
51+
health_check = true
52+
53+
realserver_bind_set {
54+
id = "rs-5qfe73i1"
55+
ip = "1.1.1.5"
56+
port = 80
57+
}
58+
59+
realserver_bind_set {
60+
id = "rs-7smh4tmf"
61+
ip = "119.29.29.35"
62+
port = 80
63+
}
64+
}
65+
`
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudInternationalGaapResource_listener7(t *testing.T) {
10+
t.Parallel()
11+
id := new(string)
12+
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccInternationalGaapLayer7ListenerBasic,
19+
Check: resource.ComposeTestCheckFunc(
20+
testAccCheckGaapLayer7ListenerExists("tencentcloud_gaap_layer7_listener.foo", id, "HTTP"),
21+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "protocol", "HTTP"),
22+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "name", "ci-test-gaap-l7-listener"),
23+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "port", "8080"),
24+
resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "client_certificate_ids.#", "0"),
25+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer7_listener.foo", "status"),
26+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer7_listener.foo", "create_time"),
27+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer7_listener.foo", "proxy_id"),
28+
),
29+
},
30+
{
31+
ResourceName: "tencentcloud_gaap_layer7_listener.foo",
32+
ImportState: true,
33+
ImportStateVerify: true,
34+
},
35+
},
36+
})
37+
}
38+
39+
var testAccInternationalGaapLayer7ListenerBasic = `
40+
resource tencentcloud_gaap_layer7_listener "foo" {
41+
protocol = "HTTP"
42+
name = "ci-test-gaap-l7-listener"
43+
port = 8080
44+
proxy_id = "link-092unjav"
45+
}
46+
`
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package tencentcloud
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccTencentCloudInternationalGaapResource_proxy(t *testing.T) {
11+
id := new(string)
12+
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheck(t) },
15+
Providers: testAccProviders,
16+
CheckDestroy: testAccCheckGaapProxyDestroy(id),
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccInternationalGaapProxyBasic,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckGaapProxyExists("tencentcloud_gaap_proxy.foo", id),
22+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "name", "ci-test-gaap-proxy"),
23+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "bandwidth", "10"),
24+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "concurrent", "2"),
25+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "project_id", "0"),
26+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "access_region", "Guangzhou"),
27+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "realserver_region", "Beijing"),
28+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "enable", "true"),
29+
resource.TestCheckNoResourceAttr("tencentcloud_gaap_proxy.foo", "tags"),
30+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "create_time"),
31+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "status"),
32+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "domain"),
33+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "ip"),
34+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "scalable"),
35+
resource.TestMatchResourceAttr("tencentcloud_gaap_proxy.foo", "support_protocols.#", regexp.MustCompile(`^[1-9]\d*$`)),
36+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "forward_ip"),
37+
),
38+
},
39+
{
40+
ResourceName: "tencentcloud_gaap_proxy.foo",
41+
ImportState: true,
42+
ImportStateVerify: true,
43+
},
44+
},
45+
})
46+
}
47+
48+
const testAccInternationalGaapProxyBasic = `
49+
resource tencentcloud_gaap_proxy "foo" {
50+
name = "ci-test-gaap-proxy"
51+
bandwidth = 10
52+
concurrent = 2
53+
access_region = "Guangzhou"
54+
realserver_region = "Beijing"
55+
network_type = "normal"
56+
}
57+
`
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
var testInternationalTkeClusterName = "tencentcloud_kubernetes_cluster"
10+
var testInternationalTkeClusterResourceKey = testInternationalTkeClusterName + ".managed_cluster"
11+
12+
func TestAccInternationalTencentCloudKubernetesResource_cluster(t *testing.T) {
13+
t.Parallel()
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
Providers: testAccProviders,
17+
CheckDestroy: testAccCheckTkeDestroy,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccInternationalTkeCluster,
21+
Check: resource.ComposeTestCheckFunc(
22+
testAccCheckTkeExists(testTkeClusterResourceKey),
23+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_cidr", "10.31.0.0/23"),
24+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_max_pod_num", "32"),
25+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_name", "test"),
26+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_desc", "test cluster desc"),
27+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_node_num", "1"),
28+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "worker_instances_list.#", "1"),
29+
resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "worker_instances_list.0.instance_id"),
30+
resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "certification_authority"),
31+
resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "user_name"),
32+
resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "password"),
33+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "tags.test", "test"),
34+
//resource.TestCheckResourceAttr(testTkeClusterResourceKey, "security_policy.#", "2"),
35+
//resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "cluster_external_endpoint"),
36+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_level", "L5"),
37+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "auto_upgrade_cluster_level", "true"),
38+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "labels.test1", "test1"),
39+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "labels.test2", "test2"),
40+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_internet_domain", "tf.cluster-internet.com"),
41+
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_intranet_domain", "tf.cluster-intranet.com"),
42+
),
43+
},
44+
},
45+
})
46+
}
47+
48+
const InternationalTkeDeps = TkeExclusiveNetwork + TkeInstanceType + TkeCIDRs + defaultImages + defaultSecurityGroupData
49+
50+
const testAccInternationalTkeCluster = InternationalTkeDeps + `
51+
variable "availability_zone" {
52+
default = "ap-guangzhou-3"
53+
}
54+
55+
resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
56+
vpc_id = local.vpc_id
57+
cluster_cidr = var.tke_cidr_a.0
58+
cluster_max_pod_num = 32
59+
cluster_name = "test"
60+
cluster_desc = "test cluster desc"
61+
cluster_max_service_num = 32
62+
cluster_internet = true
63+
cluster_internet_domain = "tf.cluster-internet.com"
64+
cluster_intranet = true
65+
cluster_intranet_domain = "tf.cluster-intranet.com"
66+
cluster_version = "1.22.5"
67+
cluster_os = "tlinux2.2(tkernel3)x86_64"
68+
cluster_level = "L5"
69+
auto_upgrade_cluster_level = true
70+
cluster_intranet_subnet_id = local.subnet_id
71+
cluster_internet_security_group = local.sg_id
72+
managed_cluster_internet_security_policies = ["3.3.3.3", "1.1.1.1"]
73+
worker_config {
74+
count = 1
75+
availability_zone = var.availability_zone
76+
instance_type = local.final_type
77+
system_disk_type = "CLOUD_SSD"
78+
system_disk_size = 60
79+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
80+
internet_max_bandwidth_out = 100
81+
public_ip_assigned = true
82+
subnet_id = local.subnet_id
83+
img_id = var.default_img_id
84+
security_group_ids = [local.sg_id]
85+
86+
data_disk {
87+
disk_type = "CLOUD_PREMIUM"
88+
disk_size = 50
89+
file_system = "ext3"
90+
auto_format_and_mount = "true"
91+
mount_target = "/var/lib/docker"
92+
disk_partition = "/dev/sdb1"
93+
}
94+
95+
enhanced_security_service = false
96+
enhanced_monitor_service = false
97+
user_data = "dGVzdA=="
98+
password = "ZZXXccvv1212"
99+
}
100+
101+
cluster_deploy_type = "MANAGED_CLUSTER"
102+
103+
tags = {
104+
"test" = "test"
105+
}
106+
107+
unschedulable = 0
108+
109+
labels = {
110+
"test1" = "test1",
111+
"test2" = "test2",
112+
}
113+
extra_args = [
114+
"root-dir=/var/lib/kubelet"
115+
]
116+
}
117+
`

0 commit comments

Comments
 (0)