Skip to content

Commit

Permalink
fix: modify test
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmkn committed Sep 22, 2023
1 parent 38c7217 commit b804a60
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
21 changes: 14 additions & 7 deletions tencentcloud/data_source_tc_cat_metric_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Use this data source to query detailed information of cat metric_data
Example Usage
```hcl
data "tencentcloud_cat_metric_data" "metric_data" {
analyze_task_type = ""
metric_type = ""
field = ""
filter = ""
group_by = ""
filters =
analyze_task_type = "AnalyzeTaskType_Network"
metric_type = "gauge"
field = "avg(\"ping_time\")"
filters = [
"\"host\" = 'www.qq.com'",
"time >= now()-1h",
]
}
```
*/
Expand All @@ -20,6 +21,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
cat "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat/v20180409"
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

Expand Down Expand Up @@ -58,7 +60,7 @@ func dataSourceTencentCloudCatMetricData() *schema.Resource {
},

"filters": {
Optional: true,
Required: true,
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -121,6 +123,11 @@ func dataSourceTencentCloudCatMetricDataRead(d *schema.ResourceData, meta interf
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCatMetricDataByFilter(ctx, paramMap)
if e != nil {
if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok {
if sdkError.Code == "FailedOperation.DbQueryFailed" {
return resource.NonRetryableError(e)
}
}
return retryError(e)
}
metric = result
Expand Down
65 changes: 57 additions & 8 deletions tencentcloud/data_source_tc_cat_metric_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -test.run TestAccTencentCloudCatMetricDataDataSource_basic -v
func TestAccTencentCloudCatMetricDataDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand All @@ -16,19 +17,67 @@ func TestAccTencentCloudCatMetricDataDataSource_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCatMetricDataDataSource,
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cat_metric_data.metric_data")),
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_cat_metric_data.metric_data"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cat_metric_data.metric_data", "metric_set"),
),
},
},
})
}

const testAccCatMetricDataDataSource = `
data "tencentcloud_cat_metric_data" "metric_data" {
analyze_task_type = ""
metric_type = ""
field = ""
filter = ""
group_by = ""
filters =
resource "tencentcloud_cat_task_set" "task_set" {
interval = 1
nodes = [
"12136",
"12137",
]
parameters = jsonencode(
{
blackList = ""
filterIp = 0
grabBag = 0
ipType = 0
netDigOn = 1
netDnsNs = ""
netDnsOn = 1
netDnsQuerymethod = 1
netDnsServer = 2
netDnsTimeout = 5
netIcmpActivex = 0
netIcmpActivexStr = ""
netIcmpDataCut = 1
netIcmpInterval = 0.5
netIcmpNum = 20
netIcmpOn = 1
netIcmpSize = 32
netIcmpTimeout = 20
netTracertNum = 30
netTracertOn = 1
netTracertTimeout = 60
whiteList = ""
}
)
tags = {}
task_category = 1
task_type = 5
batch_tasks {
name = "terraform-test"
target_address = "www.baidu.com"
}
}
data "tencentcloud_cat_metric_data" "metric_data" {
analyze_task_type = "AnalyzeTaskType_Network"
metric_type = "gauge"
field = "avg(\"ping_time\")"
filters = [
"\"host\" = 'www.baidu.com'",
"time >= now()-1h",
]
depends_on = [ tencentcloud_cat_task_set.task_set ]
}
`

0 comments on commit b804a60

Please sign in to comment.