Skip to content

Commit

Permalink
Stricter linting (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
okokes-akamai authored Jan 3, 2024
1 parent 2520087 commit 83868ae
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 152 deletions.
50 changes: 31 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
run:
timeout: 5m

linters:
disable-all: true
enable:
# these are enabled by default
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
# cherry picked from https://golangci-lint.run/usage/linters/
# - ginkgolinter # to be enabled once #158 is merged
- bodyclose
- exportloopref
- gocheckcompilerdirectives
- gofmt
- goimports
- structcheck
- varcheck
- staticcheck
- importas
- loggercheck
- makezero
- nilerr
- prealloc
- reassign
- tenv
- unconvert
- revive
- ineffassign
- vet
- unused
- misspell
disable:
- errcheck

run:
tests: false
timeout: 8m
skip-dirs:
- api
- design
- docs
- docs/man
- wastedassign
- unparam
- gofumpt
- nosprintfhostport
- musttag
- exhaustive
- nilnil
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ codegen:
lint:
docker run --rm -v "$(shell pwd):/var/work:ro" -w /var/work \
golangci/golangci-lint:v1.55.2 golangci-lint run -v --timeout=5m
docker run --rm -v "$(shell pwd):/var/work:ro" -w /var/work/e2e \
golangci/golangci-lint:v1.55.2 golangci-lint run -v --timeout=5m

.PHONY: fmt
fmt:
Expand Down
4 changes: 0 additions & 4 deletions cloud/linode/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,3 @@ func TestParseProviderID(t *testing.T) {
})
}
}

func stringPtr(s string) *string {
return &s
}
5 changes: 2 additions & 3 deletions cloud/linode/fake_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(rr)
return
}

}

case "POST":
Expand Down Expand Up @@ -596,9 +595,9 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

func randString(n int) string {
func randString() string {
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, n)
b := make([]byte, 10)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
Expand Down
49 changes: 36 additions & 13 deletions cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func TestInstanceExists(t *testing.T) {
instances := newInstances(client)
node := nodeWithProviderID(providerIDPrefix + "123")
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
{ID: 123,
{
ID: 123,
Label: "mock",
Region: "us-east",
Type: "g6-standard-2"},
Type: "g6-standard-2",
},
}, nil)

exists, err := instances.InstanceExists(ctx, node)
Expand Down Expand Up @@ -154,16 +156,36 @@ func TestMetadataRetrieval(t *testing.T) {
expectedErr error
}{
{"no IPs", nil, nil, instanceNoIPAddressesError{192910}},
{"one public, one private", []string{"32.74.121.25", "192.168.121.42"},
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeInternalIP, Address: "192.168.121.42"}}, nil},
{"one public, no private", []string{"32.74.121.25"},
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}}, nil},
{"one private, no public", []string{"192.168.121.42"},
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}}, nil},
{"two public addresses", []string{"32.74.121.25", "32.74.121.22"},
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "32.74.121.22"}}, nil},
{"two private addresses", []string{"192.168.121.42", "10.0.2.15"},
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.2.15"}}, nil},
{
"one public, one private",
[]string{"32.74.121.25", "192.168.121.42"},
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
nil,
},
{
"one public, no private",
[]string{"32.74.121.25"},
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}},
nil,
},
{
"one private, no public",
[]string{"192.168.121.42"},
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
nil,
},
{
"two public addresses",
[]string{"32.74.121.25", "32.74.121.22"},
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "32.74.121.22"}},
nil,
},
{
"two private addresses",
[]string{"192.168.121.42", "10.0.2.15"},
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.2.15"}},
nil,
},
}

for _, test := range ipTests {
Expand Down Expand Up @@ -281,7 +303,8 @@ func TestInstanceShutdown(t *testing.T) {
id := 12345
node := nodeWithProviderID(providerIDPrefix + strconv.Itoa(id))
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
{ID: id, Label: "shutting-down-linode", Status: linodego.InstanceShuttingDown}}, nil)
{ID: id, Label: "shutting-down-linode", Status: linodego.InstanceShuttingDown},
}, nil)
shutdown, err := instances.InstanceShutdown(ctx, node)

assert.NoError(t, err)
Expand Down
6 changes: 2 additions & 4 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ const (
annLinodeNodePrivateIP = "node.k8s.linode.com/private-ip"
)

var (
errNoNodesAvailable = errors.New("no nodes available for nodebalancer")
)
var errNoNodesAvailable = errors.New("no nodes available for nodebalancer")

type lbNotFoundError struct {
serviceNn string
Expand Down Expand Up @@ -547,7 +545,7 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1

health, err := getHealthCheckType(service)
if err != nil {
return linodego.NodeBalancerConfig{}, nil
return linodego.NodeBalancerConfig{}, err
}

config := linodego.NodeBalancerConfig{
Expand Down
Loading

0 comments on commit 83868ae

Please sign in to comment.