Add acceptance test documentation

This commit is contained in:
Fabian Reinartz 2015-10-02 12:32:19 +02:00
parent f29a380ec4
commit 83a0d68fc8
1 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,8 @@ import (
"golang.org/x/net/context"
)
// AcceptanceTest provides declarative definition of given inputs and expected
// output of an Alertmanager setup.
type AcceptanceTest struct {
*testing.T
@ -30,6 +32,7 @@ type AcceptanceTest struct {
actions map[float64][]func()
}
// AcceptanceOpts defines configuration paramters for an acceptance test.
type AcceptanceOpts struct {
baseTime time.Time
Tolerance time.Duration
@ -37,14 +40,20 @@ type AcceptanceOpts struct {
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 {
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 {
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 {
test := &AcceptanceTest{
T: t,
@ -56,6 +65,7 @@ func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
return test
}
// freeAddress returns a new listen address not currently in use.
func freeAddress() string {
// Let the OS allocate a free address, close it and hope
// it is still free when starting Alertmanager.
@ -118,6 +128,7 @@ func (t *AcceptanceTest) Alertmanager() *Alertmanager {
return am
}
// Collector returns a new collector bound to the test instance.
func (t *AcceptanceTest) Collector(name string) *Collector {
co := &Collector{
t: t.T,