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

refactor: Update & Fix golangci-lint #408

Merged
merged 2 commits into from
Mar 28, 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
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Run tests
on: [ push, pull_request ]
jobs:
test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- uses: actions/checkout@v3
- name: Run tests
run: |
go vet ./...
go test $(go list ./... | grep -v e2etests)

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
# In general linting is quite fast with warm caches, but a fresh run might take some time.
args: --timeout 5m

imports:
name: Check Imports
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- uses: actions/checkout@v3
- name: Check imports
shell: bash
run: |
export PATH=$(go env GOPATH)/bin:$PATH
go get golang.org/x/tools/cmd/goimports
diff -u <(echo -n) <(goimports -d .)
16 changes: 0 additions & 16 deletions .github/workflows/goimports.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test.yml

This file was deleted.

46 changes: 30 additions & 16 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,60 @@
linters-settings:
errcheck:
exclude: ./.errcheck_excludes.txt
gocyclo:
min-complexity: 15
exhaustive:
default-signifies-exhaustive: true
gci:
sections:
- standard
- default
- prefix(github.com/hetznercloud)

importas:
no-unaliased: true
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1

misspell:
locale: "US"

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- errcheck
- errname
- exhaustive
- exportloopref
- gci
- gocritic
- gocyclo
- godot
- goimports
- golint
- gomodguard
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- prealloc
- rowserrcheck
- scopelint
- revive
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck
- whitespace

issues:
include:
- EXC0002 # disable excluding of issues about comments from golint

exclude-rules:
- path: _test\.go
- path: (_test\.go|testing\.go|testsupport|e2etests)
linters:
- gosec
- linters:
- gosec
text: "G204:"
- errcheck
- path: internal/mocks
linters:
- unparam
13 changes: 6 additions & 7 deletions e2etests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/annotation"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/hcops"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/stretchr/testify/assert"
typesv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var testCluster TestCluster
Expand Down Expand Up @@ -80,8 +81,7 @@ func TestCloudControllerManagerSetCorrectNodeLabelsAndIPAddresses(t *testing.T)
}

for _, address := range node.Status.Addresses {
switch address.Type {
case typesv1.NodeExternalIP:
if address.Type == corev1.NodeExternalIP {
expectedIP := testCluster.setup.ClusterNode.PublicNet.IPv4.IP.String()
if expectedIP != address.Address {
t.Errorf("Got %s as NodeExternalIP but expected %s", address.Address, expectedIP)
Expand All @@ -90,8 +90,7 @@ func TestCloudControllerManagerSetCorrectNodeLabelsAndIPAddresses(t *testing.T)
}
if testCluster.useNetworks {
for _, address := range node.Status.Addresses {
switch address.Type {
case typesv1.NodeInternalIP:
if address.Type == corev1.NodeInternalIP {
expectedIP := testCluster.setup.ClusterNode.PrivateNet[0].IP.String()
if expectedIP != address.Address {
t.Errorf("Got %s as NodeInternalIP but expected %s", address.Address, expectedIP)
Expand Down
Loading