kubeprobes/query_test.go

45 lines
872 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, _ = NewProbe("pass", func() error {
return nil
}, 0)
probeFailing, _ = NewProbe("fail", func() error {
return errProbeFailed
}, 0)
)
2023-07-21 23:12:18 +02:00
tests := map[string]struct {
probes []Probe
2023-07-21 23:12:18 +02:00
expectedStatus bool
}{
"all green": {
probes: []Probe{probePassing},
2023-07-21 23:12:18 +02:00
expectedStatus: true,
},
"some failed": {
probes: []Probe{probePassing, probeFailing},
2023-07-21 23:12:18 +02:00
expectedStatus: false,
},
"all failed": {
probes: []Probe{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
}
})
}
}