Skip to content

Commit

Permalink
remove variable test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
brookesargent committed Nov 25, 2024
1 parent c9f66ad commit af873b0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type NotificationRecipientDetails struct {

type WebhookPayloads struct {
PayloadTemplates PayloadTemplates `json:"payload_templates"`
TemplateVariables []TemplateVariable `json:"template_variables,omitempty"`
TemplateVariables []TemplateVariable `json:"template_variables"`
}

type PayloadTemplates struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/webhook_recipient_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ func (r *webhookRecipientResource) Update(ctx context.Context, req resource.Upda
state.Templates = plan.Templates
if rcpt.Details.WebhookPayloads.TemplateVariables != nil {
state.Variables = plan.Variables
} else {
state.Variables = types.SetNull(types.ObjectType{AttrTypes: models.TemplateVariableAttrType})
}
} else {
state.Templates = types.SetNull(types.ObjectType{AttrTypes: models.WebhookTemplateAttrType})
Expand Down
76 changes: 76 additions & 0 deletions internal/provider/webhook_recipient_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,82 @@ resource "honeycombio_webhook_recipient" "test" {
})
})

t.Run("custom webhook when a variable is removed", func(t *testing.T) {
name := test.RandomStringWithPrefix("test.", 20)
url := test.RandomURL()
body := `<<EOT
{
"name": " {{ .Name }}",
"id": " {{ .ID }}"
}
EOT`

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"
variable {
name = "severity"
default_value = "critical"
}
template {
type = "trigger"
body = %s
}
}`, name, url, body),
Check: resource.ComposeAggregateTestCheckFunc(
testAccEnsureRecipientExists(t, "honeycombio_webhook_recipient.test"),
resource.TestCheckResourceAttrSet("honeycombio_webhook_recipient.test", "id"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "name", name),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "url", url),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "template.#", "1"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "template.0.type", "trigger"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "variable.#", "1"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "variable.0.name", "severity"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "variable.0.default_value", "critical"),
resource.TestCheckNoResourceAttr("honeycombio_webhook_recipient.test", "secret"),
),
},
{
Config: fmt.Sprintf(`
resource "honeycombio_webhook_recipient" "test" {
name = "%s"
url = "%s"
secret = "so-secret"
template {
type = "trigger"
body = %s
}
}`, name, url, body),
Check: resource.ComposeAggregateTestCheckFunc(
testAccEnsureRecipientExists(t, "honeycombio_webhook_recipient.test"),
resource.TestCheckResourceAttrSet("honeycombio_webhook_recipient.test", "id"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "name", name),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "url", url),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "secret", "so-secret"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "template.#", "1"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "template.0.type", "trigger"),
resource.TestCheckResourceAttr("honeycombio_webhook_recipient.test", "variable.#", "0"),
),
},
{
ResourceName: "honeycombio_webhook_recipient.test",
ImportState: true,
},
},
})
})

t.Run("custom webhook validations error when they should", func(t *testing.T) {
name := test.RandomStringWithPrefix("test.", 20)
url := test.RandomURL()
Expand Down

0 comments on commit af873b0

Please sign in to comment.