mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-18 03:27:04 +00:00
Add acceptance test documentation
This commit is contained in:
parent
f29a380ec4
commit
83a0d68fc8
@ -19,6 +19,8 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AcceptanceTest provides declarative definition of given inputs and expected
|
||||||
|
// output of an Alertmanager setup.
|
||||||
type AcceptanceTest struct {
|
type AcceptanceTest struct {
|
||||||
*testing.T
|
*testing.T
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ type AcceptanceTest struct {
|
|||||||
actions map[float64][]func()
|
actions map[float64][]func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AcceptanceOpts defines configuration paramters for an acceptance test.
|
||||||
type AcceptanceOpts struct {
|
type AcceptanceOpts struct {
|
||||||
baseTime time.Time
|
baseTime time.Time
|
||||||
Tolerance time.Duration
|
Tolerance time.Duration
|
||||||
@ -37,14 +40,20 @@ type AcceptanceOpts struct {
|
|||||||
Config string
|
Config string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expandTime returns the absolute time for the relative time
|
||||||
|
// calculated from the test's base time.
|
||||||
func (opts *AcceptanceOpts) expandTime(rel float64) time.Time {
|
func (opts *AcceptanceOpts) expandTime(rel float64) time.Time {
|
||||||
return opts.baseTime.Add(time.Duration(rel * float64(time.Second)))
|
return opts.baseTime.Add(time.Duration(rel * float64(time.Second)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expandTime returns the relative time for the given time
|
||||||
|
// calculated from the test's base time.
|
||||||
func (opts *AcceptanceOpts) relativeTime(act time.Time) float64 {
|
func (opts *AcceptanceOpts) relativeTime(act time.Time) float64 {
|
||||||
return float64(act.Sub(opts.baseTime)) / float64(time.Second)
|
return float64(act.Sub(opts.baseTime)) / float64(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAcceptanceTest returns a new acceptance test with the base time
|
||||||
|
// set to the current time.
|
||||||
func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
|
func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
|
||||||
test := &AcceptanceTest{
|
test := &AcceptanceTest{
|
||||||
T: t,
|
T: t,
|
||||||
@ -56,6 +65,7 @@ func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
|
|||||||
return test
|
return test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// freeAddress returns a new listen address not currently in use.
|
||||||
func freeAddress() string {
|
func freeAddress() string {
|
||||||
// Let the OS allocate a free address, close it and hope
|
// Let the OS allocate a free address, close it and hope
|
||||||
// it is still free when starting Alertmanager.
|
// it is still free when starting Alertmanager.
|
||||||
@ -118,6 +128,7 @@ func (t *AcceptanceTest) Alertmanager() *Alertmanager {
|
|||||||
return am
|
return am
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collector returns a new collector bound to the test instance.
|
||||||
func (t *AcceptanceTest) Collector(name string) *Collector {
|
func (t *AcceptanceTest) Collector(name string) *Collector {
|
||||||
co := &Collector{
|
co := &Collector{
|
||||||
t: t.T,
|
t: t.T,
|
||||||
|
Loading…
Reference in New Issue
Block a user