diff --git a/probes_test.go b/probes_test.go index 4146aaf..a55a591 100644 --- a/probes_test.go +++ b/probes_test.go @@ -19,8 +19,8 @@ func TestKubeprobes(t *testing.T) { live, ready := NewStatefulProbe(), NewStatefulProbe() tests := map[string]struct { - livenessProbeTransformation func(*testing.T, *statefulProbe) - readinessProbeTransformation func(*testing.T, *statefulProbe) + livenessProbeTransformation func(*testing.T, *StatefulProbe) + readinessProbeTransformation func(*testing.T, *StatefulProbe) expectedLiveStatus int expectedReadyStatus int }{ diff --git a/stateful_probe.go b/stateful_probe.go index 9aca112..fba59b7 100644 --- a/stateful_probe.go +++ b/stateful_probe.go @@ -7,7 +7,9 @@ import ( var errProbeDown = errors.New("DOWN") -type statefulProbe struct { +// StatefulProbe represents the simple probe that can be either +// marked as "up" (healthy) or "down" (unhealthy). +type StatefulProbe struct { status bool mux sync.Mutex } @@ -15,22 +17,22 @@ type statefulProbe struct { // NewStatefulProbe returns a new instance of a stateful probe // which can be either marked as "up" (healthy) or "down" (unhealthy). // The probe is initially marked as "down". -func NewStatefulProbe() *statefulProbe { - return &statefulProbe{ +func NewStatefulProbe() *StatefulProbe { + return &StatefulProbe{ status: false, mux: sync.Mutex{}, } } // MarkAsUp marks the probe as healthy -func (sp *statefulProbe) MarkAsUp() { +func (sp *StatefulProbe) MarkAsUp() { sp.mux.Lock() defer sp.mux.Unlock() sp.status = true } // MarkAsDown marks the probe as unhealthy -func (sp *statefulProbe) MarkAsDown() { +func (sp *StatefulProbe) MarkAsDown() { sp.mux.Lock() defer sp.mux.Unlock() sp.status = false @@ -38,7 +40,7 @@ func (sp *statefulProbe) MarkAsDown() { // GetProbeFunction returns a function that can be used to check // whether the probe is healthy or not. -func (sp *statefulProbe) GetProbeFunction() ProbeFunction { +func (sp *StatefulProbe) GetProbeFunction() ProbeFunction { return func() error { sp.mux.Lock() defer sp.mux.Unlock() diff --git a/stateful_probe_test.go b/stateful_probe_test.go index dc001c2..2d45ac2 100644 --- a/stateful_probe_test.go +++ b/stateful_probe_test.go @@ -3,11 +3,11 @@ package kubeprobes import "testing" var ( - markAsDown func(*testing.T, *statefulProbe) = func(t *testing.T, sp *statefulProbe) { + markAsDown func(*testing.T, *StatefulProbe) = func(t *testing.T, sp *StatefulProbe) { t.Helper() sp.MarkAsDown() } - markAsUp func(*testing.T, *statefulProbe) = func(t *testing.T, sp *statefulProbe) { + markAsUp func(*testing.T, *StatefulProbe) = func(t *testing.T, sp *StatefulProbe) { t.Helper() sp.MarkAsUp() } @@ -15,7 +15,7 @@ var ( func TestStatefulProbe(t *testing.T) { tests := map[string]struct { - probeTransformation func(*testing.T, *statefulProbe) + probeTransformation func(*testing.T, *StatefulProbe) expectedError bool }{ "mark as up": {