kubeprobes/probe_manual_test.go

47 lines
996 B
Go
Raw Normal View History

package kubeprobes
import "testing"
var (
markAsDown func(*testing.T, ManualProbe) = func(t *testing.T, sp ManualProbe) {
t.Helper()
sp.Fail()
}
markAsUp func(*testing.T, ManualProbe) = func(t *testing.T, sp ManualProbe) {
t.Helper()
sp.Pass()
}
)
func TestManualProbe(t *testing.T) {
tests := map[string]struct {
probeTransformation func(*testing.T, ManualProbe)
expectedError bool
}{
"mark as up": {
probeTransformation: markAsUp,
expectedError: false,
},
"mark as down": {
probeTransformation: markAsDown,
expectedError: true,
},
}
for name, tc := range tests {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
sp, _ := NewManualProbe("some name")
tc.probeTransformation(t, sp)
err := sp.status()
switch {
case err == nil && tc.expectedError:
t.Error("expected error, but no error was returned")
case err != nil && !tc.expectedError:
t.Errorf("expected no error but got %v", err)
}
})
}
}