Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikatong committed Sep 26, 2023
1 parent f1d905e commit 1280890
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 72 deletions.
18 changes: 18 additions & 0 deletions tencentcloud/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,3 +1130,21 @@ variable "instance_id" {
`

// End of Clickhouse

// CLB
const clbTargetEniTestCase = instanceCommonTestCase + `
resource "tencentcloud_eni" "clb_eni_target" {
name = "ci-test-eni"
vpc_id = var.cvm_vpc_id
subnet_id = var.cvm_subnet_id
description = "clb eni backend"
ipv4_count = 1
}
resource "tencentcloud_eni_attachment" "foo" {
eni_id = tencentcloud_eni.clb_eni_target.id
instance_id = tencentcloud_instance.default.id
}
`

//End of Clb
2 changes: 1 addition & 1 deletion tencentcloud/resource_tc_clb_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func targetGroupContainsEni(targets []*clb.Backend, eniIp interface{}) (contains
return
}
for _, target := range targets {
if len(target.PrivateIpAddresses) > 0 && target.PrivateIpAddresses[0] != nil {
if len(target.PrivateIpAddresses) == 0 && target.PrivateIpAddresses[0] == nil {
continue
}
if ip == *target.PrivateIpAddresses[0] {
Expand Down
140 changes: 70 additions & 70 deletions tencentcloud/resource_tc_clb_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ func TestAccTencentCloudClbAttachmentResource_tcp(t *testing.T) {
{
Config: testAccClbServerAttachment_tcp,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.foo"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "TCP"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"),
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_tcp"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "protocol_type", "TCP"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "targets.#", "1"),
),
}, {
Config: testAccClbServerAttachment_tcp_update,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.foo"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "TCP"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"),
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_tcp"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "protocol_type", "TCP"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "targets.#", "1"),
),
}, {
Config: testAccClbServerAttachment_tcp_update_ssl,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.foo"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "TCP_SSL"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"),
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_tcp"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_tcp", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "protocol_type", "TCP_SSL"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_tcp", "targets.#", "1"),
),
},
},
Expand All @@ -60,25 +60,25 @@ func TestAccTencentCloudClbAttachmentResource_http(t *testing.T) {
{
Config: fmt.Sprintf(testAccClbServerAttachment_http, defaultSshCertificate),
Check: resource.ComposeTestCheckFunc(
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.foo"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "HTTPS"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "2"),
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_http"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "protocol_type", "HTTPS"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "targets.#", "2"),
),
},
{
Config: fmt.Sprintf(testAccClbServerAttachment_httpUpdate, defaultSshCertificate),
Check: resource.ComposeTestCheckFunc(
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.foo"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.foo", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "protocol_type", "HTTPS"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.foo", "targets.#", "1"),
testAccCheckClbServerAttachmentExists("tencentcloud_clb_attachment.clb_attachment_http"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "clb_id"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_attachment.clb_attachment_http", "listener_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "protocol_type", "HTTPS"),
resource.TestCheckResourceAttr("tencentcloud_clb_attachment.clb_attachment_http", "targets.#", "1"),
),
},
{
ResourceName: "tencentcloud_clb_attachment.foo",
ResourceName: "tencentcloud_clb_attachment.clb_attachment_http",
ImportState: true,
ImportStateVerify: true,
},
Expand Down Expand Up @@ -172,15 +172,15 @@ func testAccCheckClbServerAttachmentExists(n string) resource.TestCheckFunc {
}
}

const testAccClbServerAttachment_tcp = instanceCommonTestCase + `
resource "tencentcloud_clb_instance" "foo" {
const testAccClbServerAttachment_tcp = clbTargetEniTestCase + `
resource "tencentcloud_clb_instance" "clb_instance_tcp" {
network_type = "OPEN"
clb_name = "tf-clb-attach-tcp-test"
vpc_id = var.cvm_vpc_id
}
resource "tencentcloud_clb_listener" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
resource "tencentcloud_clb_listener" "clb_listener_tcp" {
clb_id = tencentcloud_clb_instance.clb_instance_tcp.id
listener_name = "tf-clb-attach-tcp-test"
port = 44
protocol = "TCP"
Expand All @@ -193,9 +193,9 @@ resource "tencentcloud_clb_listener" "foo" {
scheduler = "WRR"
}
resource "tencentcloud_clb_attachment" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
resource "tencentcloud_clb_attachment" "clb_attachment_tcp" {
clb_id = tencentcloud_clb_instance.clb_instance_tcp.id
listener_id = tencentcloud_clb_listener.clb_listener_tcp.listener_id
targets {
instance_id = tencentcloud_instance.default.id
Expand All @@ -205,16 +205,16 @@ resource "tencentcloud_clb_attachment" "foo" {
}
`

const testAccClbServerAttachment_tcp_update = instanceCommonTestCase + presetCVM + `
resource "tencentcloud_clb_instance" "foo" {
const testAccClbServerAttachment_tcp_update = clbTargetEniTestCase + presetCVM + `
resource "tencentcloud_clb_instance" "clb_instance_tcp" {
network_type = "OPEN"
clb_name = "tf-clb-attach-tcp-test"
vpc_id = var.cvm_vpc_id
snat_pro = true
}
resource "tencentcloud_clb_listener" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
resource "tencentcloud_clb_listener" "clb_listener_tcp" {
clb_id = tencentcloud_clb_instance.clb_instance_tcp.id
listener_name = "tf-clb-attach-tcp-test"
port = 44
protocol = "TCP"
Expand All @@ -227,33 +227,33 @@ resource "tencentcloud_clb_listener" "foo" {
scheduler = "WRR"
}
resource "tencentcloud_clb_attachment" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
resource "tencentcloud_clb_attachment" "clb_attachment_tcp" {
clb_id = tencentcloud_clb_instance.clb_instance_tcp.id
listener_id = tencentcloud_clb_listener.clb_listener_tcp.listener_id
targets {
eni_ip = local.cvm_private_ip
eni_ip = tencentcloud_eni.clb_eni_target.ipv4_info.0.ip
port = 23
weight = 50
}
}
`

const testAccClbServerAttachment_tcp_update_ssl = instanceCommonTestCase + presetCVM + `
const testAccClbServerAttachment_tcp_update_ssl = clbTargetEniTestCase + presetCVM + `
data "tencentcloud_ssl_certificates" "foo" {
name = "keep-svr-ca"
}
resource "tencentcloud_clb_instance" "foo" {
resource "tencentcloud_clb_instance" "clb_instance_tcp" {
network_type = "OPEN"
clb_name = "tf-clb-attach-tcp-ssl"
vpc_id = var.cvm_vpc_id
snat_pro = true
}
# This is will force new as expected
resource "tencentcloud_clb_listener" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
resource "tencentcloud_clb_listener" "clb_listener_tcp" {
clb_id = tencentcloud_clb_instance.clb_instance_tcp.id
listener_name = "tf-clb-attach-tcp-ssl"
port = 44
protocol = "TCP_SSL"
Expand All @@ -263,48 +263,48 @@ resource "tencentcloud_clb_listener" "foo" {
certificate_id = data.tencentcloud_ssl_certificates.foo.certificates.0.id
}
resource "tencentcloud_clb_attachment" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
resource "tencentcloud_clb_attachment" "clb_attachment_tcp" {
clb_id = tencentcloud_clb_instance.clb_instance_tcp.id
listener_id = tencentcloud_clb_listener.clb_listener_tcp.listener_id
# cross network target
targets {
eni_ip = local.cvm_private_ip
eni_ip = tencentcloud_eni.clb_eni_target.ipv4_info.0.ip
port = 23
weight = 50
}
}
`

const testAccClbServerAttachment_http = instanceCommonTestCase + presetCVM + `
resource "tencentcloud_clb_instance" "foo" {
resource "tencentcloud_clb_instance" "clb_instance_http" {
network_type = "OPEN"
clb_name = "tf-clb-attach-http-test"
vpc_id = var.cvm_vpc_id
}
resource "tencentcloud_clb_listener" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
resource "tencentcloud_clb_listener" "clb_listener_http" {
clb_id = tencentcloud_clb_instance.clb_instance_http.id
listener_name = "tf-clb-attach-http-test"
port = 77
protocol = "HTTPS"
certificate_ssl_mode = "UNIDIRECTIONAL"
certificate_id = "%s"
}
resource "tencentcloud_clb_listener_rule" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
resource "tencentcloud_clb_listener_rule" "clb_listener_rule_http" {
clb_id = tencentcloud_clb_instance.clb_instance_http.id
listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id
domain = "abc.com"
url = "/"
session_expire_time = 30
scheduler = "WRR"
}
resource "tencentcloud_clb_attachment" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
rule_id = tencentcloud_clb_listener_rule.foo.rule_id
resource "tencentcloud_clb_attachment" "clb_attachment_http" {
clb_id = tencentcloud_clb_instance.clb_instance_http.id
listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id
rule_id = tencentcloud_clb_listener_rule.clb_listener_rule_http.rule_id
targets {
instance_id = tencentcloud_instance.default.id
Expand All @@ -320,38 +320,38 @@ resource "tencentcloud_clb_attachment" "foo" {
`

const testAccClbServerAttachment_httpUpdate = instanceCommonTestCase + presetCVM + `
resource "tencentcloud_clb_instance" "foo" {
resource "tencentcloud_clb_instance" "clb_instance_http" {
network_type = "OPEN"
clb_name = "tf-clb-attach-http-test"
vpc_id = var.cvm_vpc_id
}
resource "tencentcloud_clb_listener" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
resource "tencentcloud_clb_listener" "clb_listener_http" {
clb_id = tencentcloud_clb_instance.clb_instance_http.id
listener_name = "tf-clb-attach-http-test"
port = 77
protocol = "HTTPS"
certificate_ssl_mode = "UNIDIRECTIONAL"
certificate_id = "%s"
}
resource "tencentcloud_clb_listener_rule" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
resource "tencentcloud_clb_listener_rule" "clb_listener_rule_http" {
clb_id = tencentcloud_clb_instance.clb_instance_http.id
listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id
domain = "abc.com"
url = "/"
session_expire_time = 30
scheduler = "WRR"
}
resource "tencentcloud_clb_attachment" "foo" {
clb_id = tencentcloud_clb_instance.foo.id
listener_id = tencentcloud_clb_listener.foo.listener_id
rule_id = tencentcloud_clb_listener_rule.foo.rule_id
resource "tencentcloud_clb_attachment" "clb_attachment_http" {
clb_id = tencentcloud_clb_instance.clb_instance_http.id
listener_id = tencentcloud_clb_listener.clb_listener_http.listener_id
rule_id = tencentcloud_clb_listener_rule.clb_listener_rule_http.rule_id
targets {
instance_id = tencentcloud_instance.default.id
port = 23
port = 24
weight = 10
}
}
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/resource_tc_clb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
request.DeleteProtect = &isDeleteProtect
}

immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "snat_pro", "zone_id"}
immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"}

for _, v := range immutableArgs {
if d.HasChange(v) {
Expand Down

0 comments on commit 1280890

Please sign in to comment.