Skip to content

Commit a1472d2

Browse files
committed
Adding linters and makefile
Signed-off-by: Filip Petrov <lombert.p.v@gmail.com>
1 parent 1cf751c commit a1472d2

File tree

6 files changed

+59
-14
lines changed

6 files changed

+59
-14
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Make
2+
3+
.PHONY: all
4+
all: build lint test
5+
6+
.PHONY: build
7+
build:
8+
go build ./...
9+
10+
.PHONY: lint
11+
lint: $(GOLINT)
12+
golangci-lint run --fix --fast ${FileDir} -e "(\\w|\\s|\`)+\\w+(\`)? should be(\\w|\\s|\`)+" --skip-dirs=fake
13+
14+
.PHONY: test
15+
test:
16+
go test -race ./...
17+
18+
.PHONY: cover
19+
cover:
20+
go test -race -coverprofile=cover.out ./...
21+
go tool cover -html=cover.out -o cover.html

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ go 1.16
55
require (
66
github.com/stretchr/objx v0.3.0 // indirect
77
github.com/stretchr/testify v1.7.0 // indirect
8+
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
9+
golang.org/x/tools v0.1.0 // indirect
810
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
911
)

go.sum

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
1111
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1212
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1313
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
14+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
15+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
16+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
17+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
18+
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI=
19+
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
20+
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
21+
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
22+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
23+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
24+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
25+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
26+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
28+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
29+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
32+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
33+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
34+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
35+
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
36+
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
37+
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
38+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
39+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
40+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1441
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1542
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
1643
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/atesting/testing.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ func Spy(v interface{}, dependencies ...interface{}) {
3232
value := reflect.ValueOf(elemQueue.Value)
3333
queue.Remove(elemQueue)
3434
var elem reflect.Value
35-
switch value.Kind() {
36-
case reflect.Ptr:
35+
if value.Kind() == reflect.Ptr {
3736
elem = value.Elem()
3837
}
3938
for i := 0; i < elem.NumField(); i++ {

pkg/atesting/testing_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11+
const (
12+
fooName = "foo"
13+
barName = "bar"
14+
testFooName = "testFoo"
15+
testBarName = "testBar"
16+
)
17+
1118
type FooEr interface {
1219
Foo()
1320
}
@@ -55,50 +62,38 @@ type Baz struct {
5562
}
5663

5764
func TestSpyUnexportedStructPtr(t *testing.T) {
58-
fooName := "foo"
5965
pkg.Autowire(&Foo{Name: fooName})
60-
barName := "bar"
6166
pkg.Autowire(&Bar{Name: barName})
6267
tmpFooBar := &FooBarUnexported{}
6368
pkg.Autowire(tmpFooBar)
6469
assert.Equal(t, tmpFooBar.foo.Name, fooName)
6570
assert.Equal(t, tmpFooBar.bar.Name, barName)
66-
testFooName := "testFoo"
67-
testBarName := "testBar"
6871
atesting.Spy(tmpFooBar, &Foo{Name: testFooName}, &Bar{Name: testBarName})
6972
assert.Equal(t, tmpFooBar.foo.Name, testFooName)
7073
assert.Equal(t, tmpFooBar.bar.Name, testBarName)
7174
assert.Equal(t, 0, len(pkg.Close()))
7275
}
7376

7477
func TestSpyExportedStructPtr(t *testing.T) {
75-
fooName := "foo"
7678
pkg.Autowire(&Foo{Name: fooName})
77-
barName := "bar"
7879
pkg.Autowire(&Bar{Name: barName})
7980
tmpFooBar := &FooBar{}
8081
pkg.Autowire(tmpFooBar)
8182
assert.Equal(t, tmpFooBar.Foo.Name, fooName)
8283
assert.Equal(t, tmpFooBar.Bar.Name, barName)
83-
testFooName := "testFoo"
84-
testBarName := "testBar"
8584
atesting.Spy(tmpFooBar, &Foo{Name: testFooName}, &Bar{Name: testBarName})
8685
assert.Equal(t, tmpFooBar.Foo.Name, testFooName)
8786
assert.Equal(t, tmpFooBar.Bar.Name, testBarName)
8887
assert.Equal(t, 0, len(pkg.Close()))
8988
}
9089

9190
func TestSpyInterface(t *testing.T) {
92-
fooName := "foo"
9391
pkg.Autowire(&Foo{Name: fooName})
94-
barName := "bar"
9592
pkg.Autowire(&Bar{Name: barName})
9693
tmpBaz := &Baz{}
9794
pkg.Autowire(tmpBaz)
9895
assert.Equal(t, tmpBaz.MyFoo.(*Foo).Name, fooName)
9996
assert.Equal(t, tmpBaz.MyBaz.(*Bar).Name, barName)
100-
testFooName := "testFoo"
101-
testBarName := "testBar"
10297
atesting.Spy(tmpBaz, &Foo{Name: testFooName}, &Bar{Name: testBarName})
10398
assert.Equal(t, tmpBaz.MyFoo.(*Foo).Name, testFooName)
10499
assert.Equal(t, tmpBaz.MyBaz.(*Bar).Name, testBarName)

pkg/internal/fake/type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package fake holds test structs
12
package fake
23

34
// Passer represents interface

0 commit comments

Comments
 (0)