Skip to content

Commit

Permalink
test: change alert_profile test to read element from alerts by name (#…
Browse files Browse the repository at this point in the history
…412)

* test: change alert_profile test to read element from alerts by name

Signed-off-by: Darren Murray <darren.murray@lacework.net>
  • Loading branch information
dmurray-lacework authored Nov 16, 2022
1 parent 2cd1ff6 commit e9ce33a
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions integration/resource_lacework_alert_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/lacework/go-sdk/api"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -31,11 +32,13 @@ func TestAlertProfileCreate(t *testing.T) {
actualExtends := terraform.Output(t, terraformOptions, "extends")
actualDescription := terraform.Output(t, terraformOptions, "alert_description")

alert := getAlert(createProps.Data.Alerts, "LW Configuration GCP Violation Alert")

assert.Equal(t, "LW_CFG_GCP_DEFAULT_PROFILE", createProps.Data.Extends)
assert.Equal(t, "{{_OCCURRENCE}} violation for GCP Resource {{RESOURCE_TYPE}}:{{RESOURCE_ID}} in project {{PROJECT_ID}} region {{RESOURCE_REGION}}", createProps.Data.Alerts[0].Description)
assert.Equal(t, "Violation", createProps.Data.Alerts[0].Name)
assert.Equal(t, "LW Configuration GCP Violation Alert", createProps.Data.Alerts[0].EventName)
assert.Equal(t, "{{_OCCURRENCE}} violation detected in project {{PROJECT_ID}}", createProps.Data.Alerts[0].Subject)
assert.Equal(t, "{{_OCCURRENCE}} violation for GCP Resource {{RESOURCE_TYPE}}:{{RESOURCE_ID}} in project {{PROJECT_ID}} region {{RESOURCE_REGION}}", alert.Description)
assert.Equal(t, "Violation", alert.Name)
assert.Equal(t, "LW Configuration GCP Violation Alert", alert.EventName)
assert.Equal(t, "{{_OCCURRENCE}} violation detected in project {{PROJECT_ID}}", alert.Subject)

assert.Equal(t, "CUSTOM_PROFILE_TERRAFORM_TEST", actualID)
assert.Equal(t, "LW_CFG_GCP_DEFAULT_PROFILE", actualExtends)
Expand All @@ -53,11 +56,13 @@ func TestAlertProfileCreate(t *testing.T) {
actualExtends = terraform.Output(t, terraformOptions, "extends")
actualDescription = terraform.Output(t, terraformOptions, "alert_description")

alert = getAlert(updateProps.Data.Alerts, "LW Configuration GCP Violation Alert")

assert.Equal(t, "LW_CFG_GCP_DEFAULT_PROFILE", updateProps.Data.Extends)
assert.Equal(t, "{{_OCCURRENCE}} violation for GCP Resource {{RESOURCE_TYPE}}:{{RESOURCE_ID}} in project {{PROJECT_ID}} region {{RESOURCE_REGION}} Updated", updateProps.Data.Alerts[0].Description)
assert.Equal(t, "Violation", updateProps.Data.Alerts[0].Name)
assert.Equal(t, "LW Configuration GCP Violation Alert", updateProps.Data.Alerts[0].EventName)
assert.Equal(t, "{{_OCCURRENCE}} violation detected in project {{PROJECT_ID}}", updateProps.Data.Alerts[0].Subject)
assert.Equal(t, "{{_OCCURRENCE}} violation for GCP Resource {{RESOURCE_TYPE}}:{{RESOURCE_ID}} in project {{PROJECT_ID}} region {{RESOURCE_REGION}} Updated", alert.Description)
assert.Equal(t, "Violation", alert.Name)
assert.Equal(t, "LW Configuration GCP Violation Alert", alert.EventName)
assert.Equal(t, "{{_OCCURRENCE}} violation detected in project {{PROJECT_ID}}", alert.Subject)

assert.Equal(t, "LW_CFG_GCP_DEFAULT_PROFILE", actualExtends)
assert.Equal(t, "{{_OCCURRENCE}} violation for GCP Resource {{RESOURCE_TYPE}}:{{RESOURCE_ID}} in project {{PROJECT_ID}} region {{RESOURCE_REGION}} Updated", actualDescription)
Expand All @@ -78,3 +83,13 @@ func TestAlertProfileValidate(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, msg, "expected value of name to not start with any of \"LW_\"")
}

func getAlert(alerts []api.AlertTemplate, name string) api.AlertTemplate {
var alert api.AlertTemplate
for _, a := range alerts {
if a.EventName == name {
return a
}
}
return alert
}

0 comments on commit e9ce33a

Please sign in to comment.