Skip to content

Commit

Permalink
Fixed golangci issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eranharel committed Dec 5, 2023
1 parent 5d64377 commit 115a62d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BIN_DIR := $(GOPATH)/bin
BIN_DIR := ./bin
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint

all: build lint test
Expand All @@ -8,11 +8,11 @@ build:
go build -v

$(GOLANGCI_LINT):
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.20.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.55.2

lint: $(GOLANGCI_LINT)
##### linting #####
golangci-lint run -E golint -E gosec -E gofmt
$(GOLANGCI_LINT) run -E revive -E gosec -E gofmt

test: build
##### testing #####
Expand Down
3 changes: 2 additions & 1 deletion checks/must.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import gosundheit "github.com/AppsFlyer/go-sundheit"

// Must is a helper that wraps a call to a function returning (gosundheit.Check, error) and panics if the error is non-nil.
// It is intended for use in check initializations such as
// c := checks.Must(checks.NewHTTPCheck(/*...*/))
//
// c := checks.Must(checks.NewHTTPCheck(/*...*/))
func Must(check gosundheit.Check, err error) gosundheit.Check {
if err != nil {
panic(err)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ go 1.15

require (
github.com/fortytw2/leaktest v1.3.0
github.com/kr/pretty v0.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.6.1
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
10 changes: 7 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
36 changes: 18 additions & 18 deletions health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

. "github.com/AppsFlyer/go-sundheit"
"github.com/AppsFlyer/go-sundheit"
"github.com/AppsFlyer/go-sundheit/checks"
"github.com/AppsFlyer/go-sundheit/test/helper"
)
Expand All @@ -27,7 +27,7 @@ const (
)

func TestHealthWithEmptySetup(t *testing.T) {
h := New()
h := gosundheit.New()

assert.True(t, h.IsHealthy(), "empty health")

Expand All @@ -39,7 +39,7 @@ func TestHealthWithEmptySetup(t *testing.T) {
}

func TestHealthWithBogusCheck(t *testing.T) {
h := New()
h := gosundheit.New()

err := h.RegisterCheck(nil)
defer h.DeregisterAll()
Expand All @@ -53,7 +53,7 @@ func TestHealthWithBogusCheck(t *testing.T) {
}

func TestRegisterCheckValidations(t *testing.T) {
h := New()
h := gosundheit.New()
defer h.DeregisterAll()

// should return an error for nil check
Expand All @@ -63,7 +63,7 @@ func TestRegisterCheckValidations(t *testing.T) {
// Should return an error for missing execution period
assert.EqualError(t, h.RegisterCheck(&checks.CustomCheck{CheckName: "non-empty"}), "execution period must be greater than 0")

hWithExecPeriod := New(ExecutionPeriod(1 * time.Minute))
hWithExecPeriod := gosundheit.New(gosundheit.ExecutionPeriod(1 * time.Minute))
defer hWithExecPeriod.DeregisterAll()

// should inherit the execution period from the health instance
Expand All @@ -75,7 +75,7 @@ func TestRegisterDeregister(t *testing.T) {
leaktest.Check(t)

checkWaiter := helper.NewCheckWaiter()
h := New(WithCheckListeners(checkWaiter))
h := gosundheit.New(gosundheit.WithCheckListeners(checkWaiter))

registerCheck(h, failingCheckName, false, false)
registerCheck(h, passingCheckName, true, false)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestRegisterDeregister(t *testing.T) {
assert.Empty(t, results, "results after stop")
}

func registerCheck(h Health, name string, passing bool, initiallyPassing bool) {
func registerCheck(h gosundheit.Health, name string, passing bool, initiallyPassing bool) {
i := 0
checkFunc := func(ctx context.Context) (details interface{}, err error) {
i++
Expand All @@ -165,9 +165,9 @@ func registerCheck(h Health, name string, passing bool, initiallyPassing bool) {
CheckName: name,
CheckFunc: checkFunc,
},
InitialDelay(20*time.Millisecond),
ExecutionPeriod(20*time.Millisecond),
InitiallyPassing(initiallyPassing),
gosundheit.InitialDelay(20*time.Millisecond),
gosundheit.ExecutionPeriod(20*time.Millisecond),
gosundheit.InitiallyPassing(initiallyPassing),
)
}

Expand All @@ -180,7 +180,7 @@ func TestCheckListener(t *testing.T) {
listenerMock.On("OnCheckStarted", passingCheckName).Return()
listenerMock.On("OnCheckCompleted", failingCheckName, mock.AnythingOfType("Result")).Return()
listenerMock.On("OnCheckCompleted", passingCheckName, mock.AnythingOfType("Result")).Return()
h := New(WithCheckListeners(listenerMock, checkWaiter))
h := gosundheit.New(gosundheit.WithCheckListeners(listenerMock, checkWaiter))

registerCheck(h, failingCheckName, false, false)
registerCheck(h, passingCheckName, true, false)
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestCheckListener(t *testing.T) {

func TestHealthListeners(t *testing.T) {
listenerMock := newHealthListenerMock()
h := New(WithHealthListeners(listenerMock))
h := gosundheit.New(gosundheit.WithHealthListeners(listenerMock))

registerCheck(h, failingCheckName, false, false)
defer h.DeregisterAll()
Expand All @@ -235,18 +235,18 @@ type checkListenerMock struct {

type completedCheck struct {
name string
res Result
res gosundheit.Result
}

func (l *checkListenerMock) OnCheckRegistered(name string, result Result) {
func (l *checkListenerMock) OnCheckRegistered(name string, result gosundheit.Result) {
l.Called(name, result)
}

func (l *checkListenerMock) OnCheckStarted(name string) {
l.Called(name)
}

func (l *checkListenerMock) OnCheckCompleted(name string, res Result) {
func (l *checkListenerMock) OnCheckCompleted(name string, res gosundheit.Result) {
l.lock.Lock()
defer l.lock.Unlock()

Expand All @@ -255,15 +255,15 @@ func (l *checkListenerMock) OnCheckCompleted(name string, res Result) {
}

type healthListenerMock struct {
completedChan chan map[string]Result
completedChan chan map[string]gosundheit.Result
}

func newHealthListenerMock() *healthListenerMock {
return &healthListenerMock{
completedChan: make(chan map[string]Result),
completedChan: make(chan map[string]gosundheit.Result),
}
}

func (l *healthListenerMock) OnResultsUpdated(results map[string]Result) {
func (l *healthListenerMock) OnResultsUpdated(results map[string]gosundheit.Result) {
l.completedChan <- results
}

0 comments on commit 115a62d

Please sign in to comment.