Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package healthcheck
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_Healthy(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
checks []*check
|
|
healthy bool
|
|
string string
|
|
}{
|
|
{
|
|
"should be healthy with handle for stringer output",
|
|
[]*check{{func(ctx context.Context) error { return nil }, &Meta{Label: "check01"}}},
|
|
true,
|
|
"PASS check01\n",
|
|
},
|
|
{
|
|
"should handle multiple healthy checks",
|
|
[]*check{
|
|
{func(ctx context.Context) error { return nil }, &Meta{Label: "check01"}},
|
|
{func(ctx context.Context) error { return nil }, &Meta{Label: "check02"}},
|
|
},
|
|
true,
|
|
"PASS check01\nPASS check02\n",
|
|
},
|
|
{
|
|
"should handle healthy and unhealthy checks",
|
|
[]*check{
|
|
{func(ctx context.Context) error { return nil }, &Meta{Label: "check01"}},
|
|
{func(ctx context.Context) error { return fmt.Errorf("x") }, &Meta{Label: "check02"}},
|
|
{func(ctx context.Context) error { return nil }, &Meta{Label: "check03"}},
|
|
},
|
|
false,
|
|
"PASS check01\nFAIL check02: x\nPASS check03\n",
|
|
},
|
|
{
|
|
"should handle labels",
|
|
[]*check{
|
|
{func(ctx context.Context) error { return nil }, &Meta{Label: "check01"}},
|
|
{func(ctx context.Context) error { return nil }, &Meta{Label: "Pretty check"}},
|
|
},
|
|
true,
|
|
"PASS check01\nPASS Pretty check\n",
|
|
},
|
|
{
|
|
"should handle empty check list",
|
|
[]*check{},
|
|
true,
|
|
"",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
a := assert.New(t)
|
|
r := (&checks{cc: tt.checks}).Run(context.Background())
|
|
a.Equal(tt.healthy, r.Healthy(), "healthy result failed")
|
|
a.Equal(tt.string, r.String(), "stringer output match failed")
|
|
})
|
|
}
|
|
}
|
|
|
|
// tested with
|
|
// go test -count 10 -race -run Test_DataRace ./pkg/healthcheck/...
|
|
func Test_DataRace(t *testing.T) {
|
|
hc := New()
|
|
|
|
go func() {
|
|
hc.Add(func(ctx context.Context) error { return nil }, "hc1")
|
|
hc.Add(func(ctx context.Context) error { return nil }, "hc2")
|
|
hc.Add(func(ctx context.Context) error { return nil }, "hc3")
|
|
}()
|
|
go hc.Run(context.Background())
|
|
|
|
}
|