Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Export StatefulProbe type
Browse files Browse the repository at this point in the history
  • Loading branch information
Icikowski committed Mar 6, 2022
1 parent ad80960 commit 1b1a9b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions probes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
Expand Down
14 changes: 8 additions & 6 deletions stateful_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,40 @@ 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
}

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

// 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()
Expand Down
6 changes: 3 additions & 3 deletions stateful_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ 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()
}
)

func TestStatefulProbe(t *testing.T) {
tests := map[string]struct {
probeTransformation func(*testing.T, *statefulProbe)
probeTransformation func(*testing.T, *StatefulProbe)
expectedError bool
}{
"mark as up": {
Expand Down

0 comments on commit 1b1a9b8

Please sign in to comment.