Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address: Unable to switch off alert grouping on a service #527

Conversation

imjaroiswebdev
Copy link
Contributor

@imjaroiswebdev imjaroiswebdev commented Jun 10, 2022

Addressing #520

With this fix the Provider will not crash when trying to switch off alert grouping on a service, and also it will accept an interface more alike with the API and GUI.

Tests result:
Screen Shot 2022-06-10 at 18 44 36

@imjaroiswebdev imjaroiswebdev force-pushed the issue-520-uable-swoff-alert-grouping branch from 0714106 to 6b59244 Compare June 10, 2022 22:49
@imjaroiswebdev imjaroiswebdev marked this pull request as ready for review June 10, 2022 23:00
Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! That util function will be useful! 👍 🌮 🎉

@stmcallister stmcallister merged commit c4a592d into PagerDuty:master Jun 17, 2022
"pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"),
),
ExpectNonEmptyPlan: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should not be used in this test. It prevents detecting changes in the API response from what is expected.

resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_grouping", "rules"),
resource.TestCheckNoResourceAttr(
"pagerduty_service.foo", "alert_grouping_parameters.0.config"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this check does not work as expected. Newer versions of the terraform SDK reject this:

=== RUN   TestAccPagerDutyService_AlertContentGrouping
    resource_pagerduty_service_test.go:206: Step 2/2 error: Check failed: Check 8/12 error: pagerduty_service.foo: list or set attribute 'alert_grouping_parameters.0.config' must be checked by element count key (alert_grouping_parameters.0.config.#) or element value keys (e.g. alert_grouping_parameters.0.config.0). Set element value checks should use TestCheckTypeSet functions instead.
--- FAIL: TestAccPagerDutyService_AlertContentGrouping (13.98s)

See #525 (comment)

Changing it to the recommended way reveals an issue:

diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go
index 7cda1e3d..dceef04a 100644
--- a/pagerduty/resource_pagerduty_service_test.go
+++ b/pagerduty/resource_pagerduty_service_test.go
@@ -254,8 +254,8 @@ func TestAccPagerDutyService_AlertContentGrouping(t *testing.T) {
                                                "pagerduty_service.foo", "alert_creation", "create_alerts_and_incidents"),
                                        resource.TestCheckResourceAttr(
                                                "pagerduty_service.foo", "alert_grouping", "rules"),
-                                       resource.TestCheckNoResourceAttr(
-                                               "pagerduty_service.foo", "alert_grouping_parameters.0.config"),
+                                       resource.TestCheckResourceAttr(
+                                               "pagerduty_service.foo", "alert_grouping_parameters.0.config.#", "0"),
                                        resource.TestCheckResourceAttr(
                                                "pagerduty_service.foo", "alert_grouping_parameters.0.type", ""),
                                        resource.TestCheckResourceAttr(

=>

make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_AlertContentGrouping'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_AlertContentGrouping -timeout 120m
=== RUN   TestAccPagerDutyService_AlertContentGrouping
    resource_pagerduty_service_test.go:206: Step 2/2 error: Check failed: Check 8/12 error: pagerduty_service.foo: Attribute 'alert_grouping_parameters.0.config.#' expected "0", got "1"
--- FAIL: TestAccPagerDutyService_AlertContentGrouping (14.80s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   14.813s
FAIL
make: *** [GNUmakefile:17: testacc] Error 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted #532 to replicate the issue.

Copy link
Contributor

@pdecat pdecat Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants