Skip to content

Commit 87ad694

Browse files
authored
build: Add testifylint linter (#706)
And fix lint problems.
1 parent f1c8495 commit 87ad694

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

.golangci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ linters:
3434
- staticcheck
3535
- stylecheck
3636
- tenv
37+
- testifylint
3738
- thelper
3839
- tparallel
3940
- unconvert
@@ -74,18 +75,20 @@ linters-settings:
7475
- style
7576
gofumpt:
7677
extra-rules: true
78+
importas:
79+
no-unaliased: false
80+
alias:
81+
- pkg: "sigs.k8s.io/cluster-api/api/v1beta1"
82+
alias: clusterv1
7783
lll:
7884
line-length: 120
7985
stylecheck:
8086
# https://staticcheck.io/docs/configuration/options/#dot_import_whitelist
8187
dot-import-whitelist:
8288
- github.com/onsi/ginkgo/v2
8389
- github.com/onsi/gomega
84-
importas:
85-
no-unaliased: false
86-
alias:
87-
- pkg: "sigs.k8s.io/cluster-api/api/v1beta1"
88-
alias: clusterv1
90+
testifylint:
91+
enable-all: true
8992

9093
issues:
9194
exclude-dirs:

pkg/handlers/generic/lifecycle/clusterautoscaler/template_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1213
)
@@ -90,7 +91,7 @@ func Test_templateValues(t *testing.T) {
9091
for _, tt := range tests {
9192
t.Run(tt.name, func(t *testing.T) {
9293
got, err := templateValues(tt.cluster, tt.text)
93-
assert.NoError(t, err)
94+
require.NoError(t, err)
9495
assert.Equal(t, tt.want, got)
9596
})
9697
}

pkg/handlers/generic/lifecycle/cni/cluster_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
"sigs.k8s.io/cluster-api/api/v1beta1"
1112
)
1213

@@ -69,7 +70,7 @@ func Test_PodCIDR(t *testing.T) {
6970
t.Run(tt.name, func(t *testing.T) {
7071
t.Parallel()
7172
cidr, err := PodCIDR(tt.cluster)
72-
assert.ErrorIs(t, err, tt.wantErr)
73+
require.ErrorIs(t, err, tt.wantErr)
7374
assert.Equal(t, tt.wantCIDR, cidr)
7475
})
7576
}

pkg/handlers/generic/lifecycle/servicelbgc/deleter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func Test_shouldDeleteServicesWithLoadBalancer(t *testing.T) {
103103
t.Run(tt.name, func(t *testing.T) {
104104
t.Parallel()
105105
shouldDelete, err := shouldDeleteServicesWithLoadBalancer(tt.cluster)
106-
assert.NoError(t, err)
106+
require.NoError(t, err)
107107
assert.Equal(t, tt.shouldDelete, shouldDelete)
108108
})
109109
}

pkg/handlers/generic/mutation/imageregistries/credentials/credential_provider_config_files_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1112
)
1213

@@ -80,7 +81,7 @@ providers:
8081
t.Run(tt.name, func(t *testing.T) {
8182
t.Parallel()
8283
file, err := templateKubeletCredentialProviderConfig()
83-
assert.ErrorIs(t, err, tt.wantErr)
84+
require.ErrorIs(t, err, tt.wantErr)
8485
assert.Equal(t, tt.want, file)
8586
})
8687
}
@@ -344,7 +345,7 @@ credentialProviders:
344345
t.Run(tt.name, func(t *testing.T) {
345346
t.Parallel()
346347
file, err := templateDynamicCredentialProviderConfig(tt.credentials)
347-
assert.ErrorIs(t, err, tt.wantErr)
348+
require.ErrorIs(t, err, tt.wantErr)
348349
assert.Equal(t, tt.want, file)
349350
})
350351
}

pkg/handlers/generic/mutation/imageregistries/credentials/inject_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
. "github.com/onsi/ginkgo/v2"
1010
"github.com/onsi/gomega"
1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/apimachinery/pkg/runtime"
@@ -117,7 +118,7 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
117118
t.Parallel()
118119

119120
need, err := needImageRegistryCredentialsConfiguration(tt.configs)
120-
assert.ErrorIs(t, err, tt.wantErr)
121+
require.ErrorIs(t, err, tt.wantErr)
121122
assert.Equal(t, tt.need, need)
122123
})
123124
}

pkg/handlers/generic/mutation/mirrors/mirror_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1112

1213
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
@@ -92,7 +93,7 @@ func Test_generateDefaultRegistryMirrorFile(t *testing.T) {
9293
t.Run(tt.name, func(t *testing.T) {
9394
t.Parallel()
9495
file, err := generateGlobalRegistryMirrorFile(tt.config)
95-
assert.ErrorIs(t, err, tt.wantErr)
96+
require.ErrorIs(t, err, tt.wantErr)
9697
assert.Equal(t, tt.want, file)
9798
})
9899
}

0 commit comments

Comments
 (0)