Skip to content

Commit

Permalink
feat(slo): more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-DiCara committed Jun 26, 2024
1 parent f837e58 commit dd33166
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/resources/slo/resource_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func TestAccResourceSlo(t *testing.T) {
Config: testutils.TestAccExample(t, "resources/grafana_slo/resource_ratio_advanced_options.tf"),
Check: resource.ComposeTestCheckFunc(
testAccSloCheckExists("grafana_slo.ratio_options", &slo),
testAlertingExists(true, "grafana_slo.ratio_options", &slo),
testAdvancedOptionsExists(true, "grafana_slo.ratio_options", &slo),
resource.TestCheckResourceAttr("grafana_slo.ratio_options", "alerting.0.advanced_options.0.min_failures", "10"),
),
},
Expand Down Expand Up @@ -158,6 +160,30 @@ func testAlertingExists(expectation bool, rn string, slo *slo.SloV00Slo) resourc
}
}

func testAdvancedOptionsExists(expectation bool, rn string, slo *slo.SloV00Slo) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs := s.RootModule().Resources[rn]
client := testutils.Provider.Meta().(*common.Client).SLOClient
req := client.DefaultAPI.V1SloIdGet(context.Background(), rs.Primary.ID)
gotSlo, _, err := req.Execute()

if err != nil {
return fmt.Errorf("error getting SLO: %s", err)
}
*slo = *gotSlo

if slo.Alerting.AdvancedOptions == nil && expectation == false {
return nil
}

if slo.Alerting.AdvancedOptions != nil && expectation == true {
return nil
}

return fmt.Errorf("SLO Alerting expectation mismatch")
}
}

func testAccSloCheckDestroy(slo *slo.SloV00Slo) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testutils.Provider.Meta().(*common.Client).SLOClient
Expand Down

0 comments on commit dd33166

Please sign in to comment.