Skip to content

Commit

Permalink
add test for duplicate error
Browse files Browse the repository at this point in the history
  • Loading branch information
brookesargent committed Nov 25, 2024
1 parent 1f9841f commit b837237
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/provider/webhook_recipient_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ func validateTemplateVarsNotDuplicated(ctx context.Context, data models.WebhookR
name := v.Name.ValueString()
if duplicateMap[name] {
resp.Diagnostics.AddAttributeError(
path.Root("template").AtListIndex(i).AtName("type"),
path.Root("template").AtListIndex(i).AtName("name"),
"Conflicting configuration arguments",
fmt.Sprintf("cannot have more than one \"variable\" with the name \"%s\"", name),
fmt.Sprintf("cannot have more than one \"variable\" with the same \"name\""),

Check failure on line 516 in internal/provider/webhook_recipient_resource.go

View workflow job for this annotation

GitHub Actions / Build

S1039: unnecessary use of fmt.Sprintf (gosimple)
)
}
duplicateMap[name] = true
Expand Down
31 changes: 31 additions & 0 deletions internal/provider/webhook_recipient_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,37 @@ resource "honeycombio_webhook_recipient" "test" {
},
},
})

resource.Test(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory,
CheckDestroy: testAccEnsureRecipientDestroyed(t),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "honeycombio_webhook_recipient" "test" {
name = "%s"
url = "%s"
template {
type = "trigger"
body = "body"
}
variable {
name = "severity"
default_value = "critical"
}
variable {
name = "severity"
default_value = "warning"
}
}`, name, url),
ExpectError: regexp.MustCompile(`cannot have more than one "variable" with the same "name"`),
},
},
})
})
}

Expand Down

0 comments on commit b837237

Please sign in to comment.