From a37c3ecee5f3936c9e89feeb53d0ee37aef64fb7 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Sat, 7 May 2022 17:55:14 +0800 Subject: [PATCH 1/2] fix: sqlserver - pubsub testcase --- tencentcloud/basic_test.go | 18 ++++ ...rce_tc_sqlserver_publish_subscribe_test.go | 91 ++----------------- 2 files changed, 26 insertions(+), 83 deletions(-) diff --git a/tencentcloud/basic_test.go b/tencentcloud/basic_test.go index 602a42cd74..355a9ad0a9 100644 --- a/tencentcloud/basic_test.go +++ b/tencentcloud/basic_test.go @@ -269,7 +269,10 @@ locals { // SQLServer const defaultSQLServerName = "keep-preset_sqlserver" +const defaultPubSQLServerName = "keep-publish-instance" +const defaultSubSQLServerName = "keep-subscribe-instance" const defaultSQLServerDB = "keep_sqlserver_db" +const defaultSQLServerPubSubDB = "keep_pubsub_db" const defaultSQLServerAccount = "keep_sqlserver_account" const CommonPresetSQLServer = ` @@ -308,6 +311,21 @@ locals { } ` +const CommonPubSubSQLServer = ` +data "tencentcloud_sqlserver_instances" "pub_sqlserver" { + name = "` + defaultPubSQLServerName + `" +} +data "tencentcloud_sqlserver_instances" "sub_sqlserver" { + name = "` + defaultSubSQLServerName + `" +} + +locals { + pub_sqlserver_id = data.tencentcloud_sqlserver_instances.pub_sqlserver.instance_list.0.id + sub_sqlserver_id = data.tencentcloud_sqlserver_instances.sub_sqlserver.instance_list.0.id + sqlserver_pubsub_db = "` + defaultSQLServerPubSubDB + `" +} +` + const instanceCommonTestCase = defaultInstanceVariable + ` resource "tencentcloud_instance" "default" { instance_name = var.instance_name diff --git a/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go b/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go index 01e952effb..764d371572 100644 --- a/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go +++ b/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go @@ -11,7 +11,6 @@ import ( ) func TestAccTencentCloudSqlserverPublishSubscribeResource(t *testing.T) { - t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -26,7 +25,6 @@ func TestAccTencentCloudSqlserverPublishSubscribeResource(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_sqlserver_publish_subscribe.example", "publish_subscribe_name", "example"), resource.TestCheckResourceAttr("tencentcloud_sqlserver_publish_subscribe.example", "database_tuples.#", "1"), ), - Destroy: false, }, { Config: testAccSqlserverPublishSubscribe_basic_update_name, @@ -97,98 +95,25 @@ func testAccCheckSqlserverPublishSubscribeExists(n string) resource.TestCheckFun } } -const testAccSqlserverPublishSubscribe_basic = defaultVpcSubnets + defaultSecurityGroupData + ` -resource "tencentcloud_sqlserver_instance" "publish_instance" { - name = "tf_sqlserver_publish_instance" - availability_zone = var.default_az - charge_type = "POSTPAID_BY_HOUR" - vpc_id = local.vpc_id - subnet_id = local.subnet_id - project_id = 0 - memory = 2 - storage = 10 - maintenance_week_set = [1,2,3] - maintenance_start_time = "09:00" - maintenance_time_span = 3 - security_groups = [local.sg_id] -} - -resource "tencentcloud_sqlserver_instance" "subscribe_instance" { - name = "tf_sqlserver_subscribe_instance" - availability_zone = var.default_az - charge_type = "POSTPAID_BY_HOUR" - vpc_id = local.vpc_id - subnet_id = local.subnet_id - project_id = 0 - memory = 2 - storage = 10 - maintenance_week_set = [1,2,3] - maintenance_start_time = "09:00" - maintenance_time_span = 3 - security_groups = [local.sg_id] -} - -resource "tencentcloud_sqlserver_db" "test_publish_subscribe" { - instance_id = tencentcloud_sqlserver_instance.publish_instance.id - name = "test111" - charset = "Chinese_PRC_BIN" - remark = "testACC-remark" -} +const testAccSqlserverPublishSubscribe_basic = CommonPubSubSQLServer + ` resource "tencentcloud_sqlserver_publish_subscribe" "example" { - publish_instance_id = tencentcloud_sqlserver_instance.publish_instance.id - subscribe_instance_id = tencentcloud_sqlserver_instance.subscribe_instance.id + publish_instance_id = local.pub_sqlserver_id + subscribe_instance_id = local.sub_sqlserver_id publish_subscribe_name = "example" delete_subscribe_db = false database_tuples { - publish_database = tencentcloud_sqlserver_db.test_publish_subscribe.name + publish_database = local.sqlserver_pubsub_db } }` -const testAccSqlserverPublishSubscribe_basic_update_name = defaultVpcSubnets + defaultSecurityGroupData + ` -resource "tencentcloud_sqlserver_instance" "publish_instance" { - name = "tf_sqlserver_publish_instance" - availability_zone = var.default_az - charge_type = "POSTPAID_BY_HOUR" - vpc_id = local.vpc_id - subnet_id = local.subnet_id - project_id = 0 - memory = 2 - storage = 10 - maintenance_week_set = [1,2,3] - maintenance_start_time = "09:00" - maintenance_time_span = 3 - security_groups = [local.sg_id] -} - -resource "tencentcloud_sqlserver_instance" "subscribe_instance" { - name = "tf_sqlserver_subscribe_instance" - availability_zone = var.default_az - charge_type = "POSTPAID_BY_HOUR" - vpc_id = local.vpc_id - subnet_id = local.subnet_id - project_id = 0 - memory = 2 - storage = 10 - maintenance_week_set = [1,2,3] - maintenance_start_time = "09:00" - maintenance_time_span = 3 - security_groups = [local.sg_id] -} - -resource "tencentcloud_sqlserver_db" "test_publish_subscribe" { - instance_id = tencentcloud_sqlserver_instance.publish_instance.id - name = "test111" - charset = "Chinese_PRC_BIN" - remark = "testACC-remark" -} - +const testAccSqlserverPublishSubscribe_basic_update_name = CommonPubSubSQLServer + ` resource "tencentcloud_sqlserver_publish_subscribe" "example" { - publish_instance_id = tencentcloud_sqlserver_instance.publish_instance.id - subscribe_instance_id = tencentcloud_sqlserver_instance.subscribe_instance.id + publish_instance_id = local.pub_sqlserver_id + subscribe_instance_id = local.sub_sqlserver_id publish_subscribe_name = "example1" delete_subscribe_db = false database_tuples { - publish_database = tencentcloud_sqlserver_db.test_publish_subscribe.name + publish_database = local.sqlserver_pubsub_db } }` From 2a0dcbcfb64574329a0c7080adbf27ae504fbb2e Mon Sep 17 00:00:00 2001 From: Kagashino Date: Sat, 7 May 2022 19:27:14 +0800 Subject: [PATCH 2/2] fix: sqlserver pubsub testcase - delete sub DB when destroy --- tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go b/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go index 764d371572..700d5bd176 100644 --- a/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go +++ b/tencentcloud/resource_tc_sqlserver_publish_subscribe_test.go @@ -101,7 +101,7 @@ resource "tencentcloud_sqlserver_publish_subscribe" "example" { publish_instance_id = local.pub_sqlserver_id subscribe_instance_id = local.sub_sqlserver_id publish_subscribe_name = "example" - delete_subscribe_db = false + delete_subscribe_db = true database_tuples { publish_database = local.sqlserver_pubsub_db } @@ -112,7 +112,7 @@ resource "tencentcloud_sqlserver_publish_subscribe" "example" { publish_instance_id = local.pub_sqlserver_id subscribe_instance_id = local.sub_sqlserver_id publish_subscribe_name = "example1" - delete_subscribe_db = false + delete_subscribe_db = true database_tuples { publish_database = local.sqlserver_pubsub_db }