kubeprobes/query_test.go

45 lines
920 B
Go
Raw Permalink Normal View History

2023-07-21 23:12:18 +02:00
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)
)
2023-07-21 23:12:18 +02:00
tests := map[string]struct {
probes []ProbeFunction
expectedStatus bool
}{
"all green": {
probes: []ProbeFunction{probePassing},
2023-07-21 23:12:18 +02:00
expectedStatus: true,
},
"some failed": {
probes: []ProbeFunction{probePassing, probeFailing},
2023-07-21 23:12:18 +02:00
expectedStatus: false,
},
"all failed": {
probes: []ProbeFunction{probeFailing},
2023-07-21 23:12:18 +02:00
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)
2023-07-21 23:12:18 +02:00
}
})
}
}