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.
47 lines
996 B
Go
47 lines
996 B
Go
package kubeprobes
|
|
|
|
import "testing"
|
|
|
|
var (
|
|
markAsDown func(*testing.T, ManualProbe) = func(t *testing.T, sp ManualProbe) {
|
|
t.Helper()
|
|
sp.Fail()
|
|
}
|
|
markAsUp func(*testing.T, ManualProbe) = func(t *testing.T, sp ManualProbe) {
|
|
t.Helper()
|
|
sp.Pass()
|
|
}
|
|
)
|
|
|
|
func TestManualProbe(t *testing.T) {
|
|
tests := map[string]struct {
|
|
probeTransformation func(*testing.T, ManualProbe)
|
|
expectedError bool
|
|
}{
|
|
"mark as up": {
|
|
probeTransformation: markAsUp,
|
|
expectedError: false,
|
|
},
|
|
"mark as down": {
|
|
probeTransformation: markAsDown,
|
|
expectedError: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range tests {
|
|
name, tc := name, tc
|
|
t.Run(name, func(t *testing.T) {
|
|
sp, _ := NewManualProbe("some name")
|
|
tc.probeTransformation(t, sp)
|
|
err := sp.status()
|
|
|
|
switch {
|
|
case err == nil && tc.expectedError:
|
|
t.Error("expected error, but no error was returned")
|
|
case err != nil && !tc.expectedError:
|
|
t.Errorf("expected no error but got %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|