kubeprobes/query_test.go
Piotr Icikowski 8dc7f27400
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
refactor(probes): rename ProbeFunction to Probe
2024-03-03 23:25:56 +01:00

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)
}
})
}
}