diff options
Diffstat (limited to 'internal/transporthealth/monitor_test.go')
| -rw-r--r-- | internal/transporthealth/monitor_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/transporthealth/monitor_test.go b/internal/transporthealth/monitor_test.go new file mode 100644 index 0000000..c5eb98d --- /dev/null +++ b/internal/transporthealth/monitor_test.go @@ -0,0 +1,30 @@ +package transporthealth + +import ( + "context" + "errors" + "testing" + "time" +) + +type checkerFunc func(context.Context) error + +func (f checkerFunc) Check(ctx context.Context) error { + return f(ctx) +} + +func TestProbeTracksReadiness(t *testing.T) { + var checkErr error + monitor := New(checkerFunc(func(context.Context) error { return checkErr }), time.Minute, time.Second) + + monitor.Probe(context.Background()) + if !monitor.Ready() { + t.Fatal("successful probe did not mark transport ready") + } + + checkErr = errors.New("transport unavailable") + monitor.Probe(context.Background()) + if monitor.Ready() { + t.Fatal("failed probe left transport ready") + } +} |
