From 071e59c956bce959dda2416d995ef5940026d539 Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 22 Sep 2023 16:27:25 +0800 Subject: [PATCH] fix: modify test --- .../data_source_tc_cat_metric_data.go | 21 ++++-- .../data_source_tc_cat_metric_data_test.go | 65 ++++++++++++++++--- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/tencentcloud/data_source_tc_cat_metric_data.go b/tencentcloud/data_source_tc_cat_metric_data.go index 5a9f9716a0..498416e41d 100644 --- a/tencentcloud/data_source_tc_cat_metric_data.go +++ b/tencentcloud/data_source_tc_cat_metric_data.go @@ -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", + ] } ``` */ @@ -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" ) @@ -58,7 +60,7 @@ func dataSourceTencentCloudCatMetricData() *schema.Resource { }, "filters": { - Optional: true, + Required: true, Type: schema.TypeSet, Elem: &schema.Schema{ Type: schema.TypeString, @@ -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 diff --git a/tencentcloud/data_source_tc_cat_metric_data_test.go b/tencentcloud/data_source_tc_cat_metric_data_test.go index c22ed16985..6a63cb6e22 100644 --- a/tencentcloud/data_source_tc_cat_metric_data_test.go +++ b/tencentcloud/data_source_tc_cat_metric_data_test.go @@ -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{ @@ -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 ] +} + `