45 lines
872 B
Go
45 lines
872 B
Go
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)
|
|
)
|
|
|
|
tests := map[string]struct {
|
|
probes []Probe
|
|
expectedStatus bool
|
|
}{
|
|
"all green": {
|
|
probes: []Probe{probePassing},
|
|
expectedStatus: true,
|
|
},
|
|
"some failed": {
|
|
probes: []Probe{probePassing, probeFailing},
|
|
expectedStatus: false,
|
|
},
|
|
"all failed": {
|
|
probes: []Probe{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)
|
|
}
|
|
})
|
|
}
|
|
}
|