2023-07-21 23:12:18 +02:00
|
|
|
package kubeprobes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStatusQueryIsAllGreen(t *testing.T) {
|
2024-03-02 23:55:28 +01:00
|
|
|
var (
|
2024-03-03 23:24:42 +01:00
|
|
|
probePassing, _ = NewProbe("pass", func() error {
|
2024-03-02 23:55:28 +01:00
|
|
|
return nil
|
|
|
|
}, 0)
|
2024-03-03 23:24:42 +01:00
|
|
|
probeFailing, _ = NewProbe("fail", func() error {
|
2024-03-02 23:55:28 +01:00
|
|
|
return errProbeFailed
|
|
|
|
}, 0)
|
|
|
|
)
|
|
|
|
|
2023-07-21 23:12:18 +02:00
|
|
|
tests := map[string]struct {
|
2024-03-03 23:24:42 +01:00
|
|
|
probes []Probe
|
2023-07-21 23:12:18 +02:00
|
|
|
expectedStatus bool
|
|
|
|
}{
|
|
|
|
"all green": {
|
2024-03-03 23:24:42 +01:00
|
|
|
probes: []Probe{probePassing},
|
2023-07-21 23:12:18 +02:00
|
|
|
expectedStatus: true,
|
|
|
|
},
|
|
|
|
"some failed": {
|
2024-03-03 23:24:42 +01:00
|
|
|
probes: []Probe{probePassing, probeFailing},
|
2023-07-21 23:12:18 +02:00
|
|
|
expectedStatus: false,
|
|
|
|
},
|
|
|
|
"all failed": {
|
2024-03-03 23:24:42 +01:00
|
|
|
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)
|
2024-03-02 23:55:28 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|