Skip to content

Commit

Permalink
Contact Points: Add recreation test (#1614)
Browse files Browse the repository at this point in the history
From this PR: #1612
This was already fixed in v3, but it can't hurt to have the test here as well.
  • Loading branch information
julienduchesne authored Jun 5, 2024
1 parent 6d6fb31 commit 8c78dfc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/resources/grafana/resource_alerting_contact_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/stretchr/testify/require"

"github.com/grafana/terraform-provider-grafana/v3/internal/testutils"
)
Expand Down Expand Up @@ -483,6 +484,53 @@ func TestAccContactPoint_inOrg(t *testing.T) {
})
}

func TestAccContactPoint_recreate(t *testing.T) {
testutils.CheckOSSTestsEnabled(t, ">=9.1.0")

var points models.ContactPoints
name := acctest.RandString(10)
config := testutils.TestAccExampleWithReplace(t, "resources/grafana_contact_point/resource.tf", map[string]string{
"My Contact Point": name,
})

resource.ParallelTest(t, resource.TestCase{
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
// Creation
{
Config: config,
Check: resource.ComposeTestCheckFunc(
checkAlertingContactPointExistsWithLength("grafana_contact_point.my_contact_point", &points, 1),
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "name", name),
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "email.#", "1"),
),
},
// Delete the contact point and check that it is missing
{
PreConfig: func() {
client := grafanaTestClient()
for _, point := range points {
_, err := client.Provisioning.DeleteContactpoints(point.UID)
require.NoError(t, err)
}
},
Config: config,
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
// Recreate the contact point
{
Config: config,
Check: resource.ComposeTestCheckFunc(
checkAlertingContactPointExistsWithLength("grafana_contact_point.my_contact_point", &points, 1),
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "name", name),
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "email.#", "1"),
),
},
},
})
}

func TestAccContactPoint_empty(t *testing.T) {
testutils.CheckOSSTestsEnabled(t, ">=9.1.0")

Expand Down

0 comments on commit 8c78dfc

Please sign in to comment.