kubeprobes/query_test.go
Piotr Icikowski d33e9f19ea
refactor(kubeprobes): refactor code
- refactored types, interfaces, options etc.
- added new options dedicated for `StatefulProbe`s
2024-03-01 23:32:11 +01:00

46 lines
1.0 KiB
Go

package kubeprobes
import (
"errors"
"testing"
"time"
)
func TestStatusQueryIsAllGreen(t *testing.T) {
tests := map[string]struct {
probes []ProbeFunction
expectedStatus bool
}{
"all green": {
probes: []ProbeFunction{
func() error { return nil },
func() error { time.Sleep(2 * time.Second); return nil },
},
expectedStatus: true,
},
"some failed": {
probes: []ProbeFunction{
func() error { return nil },
func() error { time.Sleep(2 * time.Second); return errors.New("failed") },
},
expectedStatus: false,
},
"all failed": {
probes: []ProbeFunction{
func() error { return errors.New("failed") },
func() error { time.Sleep(2 * time.Second); return errors.New("failed") },
},
expectedStatus: false,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
sq := newStatusQuery(test.probes)
if sq.isAllGreen() != test.expectedStatus {
t.Errorf("expected status %v, got %v", test.expectedStatus, sq.isAllGreen())
}
})
}
}