Skip to content

Commit 9f904b4

Browse files
tongyimingmikatong
andauthored
Fix/ckafka unit test (#1009)
* fix: kafka bug && unit test * fix: unit-test * fix: unit test Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 13a3831 commit 9f904b4

11 files changed

+149
-137
lines changed

tencentcloud/basic_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ const (
9696
defaultEMRSgId = "sg-mag8k2fj"
9797
)
9898

99+
//ckafka
100+
const (
101+
defaultKafkaInstanceId = "ckafka-vv7wpvae"
102+
defaultKafkaVpcId = "vpc-68vi2d3h"
103+
defaultKafkaSubnetId = "subnet-ob6clqwk"
104+
)
105+
106+
const defaultKafkaVariable = `
107+
variable "instance_id" {
108+
default = "` + defaultKafkaInstanceId + `"
109+
}
110+
variable "vpc_id" {
111+
default = "` + defaultKafkaVpcId + `"
112+
}
113+
variable "subnet_id" {
114+
default = "` + defaultKafkaSubnetId + `"
115+
}
116+
`
117+
99118
// Tke Exclusive Network Environment
100119
const (
101120
tkeExclusiveVpcId = "vpc-391sv4w3"

tencentcloud/data_source_tc_ckafka_acls_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func TestAccTencentCloudCkafkaAclsDataSource(t *testing.T) {
1010
t.Parallel()
1111
resource.Test(t, resource.TestCase{
12-
PreCheck: func() { testAccPreCheck(t) },
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
1313
Providers: testAccProviders,
1414
CheckDestroy: testAccCheckCkafkaAclDestroy,
1515
Steps: []resource.TestStep{
@@ -29,7 +29,38 @@ func TestAccTencentCloudCkafkaAclsDataSource(t *testing.T) {
2929
})
3030
}
3131

32-
const testAccTencentCloudDataSourceCkafkaAcl = testAccCkafkaAcl + `
32+
const testAccTencentCloudDataSourceCkafkaAcl = defaultKafkaVariable + `
33+
resource "tencentcloud_ckafka_user" "foo" {
34+
instance_id = var.instance_id
35+
account_name = "tf-test-acl-data"
36+
password = "test1234"
37+
}
38+
39+
resource "tencentcloud_ckafka_topic" "kafka_topic_acl" {
40+
instance_id = var.instance_id
41+
topic_name = "ckafka-topic-acl-data-test"
42+
replica_num = 2
43+
partition_num = 1
44+
note = "test topic"
45+
enable_white_list = true
46+
ip_white_list = ["192.168.1.1"]
47+
clean_up_policy = "delete"
48+
sync_replica_min_num = 1
49+
unclean_leader_election_enable = false
50+
segment = 86400000
51+
retention = 60000
52+
}
53+
54+
resource "tencentcloud_ckafka_acl" foo {
55+
instance_id = var.instance_id
56+
resource_type = "TOPIC"
57+
resource_name = tencentcloud_ckafka_topic.kafka_topic_acl.topic_name
58+
operation_type = "WRITE"
59+
permission_type = "ALLOW"
60+
host = "10.10.10.0"
61+
principal = tencentcloud_ckafka_user.foo.account_name
62+
}
63+
3364
data "tencentcloud_ckafka_acls" "foo" {
3465
instance_id = tencentcloud_ckafka_acl.foo.instance_id
3566
resource_type = tencentcloud_ckafka_acl.foo.resource_type

tencentcloud/data_source_tc_ckafka_topics_test.go

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

9-
func TestAccTencentCloudCkafkaTopicDataSource(t *testing.T) {
9+
func TestAccTencentCloudCKafkaTopicDataSource(t *testing.T) {
1010
t.Parallel()
1111
resource.Test(t, resource.TestCase{
12-
PreCheck: func() { testAccPreCheck(t) },
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
1313
Providers: testAccProviders,
1414
CheckDestroy: testAccTencentCloudKafkaTopicDestory,
1515
Steps: []resource.TestStep{
1616
{
1717
Config: testAccTencentCloudCkafkaTopicDataSourceConfig,
1818
Check: resource.ComposeTestCheckFunc(
1919
testAccCheckKafkaTopicInstanceExists("tencentcloud_ckafka_topic.kafka_topic"),
20-
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_id", "ckafka-f9ife4zz"),
20+
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_id", "ckafka-vv7wpvae"),
2121
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.#", "1"),
2222
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.topic_name", "ckafkaTopic-tf-test"),
2323
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.partition_num", "1"),
@@ -29,21 +29,21 @@ func TestAccTencentCloudCkafkaTopicDataSource(t *testing.T) {
2929
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.clean_up_policy", "delete"),
3030
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.sync_replica_min_num", "1"),
3131
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.unclean_leader_election_enable"),
32-
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.segment", "3600000"),
32+
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.segment", "86400000"),
3333
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.kafka_topics", "instance_list.0.retention", "60000"),
34-
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.foo", "instance_list.#", "2"),
35-
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.foo", "instance_list.1.partition_num"),
36-
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.foo", "instance_list.1.replica_num"),
37-
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.foo", "instance_list.1.create_time"),
34+
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_topics.foo", "instance_list.#", "1"),
35+
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.foo", "instance_list.0.partition_num"),
36+
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.foo", "instance_list.0.replica_num"),
37+
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_topics.foo", "instance_list.0.create_time"),
3838
),
3939
},
4040
},
4141
})
4242
}
4343

44-
const testAccTencentCloudCkafkaTopicDataSourceConfig = `
44+
const testAccTencentCloudCkafkaTopicDataSourceConfig = defaultKafkaVariable + `
4545
resource "tencentcloud_ckafka_topic" "kafka_topic" {
46-
instance_id = "ckafka-f9ife4zz"
46+
instance_id = var.instance_id
4747
topic_name = "ckafkaTopic-tf-test"
4848
replica_num = 2
4949
partition_num = 1
@@ -53,7 +53,7 @@ resource "tencentcloud_ckafka_topic" "kafka_topic" {
5353
clean_up_policy = "delete"
5454
sync_replica_min_num = 1
5555
unclean_leader_election_enable = false
56-
segment = 3600000
56+
segment = 86400000
5757
retention = 60000
5858
}
5959

tencentcloud/data_source_tc_ckafka_users_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func TestAccTencentCloudCkafkaUsersDataSource(t *testing.T) {
1010
t.Parallel()
1111
resource.Test(t, resource.TestCase{
12-
PreCheck: func() { testAccPreCheck(t) },
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
1313
Providers: testAccProviders,
1414
CheckDestroy: testAccCheckCkafkaUserDestroy,
1515
Steps: []resource.TestStep{
@@ -18,7 +18,7 @@ func TestAccTencentCloudCkafkaUsersDataSource(t *testing.T) {
1818
Check: resource.ComposeAggregateTestCheckFunc(
1919
testAccCheckCkafkaUserExists("tencentcloud_ckafka_user.foo"),
2020
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_users.foo", "instance_id"),
21-
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_users.foo", "user_list.0.account_name", "test"),
21+
resource.TestCheckResourceAttr("data.tencentcloud_ckafka_users.foo", "user_list.0.account_name", "test1"),
2222
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_users.foo", "user_list.0.create_time"),
2323
resource.TestCheckResourceAttrSet("data.tencentcloud_ckafka_users.foo", "user_list.0.update_time"),
2424
),
@@ -27,10 +27,10 @@ func TestAccTencentCloudCkafkaUsersDataSource(t *testing.T) {
2727
})
2828
}
2929

30-
const testAccTencentCloudDataSourceCkafkaUser = `
30+
const testAccTencentCloudDataSourceCkafkaUser = defaultKafkaVariable + `
3131
resource "tencentcloud_ckafka_user" "foo" {
32-
instance_id = "ckafka-f9ife4zz"
33-
account_name = "test"
32+
instance_id = var.instance_id
33+
account_name = "test1"
3434
password = "test1234"
3535
}
3636

tencentcloud/resource_tc_ckafka_acl_test.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1010
)
1111

12-
func TestAccTencentCloudCkafkaAcl(t *testing.T) {
12+
func TestAccTencentCloudCkafkaAclResource(t *testing.T) {
1313
t.Parallel()
1414
resource.Test(t, resource.TestCase{
15-
PreCheck: func() { testAccPreCheck(t) },
15+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
1616
Providers: testAccProviders,
1717
CheckDestroy: testAccCheckCkafkaAclDestroy,
1818
Steps: []resource.TestStep{
@@ -89,11 +89,32 @@ func testAccCheckCkafkaAclDestroy(s *terraform.State) error {
8989
return nil
9090
}
9191

92-
const testAccCkafkaAcl = testAccCkafkaUser + `
92+
const testAccCkafkaAcl = defaultKafkaVariable + `
93+
resource "tencentcloud_ckafka_user" "foo" {
94+
instance_id = var.instance_id
95+
account_name = "tf-test-acl-resource"
96+
password = "test1234"
97+
}
98+
99+
resource "tencentcloud_ckafka_topic" "kafka_topic_acl" {
100+
instance_id = var.instance_id
101+
topic_name = "ckafka-topic-acl-test"
102+
replica_num = 2
103+
partition_num = 1
104+
note = "test topic"
105+
enable_white_list = true
106+
ip_white_list = ["192.168.1.1"]
107+
clean_up_policy = "delete"
108+
sync_replica_min_num = 1
109+
unclean_leader_election_enable = false
110+
segment = 86400000
111+
retention = 60000
112+
}
113+
93114
resource "tencentcloud_ckafka_acl" foo {
94-
instance_id = "ckafka-f9ife4zz"
115+
instance_id = var.instance_id
95116
resource_type = "TOPIC"
96-
resource_name = "topic-tf-test"
117+
resource_name = tencentcloud_ckafka_topic.kafka_topic_acl.topic_name
97118
operation_type = "WRITE"
98119
permission_type = "ALLOW"
99120
host = "10.10.10.0"

tencentcloud/resource_tc_ckafka_instance.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ func resourceTencentCloudCkafkaInstanceCreate(d *schema.ResourceData, meta inter
388388
}
389389
return resource.RetryableError(fmt.Errorf("create ckafka instance task is processing"))
390390
})
391+
if err != nil {
392+
return err
393+
}
391394
d.SetId(*instanceId)
392395

393396
// modify instance attributes
@@ -669,7 +672,7 @@ func resourceTencentCLoudCkafkaInstanceDelete(d *schema.ResourceData, meta inter
669672
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
670673
_, err := service.client.UseCkafkaClient().DeleteInstancePre(request)
671674
if err != nil {
672-
retryError(err, "UnsupportedOperation")
675+
return retryError(err, "UnsupportedOperation")
673676
}
674677
return nil
675678
})
@@ -687,5 +690,8 @@ func resourceTencentCLoudCkafkaInstanceDelete(d *schema.ResourceData, meta inter
687690
}
688691
return resource.RetryableError(fmt.Errorf("delete ckafka instance task is processing"))
689692
})
693+
if err != nil {
694+
return err
695+
}
690696
return nil
691697
}

0 commit comments

Comments
 (0)