Piotr Icikowski
9dd25ff024
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
- `ProbeFunction` is now an interface for easier use - `ProbeFunction`s can be auto-updated with specified update interval - `StatefulProbes` changed into `ManualProbes` and implement `ProbeFunction` interface - `ManualProbes` allows for marking probe as unhealthy with custom cause - handlers now return JSON response with failed probes - handler's response can be set to verbose via `Kubeprobes` option or via `?v` request param BREAKING CHANGE: type definitions were replaced with more robust implementation.
45 lines
920 B
Go
45 lines
920 B
Go
package kubeprobes
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestStatusQueryIsAllGreen(t *testing.T) {
|
|
var (
|
|
probePassing, _ = NewProbeFunction("pass", func() error {
|
|
return nil
|
|
}, 0)
|
|
probeFailing, _ = NewProbeFunction("fail", func() error {
|
|
return errProbeFailed
|
|
}, 0)
|
|
)
|
|
|
|
tests := map[string]struct {
|
|
probes []ProbeFunction
|
|
expectedStatus bool
|
|
}{
|
|
"all green": {
|
|
probes: []ProbeFunction{probePassing},
|
|
expectedStatus: true,
|
|
},
|
|
"some failed": {
|
|
probes: []ProbeFunction{probePassing, probeFailing},
|
|
expectedStatus: false,
|
|
},
|
|
"all failed": {
|
|
probes: []ProbeFunction{probeFailing},
|
|
expectedStatus: false,
|
|
},
|
|
}
|
|
|
|
for name, test := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
sq := newStatusQuery(test.probes)
|
|
sq.wait()
|
|
if sq.ok != test.expectedStatus {
|
|
t.Errorf("expected status %v, got %v", test.expectedStatus, sq.ok)
|
|
}
|
|
})
|
|
}
|
|
}
|