Skip to content

Commit

Permalink
trigger test
Browse files Browse the repository at this point in the history
  • Loading branch information
brookesargent committed Dec 20, 2024
1 parent 824305c commit c211fa7
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions internal/provider/trigger_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ func TestAcc_TriggerResource(t *testing.T) {
},
})
})

t.Run("trigger resource with custom webhook recipient", func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory,
Steps: []resource.TestStep{
{
Config: testAccConfigBasicTriggerTestWithWebhookRecip(dataset, name, "info"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccEnsureTriggerExists(t, "honeycombio_trigger.test"),
resource.TestCheckResourceAttr("honeycombio_trigger.test", "name", name),
resource.TestCheckResourceAttr("honeycombio_trigger.test", "frequency", "600"),
resource.TestCheckResourceAttr("honeycombio_trigger.test", "recipient.#", "1"),
resource.TestCheckResourceAttr("honeycombio_trigger.test", "threshold.0.exceeded_limit", "1"),
resource.TestCheckResourceAttrPair("honeycombio_trigger.test", "query_id", "honeycombio_query.test", "id"),
resource.TestCheckNoResourceAttr("honeycombio_trigger.test", "query_json"),
),
},
// then update the variable value from info -> critical
{
Config: testAccConfigBasicTriggerTestWithWebhookRecip(dataset, name, "critical"),
},
{
ResourceName: "honeycombio_trigger.test",
ImportStateIdPrefix: fmt.Sprintf("%v/", dataset),
ImportState: true,
},
},
})
})
}

// TestAcc_TriggerResourceUpgradeFromVersion014 is intended to test the migration
Expand Down Expand Up @@ -839,6 +869,77 @@ resource "honeycombio_trigger" "test" {
}`, dataset, name, pdseverity, email, pdKey, pdName)
}

func testAccConfigBasicTriggerTestWithWebhookRecip(dataset, name, varValue string) string {
tmplBody := `<<EOT
{
"name": " {{ .Name }}",
"id": " {{ .ID }}",
"description": " {{ .Description }}",
}
EOT`

return fmt.Sprintf(`
data "honeycombio_query_specification" "test" {
calculation {
op = "AVG"
column = "duration_ms"
}
time_range = 1200
}
resource "honeycombio_query" "test" {
dataset = "%[1]s"
query_json = data.honeycombio_query_specification.test.json
}
resource "honeycombio_webhook_recipient" "test" {
name = "test"
url = "http://example.com"
header {
name = "Authorization"
value = "Bearer abc123"
}
variable {
name = "severity"
default_value = "critical"
}
template {
type = "trigger"
body = %[4]s
}
}
resource "honeycombio_trigger" "test" {
name = "%[2]s"
dataset = "%[1]s"
description = "My nice description"
query_id = honeycombio_query.test.id
threshold {
op = ">"
value = 100
}
frequency = data.honeycombio_query_specification.test.time_range / 2
recipient {
id = honeycombio_webhook_recipient.test.id
notification_details {
variable {
name = "severity"
value = "%[3]s"
}
}
}
}`, dataset, name, varValue, tmplBody)
}

func testAccConfigBasicTriggerTest_QuerySpec(dataset, name, pdseverity string) string {
email := test.RandomEmail()
pdKey := test.RandomString(32)
Expand Down

0 comments on commit c211fa7

Please sign in to comment.