Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated golang versions for CI #56

Merged
merged 10 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
jobs:
build:
docker:
- image: circleci/golang:1.15.6 # the primary container, where your job's commands are run
- image: circleci/golang:1.21.4 # the primary container, where your job's commands are run
# environment:
# GOPROXY: https://proxy.golang.org
steps:
Expand Down
50 changes: 24 additions & 26 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,71 @@ name: go-build
on: [ push, pull_request ]
jobs:
build:
name: build ( ${{ matrix.go }} ), test, lint
name: build ( ${{ matrix.go-version }} ), test, lint
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.15', '1.14', '1.13' ]
go: [ '1.19', '1.20', '1.21.x' ]
steps:
- name: Check out source code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- name: Build
env:
GOPROXY: "https://proxy.golang.org"
run: go build .

- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.20.0

- name: Run golangci-lint
run: golangci-lint run -E golint -E gosec -E gofmt
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
skip-go-installation: true

- name: Test
env:
GOPROXY: "https://proxy.golang.org"
run: go test -v -race -coverprofile=coverage.out ./...

- name: convert to lcov
if: ${{ matrix.go }} == '1.15'
if: ${{ matrix.go-version }} == '1.15'
run: |
go get -u github.com/jandelgado/gcov2lcov
gcov2lcov -infile=coverage.out -outfile=coverage.lcov
go install github.com/jandelgado/gcov2lcov@latest
$(go env GOPATH)/bin/gcov2lcov -infile=coverage.out -outfile=coverage.lcov

- name: Coveralls
uses: coverallsapp/github-action@master
if: ${{ matrix.go }} == '1.15'
if: ${{ matrix.go-version }} == '1.15'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
build-opencencus-check-listener:
name: build ( ${{ matrix.go }} ), test, lint for opencensus
name: build ( ${{ matrix.go-version }} ), test, lint for opencensus
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.15', '1.14', '1.13' ]
go: [ '1.19', '1.20', '1.21.x' ]
steps:
- name: Check out source code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.go-version }}

- name: Build
env:
GOPROXY: "https://proxy.golang.org"
run: cd opencensus && go build .

- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.20.0

- name: Run golangci-lint
run: cd opencensus && golangci-lint run -E golint -E gosec -E gofmt
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
skip-go-installation: true

- name: Test
env:
Expand Down
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Refer to golangci-lint's example config file for more options and information:
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml

run:
timeout: 5m
modules-download-mode: readonly

linters:
disable-all: true
enable:
- errcheck
- goimports
- revive
- govet
- staticcheck
- gosec
- gofmt

linters-settings:
revive:
severity: warning

issues:
exclude-use-default: false
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
6 changes: 6 additions & 0 deletions check_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@ type CheckListener interface {
OnCheckCompleted(name string, result Result)
}

// CheckListeners is a slice of check listeners
type CheckListeners []CheckListener

// OnCheckRegistered is called when the check with the specified name has registered.
// Result argument is for reporting the first run state of the check
func (c CheckListeners) OnCheckRegistered(name string, result Result) {
for _, listener := range c {
listener.OnCheckRegistered(name, result)
}
}

// OnCheckStarted is called when a check with the specified name has started
func (c CheckListeners) OnCheckStarted(name string) {
for _, listener := range c {
listener.OnCheckStarted(name)
}
}

// OnCheckCompleted is called when the check with the specified name has completed it's execution.
// The results are passed as an argument
func (c CheckListeners) OnCheckCompleted(name string, result Result) {
for _, listener := range c {
listener.OnCheckCompleted(name, result)
Expand Down
1 change: 1 addition & 0 deletions checks/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package checks

import (
"context"

gosundheit "github.com/AppsFlyer/go-sundheit"
)

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"
gosundheit "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
}
2 changes: 1 addition & 1 deletion http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

"github.com/AppsFlyer/go-sundheit"
gosundheit "github.com/AppsFlyer/go-sundheit"
)

const (
Expand Down
Loading