From d73358b0752677a0abc663adb325111ddebdde46 Mon Sep 17 00:00:00 2001 From: Joe Blubaugh Date: Thu, 5 Dec 2024 22:16:04 +0800 Subject: [PATCH] fix(slo test): Don't fail tests if a 404 is seen for a deleted resource There is a "destroy SLO" check that runs at the end of tests that currently fails if it receives a 404. It should not fail, because that means the SLO was deleted. --- internal/resources/slo/resource_slo_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/resources/slo/resource_slo_test.go b/internal/resources/slo/resource_slo_test.go index 06ba32a33..bcf0dba46 100644 --- a/internal/resources/slo/resource_slo_test.go +++ b/internal/resources/slo/resource_slo_test.go @@ -2,6 +2,7 @@ package slo_test import ( "context" + "errors" "fmt" "regexp" "strings" @@ -275,12 +276,17 @@ func testAdvancedOptionsExists(expectation bool, rn string, slo *slo.SloV00Slo) } } -func testAccSloCheckDestroy(slo *slo.SloV00Slo) resource.TestCheckFunc { +func testAccSloCheckDestroy(sloObj *slo.SloV00Slo) resource.TestCheckFunc { return func(s *terraform.State) error { client := testutils.Provider.Meta().(*common.Client).SLOClient - req := client.DefaultAPI.V1SloIdGet(context.Background(), slo.Uuid) + req := client.DefaultAPI.V1SloIdGet(context.Background(), sloObj.Uuid) gotSlo, resp, err := req.Execute() if err != nil { + var oapiErr slo.GenericOpenAPIError + if errors.As(err, &oapiErr) && strings.Contains(oapiErr.Error(), "404 Not Found") { + return nil + } + return fmt.Errorf("error getting SLO: %s", err) }