Skip to content

Commit c4831e7

Browse files
author
mikatong
committed
[feat] add test
1 parent 23600bd commit c4831e7

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ terraform.tfstate
1616
terraform.tfstate.backup
1717
terraform.tfstate.lock.info
1818
dist/
19-
gendoc/gendoc
19+
gendoc/gendoc
20+
.vscode/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package tencentcloud
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
10+
)
11+
12+
func TestAccTencentCloudClbInstanceTopic(t *testing.T) {
13+
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
Providers: testAccProviders,
17+
CheckDestroy: testAccCheckClbListenerRuleDestroy,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccClbInstanceTopic,
21+
Check: resource.ComposeTestCheckFunc(
22+
testAccCheckClbInstanceTopicExists("tencentcloud_clb_instances_topic.topic"),
23+
resource.TestCheckResourceAttr("tencentcloud_clb_instances_topic.topic", "topic_name", "clb-topic-test"),
24+
resource.TestCheckResourceAttr("tencentcloud_clb_instances_topic.topic", "partition_count", "3"),
25+
),
26+
},
27+
},
28+
})
29+
}
30+
31+
func testAccCheckClbInstanceTopicExists(n string) resource.TestCheckFunc {
32+
return func(s *terraform.State) error {
33+
logId := getLogId(contextNil)
34+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
35+
36+
rs, ok := s.RootModule().Resources[n]
37+
if !ok {
38+
return fmt.Errorf("[CHECK][CLB topic][Exists] check: CLB topic %s is not found", n)
39+
}
40+
if rs.Primary.ID == "" {
41+
return fmt.Errorf("[CHECK][CLB topic][Exists] check: CLB topic id is not set")
42+
}
43+
clsService := ClsService{
44+
client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn,
45+
}
46+
topicName := rs.Primary.Attributes["topic_name"]
47+
instance, err := clsService.DeleteTopicsByTopicName(ctx, topicName)
48+
if err != nil {
49+
return err
50+
}
51+
if instance == nil {
52+
return fmt.Errorf("[CHECK][CLB topic][Exists] id %s is not exist", rs.Primary.ID)
53+
}
54+
return nil
55+
}
56+
}
57+
58+
const testAccClbInstanceTopic = `
59+
resource "tencentcloud_clb_instances_topic" "topic" {
60+
topic_name="clb-topic-test"
61+
partition_count=3
62+
}
63+
`

0 commit comments

Comments
 (0)