Document example acceptance test scenario

This commit is contained in:
Fabian Reinartz 2015-09-30 16:18:44 +02:00
parent 4401bb1b82
commit f20f5dce42
1 changed files with 13 additions and 0 deletions

View File

@ -22,22 +22,35 @@ notification_configs:
` `
func TestSomething(t *testing.T) { func TestSomething(t *testing.T) {
// Create a new acceptance test that instantiates new Alertmanagers
// with the given configuration and verifies times with the given
// tollerance.
at := NewAcceptanceTest(t, &AcceptanceOpts{ at := NewAcceptanceTest(t, &AcceptanceOpts{
Tolerance: 150 * time.Millisecond, Tolerance: 150 * time.Millisecond,
Config: somethingConfig, Config: somethingConfig,
}) })
// Create a new Alertmanager process listening to a random port
am := at.Alertmanager() am := at.Alertmanager()
// Create a collector to which alerts can be written and verified
// against a set of expected alert notifications.
co := at.Collector("webhook") co := at.Collector("webhook")
// Run something that satisfies the webhook interface to which the
// Alertmanager pushes as defined by its configuration.
go NewWebhook(":8088", co).Run() go NewWebhook(":8088", co).Run()
// Declare pushes to be made to the Alertmanager at the given time.
// Times are provided in fractions of seconds.
am.Push(At(1), Alert("alertname", "test").Active(1)) am.Push(At(1), Alert("alertname", "test").Active(1))
am.Push(At(3.5), Alert("alertname", "test").Active(1, 3)) am.Push(At(3.5), Alert("alertname", "test").Active(1, 3))
// Declare which alerts are expected to arrive at the collector within
// the defined time intervals.
co.Want(Between(2, 2.5), Alert("alertname", "test").Active(1)) co.Want(Between(2, 2.5), Alert("alertname", "test").Active(1))
co.Want(Between(3, 3.5), Alert("alertname", "test").Active(1)) co.Want(Between(3, 3.5), Alert("alertname", "test").Active(1))
co.Want(Between(3.5, 4.5), Alert("alertname", "test").Active(1, 3)) co.Want(Between(3.5, 4.5), Alert("alertname", "test").Active(1, 3))
// Start the flow as defined above and run the checks afterwards.
at.Run() at.Run()
} }