Skip to content

Commit

Permalink
[datadog_service_level_objectives] Fix test flakiness (#2162)
Browse files Browse the repository at this point in the history
* fix slo destroy helper to only delete slo resources, and also delete all slo resources

* rerecord because new

* remove second name since it was always the same as the first name
  • Loading branch information
nkzou authored Oct 31, 2023
1 parent 46ff323 commit 68ac174
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 162 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-01-12T12:48:42.231916-05:00
2023-10-27T16:33:32.381688-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-01-12T12:49:48.543499-05:00
2023-10-27T16:19:33.207655-04:00

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions datadog/tests/data_source_datadog_service_level_objectives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
func TestAccDatadogServiceLevelObjectivesDatasource(t *testing.T) {
t.Parallel()
ctx, accProviders := testAccProviders(context.Background(), t)
firstSLOName := strings.ToLower(strings.ReplaceAll(uniqueEntityName(ctx, t), "-", "_"))
secondSLOName := strings.ToLower(strings.ReplaceAll(uniqueEntityName(ctx, t), "-", "_"))
sloName := strings.ToLower(strings.ReplaceAll(uniqueEntityName(ctx, t), "-", "_"))
accProvider := testAccProvider(t, accProviders)

resource.Test(t, resource.TestCase{
Expand All @@ -23,20 +22,20 @@ func TestAccDatadogServiceLevelObjectivesDatasource(t *testing.T) {
CheckDestroy: testAccCheckDatadogServiceLevelObjectiveDestroy(accProvider),
Steps: []resource.TestStep{
{
Config: testAccDatasourceServiceLevelObjectivesIdsConfig(firstSLOName),
Check: checkServiceLevelObjectivesSingleResultDatasourceAttrs(accProvider, firstSLOName),
Config: testAccDatasourceServiceLevelObjectivesIdsConfig(sloName),
Check: checkServiceLevelObjectivesSingleResultDatasourceAttrs(accProvider, sloName),
},
{
Config: testAccDatasourceServiceLevelObjectivesNameFilterConfig(firstSLOName, secondSLOName),
Check: checkServiceLevelObjectivesSingleResultDatasourceAttrs(accProvider, firstSLOName),
Config: testAccDatasourceServiceLevelObjectivesNameFilterConfig(sloName),
Check: checkServiceLevelObjectivesSingleResultDatasourceAttrs(accProvider, sloName),
},
{
Config: testAccDatasourceServiceLevelObjectivesTagsFilterConfig(firstSLOName),
Check: checkServiceLevelObjectivesMultipleResultsDatasourceAttrs(accProvider, firstSLOName),
Config: testAccDatasourceServiceLevelObjectivesTagsFilterConfig(sloName),
Check: checkServiceLevelObjectivesMultipleResultsDatasourceAttrs(accProvider, sloName),
},
{
Config: testAccDatasourceServiceLevelObjectivesMetricsFilterConfig(firstSLOName),
Check: checkServiceLevelObjectivesMultipleResultsDatasourceAttrs(accProvider, firstSLOName),
Config: testAccDatasourceServiceLevelObjectivesMetricsFilterConfig(sloName),
Check: checkServiceLevelObjectivesMultipleResultsDatasourceAttrs(accProvider, sloName),
},
},
})
Expand Down Expand Up @@ -112,7 +111,7 @@ data "datadog_service_level_objectives" "foo" {
)
}

func testAccDatasourceServiceLevelObjectivesNameFilterConfig(firstSLOName string, secondSLOName string) string {
func testAccDatasourceServiceLevelObjectivesNameFilterConfig(sloName string) string {
return fmt.Sprintf(`
%s
%s
Expand All @@ -124,9 +123,9 @@ data "datadog_service_level_objectives" "foo" {
name_query = "%s"
}
`,
testAccCheckDatadogServiceLevelObjectiveUniqueTagMetricConfig(firstSLOName),
strings.ReplaceAll(testAccCheckDatadogServiceLevelObjectiveUniqueTagMetricConfig(secondSLOName), "\"foo\"", "\"bar\""),
firstSLOName,
testAccCheckDatadogServiceLevelObjectiveUniqueTagMetricConfig(sloName),
strings.ReplaceAll(testAccCheckDatadogServiceLevelObjectiveUniqueTagMetricConfig(sloName), "\"foo\"", "\"bar\""),
sloName,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ func testAccCheckDatadogServiceLevelObjectiveDestroy(accProvider func() (*schema
func destroyServiceLevelObjectiveHelper(ctx context.Context, s *terraform.State, apiInstances *utils.ApiInstances) error {
err := utils.Retry(2, 5, func() error {
for _, r := range s.RootModule().Resources {
if r.Primary.ID != "" {
if r.Primary.ID != "" && r.Type == "datadog_service_level_objective" {
if _, httpResp, err := apiInstances.GetServiceLevelObjectivesApiV1().GetSLO(ctx, r.Primary.ID); err != nil {
if httpResp != nil && httpResp.StatusCode == 404 {
return nil
continue
}
return &utils.FatalError{Prob: fmt.Sprintf("received an error retrieving service level objective %s", err)}
}
Expand Down

0 comments on commit 68ac174

Please sign in to comment.