Skip to content

Commit

Permalink
Switch from gometalinter to golangci-lint
Browse files Browse the repository at this point in the history
The maintainer of gometalinter has deprecated its tool and advise now to
use golangci-lint instead. We can't use the latest version, because it's
not compatible with the current version of Go.

Use the shell script installer instead of `go get` as the authors of the
tool say in the README. It's faster and more reliable to download
directly the binary that build it in.
  • Loading branch information
Erouan50 committed Mar 16, 2020
1 parent dd9a162 commit 40c32ee
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
all: build

tools:
which gometalinter || ( go get -u github.com/alecthomas/gometalinter && gometalinter --install )
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.16.0
which glide || go get -u github.com/Masterminds/glide
which goveralls || go get github.com/mattn/goveralls

lint:
gometalinter --concurrency=1 --deadline=300s --vendor --disable-all \
./bin/golangci-lint run --concurrency=1 --disable-all \
--enable=golint \
--enable=vet \
--enable=vetshadow \
Expand All @@ -17,7 +17,6 @@ lint:
--enable=deadcode \
--enable=ineffassign \
--enable=dupl \
--enable=gotype \
--enable=varcheck \
--enable=interfacer \
--enable=goconst \
Expand All @@ -26,8 +25,7 @@ lint:
--enable=misspell \
--enable=gas \
--enable=goimports \
--enable=gocyclo \
./...
--enable=gocyclo

fmt:
go fmt ./...
Expand Down
2 changes: 1 addition & 1 deletion cmd/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRootCmd(t *testing.T) {
t.Errorf("Failed to execute the main command: %+v", err)
}
case <-time.After(time.Second):
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
syscall.Kill(syscall.Getpid(), syscall.SIGTERM) //nolint:errcheck - it's a test don't need to over check
case <-time.After(10 * time.Second):
t.Error("Timeout waiting for the execute command to exit after SIGTERM")
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/controllers/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand Down Expand Up @@ -107,9 +107,6 @@ func TestController(t *testing.T) {
n := new(count.Notifier)
cont := &testController{}
cont.Init(c, n)
if cont == nil {
t.Errorf("Failed to initialize a test pod controller")
}

wg := sync.WaitGroup{}
wg.Add(1)
Expand All @@ -127,7 +124,10 @@ func TestController(t *testing.T) {

// test deletion
store := cont.Informer.GetStore()
store.Delete(obj2)
err := store.Delete(obj2)
if err != nil {
t.Fatalf("Unexcepted error %v", err)
}
time.Sleep(config.FakeResyncInterval + config.FakeResyncInterval/2)

if n.Count() < 5 {
Expand All @@ -140,7 +140,10 @@ func TestController(t *testing.T) {
// test retries on notifiers failure
fnotif := new(failingNotifier)
cont.Notifiers = fnotif
store.Add(obj4)
err = store.Add(obj4)
if err != nil {
t.Fatalf("Unexcepted error %v", err)
}

time.Sleep(config.FakeResyncInterval + config.FakeResyncInterval/2)
if fnotif.countChange() < maxProcessRetry {
Expand Down
5 changes: 1 addition & 4 deletions pkg/controllers/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"k8s.io/api/apps/v1beta1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/bpineau/kube-deployments-notifier/config"
Expand All @@ -25,9 +25,6 @@ func TestDeployment(t *testing.T) {
notif := new(count.Notifier)
cont := new(Controller)
cont.Init(config.FakeConfig(obj1), notif)
if cont == nil {
t.Errorf("Failed to create a deployment controller")
}

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down
9 changes: 5 additions & 4 deletions pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,24 @@ func TestLog(t *testing.T) {
}

logger = New("info", "127.0.0.1:514", "syslog")
if fmt.Sprintf("%T", logger) != "*logrus.Logger" {
logrusLoggerPattern := "*logrus.Logger"
if fmt.Sprintf("%T", logger) != logrusLoggerPattern {
t.Error("Failed to instantiate a syslog logger")
}

logger = New("info", "", "stdout")
if fmt.Sprintf("%T", logger) != "*logrus.Logger" {
if fmt.Sprintf("%T", logger) != logrusLoggerPattern {
t.Error("Failed to instantiate a stdout logger")
}

logger = New("info", "", "stderr")
if fmt.Sprintf("%T", logger) != "*logrus.Logger" {
if fmt.Sprintf("%T", logger) != logrusLoggerPattern {
t.Error("Failed to instantiate a stderr logger")
}

for _, level := range levels {
lg := New(level, "", "test")
if fmt.Sprintf("%T", lg) != "*logrus.Logger" {
if fmt.Sprintf("%T", lg) != logrusLoggerPattern {
t.Errorf("Failed to instantiate at %s level", level)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"k8s.io/api/apps/v1beta1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/bpineau/kube-deployments-notifier/config"
Expand Down Expand Up @@ -61,6 +61,6 @@ func runFromConf(t *testing.T, conf *config.KdnConfig) {
t.Error("Timeout waiting for a event to pop up as a notification")
}

syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
time.Sleep(300 * time.Millisecond) // controllers wait for 200ms before stopping
syscall.Kill(syscall.Getpid(), syscall.SIGTERM) //nolint:errcheck - it's a test don't need to over check
time.Sleep(300 * time.Millisecond) // controllers wait for 200ms before stopping
}

0 comments on commit 40c32ee

Please sign in to comment.