2015-09-30 14:13:00 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/prometheus/alertmanager/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
var somethingConfig = `
|
|
|
|
routes:
|
|
|
|
- send_to: "default"
|
|
|
|
group_wait: 1s
|
|
|
|
group_interval: 1s
|
|
|
|
|
|
|
|
notification_configs:
|
|
|
|
- name: "default"
|
|
|
|
send_resolved: true
|
|
|
|
|
|
|
|
webhook_configs:
|
|
|
|
- url: 'http://localhost:8088'
|
|
|
|
`
|
|
|
|
|
|
|
|
func TestSomething(t *testing.T) {
|
2015-09-30 14:18:44 +00:00
|
|
|
// Create a new acceptance test that instantiates new Alertmanagers
|
|
|
|
// with the given configuration and verifies times with the given
|
|
|
|
// tollerance.
|
2015-09-30 14:13:00 +00:00
|
|
|
at := NewAcceptanceTest(t, &AcceptanceOpts{
|
|
|
|
Tolerance: 150 * time.Millisecond,
|
|
|
|
Config: somethingConfig,
|
|
|
|
})
|
|
|
|
|
2015-09-30 14:18:44 +00:00
|
|
|
// Create a new Alertmanager process listening to a random port
|
2015-09-30 14:13:00 +00:00
|
|
|
am := at.Alertmanager()
|
2015-09-30 14:18:44 +00:00
|
|
|
// Create a collector to which alerts can be written and verified
|
|
|
|
// against a set of expected alert notifications.
|
2015-09-30 14:13:00 +00:00
|
|
|
co := at.Collector("webhook")
|
|
|
|
|
2015-09-30 14:18:44 +00:00
|
|
|
// Run something that satisfies the webhook interface to which the
|
|
|
|
// Alertmanager pushes as defined by its configuration.
|
2015-09-30 14:13:00 +00:00
|
|
|
go NewWebhook(":8088", co).Run()
|
|
|
|
|
2015-09-30 14:18:44 +00:00
|
|
|
// Declare pushes to be made to the Alertmanager at the given time.
|
|
|
|
// Times are provided in fractions of seconds.
|
2015-09-30 14:13:00 +00:00
|
|
|
am.Push(At(1), Alert("alertname", "test").Active(1))
|
|
|
|
am.Push(At(3.5), Alert("alertname", "test").Active(1, 3))
|
|
|
|
|
2015-09-30 14:18:44 +00:00
|
|
|
// Declare which alerts are expected to arrive at the collector within
|
|
|
|
// the defined time intervals.
|
2015-09-30 14:13:00 +00:00
|
|
|
co.Want(Between(2, 2.5), Alert("alertname", "test").Active(1))
|
|
|
|
co.Want(Between(3, 3.5), Alert("alertname", "test").Active(1))
|
2015-09-30 15:35:33 +00:00
|
|
|
co.Want(Between(4, 4.5), Alert("alertname", "test").Active(1, 3))
|
2015-09-30 14:13:00 +00:00
|
|
|
|
2015-09-30 14:18:44 +00:00
|
|
|
// Start the flow as defined above and run the checks afterwards.
|
2015-09-30 14:13:00 +00:00
|
|
|
at.Run()
|
|
|
|
}
|