Documentation ¶
Overview ¶
Package livetest implements a set of helpers that ease writing of a sidecar that tests the functions of a service.
Assuring the functional correctness of a service is an important task for a production grade system. This package aims to provide helpers that allow a go test like experience for building functional health tests in production.
Test functions need to be written similarly to the regular go test function format. Only difference is the use of the testing.TB interface.
If a test failed, all other tests are still executed. So tests should not build on each other. Sub tests should be used for that purpose.
The result for the tests is exposed via prometheus metrics.
The interval is configured using PACE_LIVETEST_INTERVAL (duration format).
Index ¶
- Variables
- func Test(ctx context.Context, tests []TestFunc) error
- type T
- func (t *T) Context() context.Context
- func (t *T) Error(args ...interface{})
- func (t *T) Errorf(format string, args ...interface{})
- func (t *T) Fail()
- func (t *T) FailNow()
- func (t *T) Failed() bool
- func (t *T) Fatal(args ...interface{})
- func (t *T) Fatalf(format string, args ...interface{})
- func (t *T) Log(args ...interface{})
- func (t *T) Logf(format string, args ...interface{})
- func (t *T) Name() string
- func (t *T) Skip(args ...interface{})
- func (t *T) SkipNow()
- func (t *T) Skipf(format string, args ...interface{})
- func (t *T) Skipped() bool
- type TestFunc
- type TestState
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFailNow = errors.New("failed test")
ErrFailNow is used as a panic if ErrFailNow is called on the test
var ErrSkipNow = errors.New("skipped test")
ErrSkipNow is used as a panic if ErrSkipNow is called on the test
Functions ¶
func Test ¶
Test executes the passed tests in the given order (array order). The tests are executed in the configured interval until the given context is done.
Example ¶
package main import ( "context" "log" "time" "github.com/pace/bricks/test/livetest" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100) defer cancel() err := livetest.Test(ctx, []livetest.TestFunc{ func(t *livetest.T) { t.Logf("Executed test no %d", 1) }, func(t *livetest.T) { t.Log("Executed test no 2") }, func(t *livetest.T) { t.Fatal("Fail test no 3") }, func(t *livetest.T) { t.Fatalf("Fail test no %d", 4) }, func(t *livetest.T) { t.Skip("Skipping test no 5") }, func(t *livetest.T) { t.Skipf("Skipping test no %d", 5) }, func(t *livetest.T) { t.SkipNow() }, func(t *livetest.T) { t.Fail() }, func(t *livetest.T) { t.FailNow() }, func(t *livetest.T) { t.Error("Some") }, func(t *livetest.T) { t.Errorf("formatted") }, }) if err != context.DeadlineExceeded { log.Fatal(err) } }
Output:
Types ¶
type T ¶
type T struct {
// contains filtered or unexported fields
}
T implements a similar interface than testing.T
func NewTestProxy ¶
NewTestProxy creates a new text proxy using the given context and name.
func (*T) Context ¶
Context returns the livetest context. Useful for passing timeout and/or logging constraints from the test executor to the individual case
func (*T) FailNow ¶
func (t *T) FailNow()
FailNow marks the test as failed and skips further execution
func (*T) Fatal ¶
func (t *T) Fatal(args ...interface{})
Fatal logs the passed message in the context of the test and fails the test
func (*T) Log ¶
func (t *T) Log(args ...interface{})
Log logs the passed message in the context of the test
func (*T) Skip ¶
func (t *T) Skip(args ...interface{})
Skip logs reason and marks the test as skipped
type TestFunc ¶
type TestFunc func(t *T)
TestFunc represents a single test (possibly with sub tests)