Skip to content

Commit 805bec2

Browse files
WeiMengXSWeiMengXS
andauthored
Pipeline/env testing case (#2328)
* feat: add operation * feat: cdb testing * feat: monitor testing --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent 3132903 commit 805bec2

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -test.run TestAccTencentCloudMonitorAlarmMonitorTypeDataSource_basic -v
10+
func TestAccTencentCloudTestingMonitorAlarmMonitorTypeDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccTestingMonitorAlarmMonitorTypeDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_monitor_alarm_monitor_type.alarm_monitor_type"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_monitor_alarm_monitor_type.alarm_monitor_type", "monitor_type_infos.#"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_monitor_alarm_monitor_type.alarm_monitor_type", "monitor_type_infos.0.id"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_monitor_alarm_monitor_type.alarm_monitor_type", "monitor_type_infos.0.name"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_monitor_alarm_monitor_type.alarm_monitor_type", "monitor_type_infos.0.sort_id"),
26+
),
27+
},
28+
},
29+
})
30+
}
31+
32+
const testAccTestingMonitorAlarmMonitorTypeDataSource = `
33+
34+
data "tencentcloud_monitor_alarm_monitor_type" "alarm_monitor_type" {
35+
}
36+
37+
`
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
const defaultTestingPrometheusId = "prom-3oq89zvg"
10+
11+
func TestAccTencentCloudTestingMonitorRecordingRule_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) },
15+
Providers: testAccProviders,
16+
CheckDestroy: testAccCheckRecordingRuleDestroy,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testTestingRecordingRule_basic,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckRecordingRuleExists("tencentcloud_monitor_tmp_recording_rule.basic"),
22+
resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_recording_rule.basic", "name", "recording_rule-test"),
23+
resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_recording_rule.basic", "rule_state", "2"),
24+
),
25+
},
26+
{
27+
Config: testTestingRecordingRule_update,
28+
Check: resource.ComposeTestCheckFunc(
29+
testAccCheckRecordingRuleExists("tencentcloud_monitor_tmp_recording_rule.update"),
30+
resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_recording_rule.update", "name", "recording_rule-update"),
31+
resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_recording_rule.update", "rule_state", "3"),
32+
),
33+
},
34+
{
35+
ResourceName: "tencentcloud_monitor_tmp_recording_rule.update",
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
},
39+
},
40+
})
41+
}
42+
43+
const testTestingRecordingRuleVar = `
44+
variable "prometheus_id" {
45+
default = "` + defaultTestingPrometheusId + `"
46+
}
47+
`
48+
const testTestingRecordingRule_basic = testTestingRecordingRuleVar + `
49+
resource "tencentcloud_monitor_tmp_recording_rule" "basic" {
50+
name = "recording_rule-test"
51+
instance_id = var.prometheus_id
52+
rule_state = 2
53+
group = <<EOF
54+
---
55+
name: example-test
56+
rules:
57+
- record: job:http_inprogress_requests:sum
58+
expr: sum by (job) (http_inprogress_requests)
59+
EOF
60+
}`
61+
62+
const testTestingRecordingRule_update = testTestingRecordingRuleVar + `
63+
resource "tencentcloud_monitor_tmp_recording_rule" "update" {
64+
name = "recording_rule-update"
65+
instance_id = var.prometheus_id
66+
rule_state = 3
67+
group = <<EOF
68+
---
69+
name: example-test-update
70+
rules:
71+
- record: job:http_inprogress_requests:sum
72+
expr: sum by (job) (http_inprogress_requests)
73+
EOF
74+
}`

0 commit comments

Comments
 (0)