Skip to content

Commit 6c7fbea

Browse files
Alerting: Fix TestAccNotificationPolicy_error test
1 parent 22eeef4 commit 6c7fbea

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

internal/resources/grafana/resource_alerting_notification_policy_test.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,39 @@ func TestAccNotificationPolicy_disableProvenance(t *testing.T) {
205205
}
206206

207207
func TestAccNotificationPolicy_error(t *testing.T) {
208-
testutils.CheckOSSTestsEnabled(t, ">=9.1.0")
208+
testCases := []struct {
209+
versionConstraint string
210+
errorMessage string
211+
}{
212+
{
213+
versionConstraint: ">=9.1.0,<11.4.0",
214+
errorMessage: "400.+invalid object specification: receiver 'invalid' does not exist",
215+
},
216+
{
217+
versionConstraint: ">=11.4.0",
218+
errorMessage: "400.+Invalid format of the submitted route: receiver 'invalid' does not exist",
219+
},
220+
}
209221

210-
resource.Test(t, resource.TestCase{
211-
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
212-
Steps: []resource.TestStep{
213-
{
214-
Config: `resource "grafana_notification_policy" "test" {
222+
for _, tc := range testCases {
223+
t.Run(tc.versionConstraint, func(t *testing.T) {
224+
testutils.CheckOSSTestsEnabled(t, tc.versionConstraint)
225+
226+
resource.Test(t, resource.TestCase{
227+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
228+
Steps: []resource.TestStep{
229+
{
230+
Config: `resource "grafana_notification_policy" "test" {
215231
group_by = ["..."]
216232
contact_point = "invalid"
217233
}`,
218-
// This tests that the API error message is propagated to the user.
219-
ExpectError: regexp.MustCompile("400.+invalid object specification: receiver 'invalid' does not exist"),
220-
},
221-
},
222-
})
234+
// This tests that the API error message is propagated to the user.
235+
ExpectError: regexp.MustCompile(tc.errorMessage),
236+
},
237+
},
238+
})
239+
})
240+
}
223241
}
224242

225243
func TestAccNotificationPolicy_inOrg(t *testing.T) {

0 commit comments

Comments
 (0)