-
Notifications
You must be signed in to change notification settings - Fork 26
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
fix: alert rule and tests association #168
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
data "thousandeyes_agent" "amsterdam" { | ||
agent_name = "Amsterdam, Netherlands" | ||
} | ||
|
||
resource "thousandeyes_alert_rule" "test" { | ||
severity = "MAJOR" | ||
rule_name = "Agent To Server Alert Rule Test" | ||
alert_type = "End-to-End (Server)" | ||
expression = "((loss >= 50%) || (probDetail != \"\") || (avgLatency >= 200 ms))" | ||
minimum_sources = 2 | ||
rounds_violating_required = 3 | ||
rounds_violating_out_of = 4 | ||
} | ||
|
||
resource "thousandeyes_agent_to_server" "agent_to_server_test" { | ||
test_name = "Agent To Server Test" | ||
interval = 300 | ||
alerts_enabled = true | ||
server = "api.stg.thousandeyes.com" | ||
protocol = "TCP" | ||
port = 443 | ||
enabled = true | ||
bgp_measurements = true | ||
use_public_bgp = true | ||
mtu_measurements = true | ||
|
||
agents { | ||
agent_id = data.thousandeyes_agent.amsterdam.agent_id | ||
} | ||
|
||
alert_rules { | ||
rule_id = thousandeyes_alert_rule.test.id | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
data "thousandeyes_agent" "amsterdam" { | ||
agent_name = "Amsterdam, Netherlands" | ||
} | ||
|
||
resource "thousandeyes_alert_rule" "test" { | ||
severity = "MAJOR" | ||
rule_name = "Agent To Server Alert Rule Test" | ||
alert_type = "End-to-End (Server)" | ||
expression = "((loss >= 50%) || (probDetail != \"\") || (avgLatency >= 200 ms))" | ||
minimum_sources = 2 | ||
rounds_violating_required = 4 | ||
rounds_violating_out_of = 4 | ||
} | ||
|
||
resource "thousandeyes_agent_to_server" "agent_to_server_test" { | ||
test_name = "Agent To Server Test" | ||
interval = 300 | ||
alerts_enabled = true | ||
server = "api.stg.thousandeyes.com" | ||
protocol = "TCP" | ||
port = 443 | ||
enabled = true | ||
bgp_measurements = true | ||
use_public_bgp = true | ||
mtu_measurements = true | ||
|
||
agents { | ||
agent_id = data.thousandeyes_agent.amsterdam.agent_id | ||
} | ||
|
||
alert_rules { | ||
rule_id = thousandeyes_alert_rule.test.id | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package thousandeyes | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccThousandEyesAlertRule(t *testing.T) { | ||
var alertRuleResourceName = "thousandeyes_alert_rule.test" | ||
testCases := []struct { | ||
name string | ||
createResourceFile string | ||
updateResourceFile string | ||
checkDestroyFunction func(*terraform.State) error | ||
checkCreateFunc []resource.TestCheckFunc | ||
checkUpdateFunc []resource.TestCheckFunc | ||
}{ | ||
{ | ||
name: "test_association_maintained_after_alert_rule_update", | ||
createResourceFile: "acceptance_resources/alert_rule/create_test_with_alert_rule.tf", | ||
updateResourceFile: "acceptance_resources/alert_rule/update_alert_rule.tf", | ||
checkDestroyFunction: func(state *terraform.State) error { | ||
resourceList := []ResourceType{ | ||
{ | ||
Name: "Agent To Server Test", | ||
ResourceName: "thousandeyes_agent_to_server", | ||
GetResource: func(id int64) (interface{}, error) { | ||
return testClient.GetAgentServer(id) | ||
}}, | ||
{ | ||
Name: "Agent To Server Alert Rule Test", | ||
ResourceName: "thousandeyes_alert_rule", | ||
GetResource: func(id int64) (interface{}, error) { | ||
return testClient.GetAlertRule(id) | ||
}}, | ||
} | ||
return testAccCheckResourceDestroy(resourceList, state) | ||
}, | ||
checkCreateFunc: []resource.TestCheckFunc{ | ||
//alert rule is created | ||
//with 3 required violating rounds | ||
resource.TestCheckResourceAttr(alertRuleResourceName, "rounds_violating_required", "3"), | ||
}, | ||
checkUpdateFunc: []resource.TestCheckFunc{ | ||
//alert rule is updated | ||
//to 4 required violating rounds | ||
resource.TestCheckResourceAttr(alertRuleResourceName, "rounds_violating_required", "4"), | ||
//and the test association is maintained | ||
resource.TestCheckResourceAttr(alertRuleResourceName, "test_ids.#", "1"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to start adding some comments to these Acceptance tests - the ones that I created also do not have them and they should! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tried to reflect that in the test name but i guess i failed miserably 😅 |
||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
CheckDestroy: tc.checkDestroyFunction, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccThousandEyesAlertRuleConfig(tc.createResourceFile), | ||
Check: resource.ComposeTestCheckFunc(tc.checkCreateFunc...), | ||
}, | ||
{ | ||
Config: testAccThousandEyesAlertRuleConfig(tc.updateResourceFile), | ||
Check: resource.ComposeTestCheckFunc(tc.checkUpdateFunc...), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccThousandEyesAlertRuleConfig(testResource string) string { | ||
content, err := os.ReadFile(testResource) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return string(content) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, more ATs for this repo! 💪