Skip to content

Commit

Permalink
r/burn_alert: trailing zero test
Browse files Browse the repository at this point in the history
  • Loading branch information
lafentres committed Nov 15, 2023
1 parent 6d28f24 commit bccb59c
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions internal/provider/burn_alert_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -157,6 +158,43 @@ func TestAcc_BurnAlertResource_budgetRateBasic(t *testing.T) {
})
}

// Check that creating a budget rate alert with a
// budget_rate_decrease_percent with trailing zeros works,
// doesn't produce spurious plans after apply, and imports successfully
func TestAcc_BurnAlertResource_budgetRateTrailingZeros(t *testing.T) {
dataset, sloID := burnAlertAccTestSetup(t)
burnAlert := &client.BurnAlert{}

// Create
budgetRateWindowMinutes := 60
budgetRateDecreasePercent := float64(5.00000)
pdSeverity := "info"

resource.Test(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory,
CheckDestroy: testAccEnsureBurnAlertDestroyed(t),
Steps: []resource.TestStep{
// Create - trailing zeros on budget_rate_decrease_percent
{
Config: testAccConfigBurnAlertBudgetRate_trailingZeros(dataset, sloID),
Check: testAccEnsureSuccessBudgetRateAlert(t, burnAlert, budgetRateWindowMinutes, budgetRateDecreasePercent, pdSeverity, sloID),
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPostRefresh: []plancheck.PlanCheck{plancheck.ExpectEmptyPlan()},
},
},
// Import
{
ResourceName: "honeycombio_burn_alert.test",
ImportStateIdPrefix: fmt.Sprintf("%v/", dataset),
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"recipient"},
},
},
})
}

// TestAcc_BurnAlertResourceUpgradeFromVersion015 is intended to test the migration
// case from the last SDK-based version of the Burn Alert resource to the current Framework-based
// version.
Expand Down Expand Up @@ -565,6 +603,31 @@ resource "honeycombio_burn_alert" "test" {
}`, budgetRateWindowMinutes, helper.FloatToPercentString(budgetRateDecreasePercent), dataset, sloID, pdseverity)
}

func testAccConfigBurnAlertBudgetRate_trailingZeros(dataset, sloID string) string {
return fmt.Sprintf(`
resource "honeycombio_pagerduty_recipient" "test" {
integration_key = "08b9d4cacd68933151a1ef1028b67da2"
integration_name = "testacc-basic"
}
resource "honeycombio_burn_alert" "test" {
alert_type = "budget_rate"
budget_rate_window_minutes = 60
budget_rate_decrease_percent = 5.00000
dataset = "%[1]s"
slo_id = "%[2]s"
recipient {
id = honeycombio_pagerduty_recipient.test.id
notification_details {
pagerduty_severity = "info"
}
}
}`, dataset, sloID)
}

func testAccConfigBurnAlertBudgetRate_validateAttributesWhenAlertTypeIsBudgetRate(dataset, sloID string) string {
return fmt.Sprintf(`
resource "honeycombio_burn_alert" "test" {
Expand Down

0 comments on commit bccb59c

Please sign in to comment.