Skip to content

Commit

Permalink
add ginko linter (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
bschimke95 authored Oct 21, 2024
1 parent 65bb21d commit ed8525e
Show file tree
Hide file tree
Showing 54 changed files with 266 additions and 327 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ linters:
- forcetypeassert
# - funlen - TODO(ben): maybe consider later; needs some refactoring
- gci
- ginkgolinter


# TODO(ben): Enable those linters step by step and fix existing issues.
# - ginkgolinter
# - gocheckcompilerdirectives
# - gochecknoglobals
# - gochecknoinits
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/cmd/k8s/k8s_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func Test_updateConfigMapstructure(t *testing.T) {
if tc.expectErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(cfg).To(SatisfyAll(tc.assertions...))
}
})
Expand Down
14 changes: 7 additions & 7 deletions src/k8s/pkg/client/dqlite/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ func TestRemoveNodeByAddress(t *testing.T) {
client, err := dqlite.NewClient(ctx, dqlite.ClientOpts{
ClusterYAML: filepath.Join(dirs[0], "cluster.yaml"),
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(client).NotTo(BeNil())

members, err := client.ListMembers(ctx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(members).To(HaveLen(2))

memberToRemove := members[0].Address
if members[0].Role == dqlite.Voter {
memberToRemove = members[1].Address
}
g.Expect(client.RemoveNodeByAddress(ctx, memberToRemove)).To(BeNil())
g.Expect(client.RemoveNodeByAddress(ctx, memberToRemove)).To(Succeed())

members, err = client.ListMembers(ctx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(members).To(HaveLen(1))
})
})
Expand All @@ -41,11 +41,11 @@ func TestRemoveNodeByAddress(t *testing.T) {
client, err := dqlite.NewClient(ctx, dqlite.ClientOpts{
ClusterYAML: filepath.Join(dirs[0], "cluster.yaml"),
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(client).NotTo(BeNil())

members, err := client.ListMembers(ctx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(members).To(HaveLen(2))

memberToRemove := members[0]
Expand All @@ -61,7 +61,7 @@ func TestRemoveNodeByAddress(t *testing.T) {
g.Expect(client.RemoveNodeByAddress(ctx, memberToRemove.Address)).To(Succeed())

members, err = client.ListMembers(ctx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(members).To(HaveLen(1))
g.Expect(members[0].Role).To(Equal(dqlite.Voter))
g.Expect(members[0].Address).ToNot(Equal(memberToRemove.Address))
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/client/kubernetes/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestGetKubeAPIServerEndpoints(t *testing.T) {
g.Expect(err).To(HaveOccurred())
g.Expect(servers).To(BeEmpty())
} else {
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(servers).To(Equal(tc.expectedAddresses))
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/pkg/client/kubernetes/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDeleteNode(t *testing.T) {
}, metav1.CreateOptions{})

err := client.DeleteNode(context.Background(), nodeName)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})

t.Run("node does not exist is successful", func(t *testing.T) {
Expand All @@ -37,7 +37,7 @@ func TestDeleteNode(t *testing.T) {
nodeName := "test-node"

err := client.DeleteNode(context.Background(), nodeName)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})

t.Run("node deletion fails", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/client/kubernetes/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestCheckForReadyPods(t *testing.T) {
err := client.CheckForReadyPods(context.Background(), tc.namespace, tc.listOptions)

if tc.expectedError == "" {
g.Expect(err).Should(BeNil())
g.Expect(err).ShouldNot(HaveOccurred())
} else {
g.Expect(err).Should(MatchError(tc.expectedError))
}
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/pkg/client/kubernetes/restart_daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TestRestartDaemonset(t *testing.T) {
if tc.expectError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
ds, err := client.AppsV1().DaemonSets("namespace").Get(context.Background(), "test", metav1.GetOptions{})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(ds.Spec.Template.Annotations["kubectl.kubernetes.io/restartedAt"]).NotTo(BeEmpty())
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/pkg/client/kubernetes/restart_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TestRestartDeployment(t *testing.T) {
if tc.expectError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
deploy, err := client.AppsV1().Deployments("namespace").Get(context.Background(), "test", metav1.GetOptions{})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(deploy.Spec.Template.Annotations["kubectl.kubernetes.io/restartedAt"]).NotTo(BeEmpty())
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/client/kubernetes/server_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestListResourcesForGroupVersion(t *testing.T) {
if tt.expectedError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(resources).To(Equal(tt.expectedList))
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/client/kubernetes/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestClusterHasReadyNodes(t *testing.T) {

ready, err := client.HasReadyNodes(context.Background())

g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(ready).To(Equal(tt.expectedReady))
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestControlPlaneConfigController(t *testing.T) {
g := NewWithT(t)

val, err := snaputil.GetServiceArgument(s, "kube-apiserver", earg)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(val).To(Equal(eval))
})
}
Expand All @@ -209,7 +209,7 @@ func TestControlPlaneConfigController(t *testing.T) {
g := NewWithT(t)

val, err := snaputil.GetServiceArgument(s, "kube-controller-manager", earg)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(val).To(Equal(eval))
})
}
Expand All @@ -222,7 +222,7 @@ func TestControlPlaneConfigController(t *testing.T) {

_, err := os.Stat(file)
if mustExist {
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
} else {
g.Expect(err).To(MatchError(os.ErrNotExist))
}
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/k8sd/controllers/csrsigning/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestFailedToGetCSR(t *testing.T) {
result, err := reconciler.Reconcile(context.Background(), getDefaultRequest())

g.Expect(result).To(Equal(ctrl.Result{}))
g.Expect(err).To(MatchError(getErr))
g.Expect(err).To(MatchError(getErr.Error()))
}

func TestHasSignedCertificate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/k8sd/controllers/node_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestConfigPropagation(t *testing.T) {

for ekey, evalue := range tc.expectArgs {
val, err := snaputil.GetServiceArgument(s, "kubelet", ekey)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(val).To(Equal(evalue))
}

Expand Down
12 changes: 6 additions & 6 deletions src/k8s/pkg/k8sd/database/capi_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ func TestClusterAPIAuthTokens(t *testing.T) {
g := NewWithT(t)
err := db.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
err := database.SetClusterAPIToken(ctx, tx, token)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})

t.Run("CheckAuthToken", func(t *testing.T) {
t.Run("ValidToken", func(t *testing.T) {
g := NewWithT(t)
err := db.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
valid, err := database.ValidateClusterAPIToken(ctx, tx, token)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(valid).To(BeTrue())
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})

t.Run("InvalidToken", func(t *testing.T) {
g := NewWithT(t)
err := db.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
valid, err := database.ValidateClusterAPIToken(ctx, tx, "invalid-token")
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(valid).To(BeFalse())
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})
})
})
Expand Down
20 changes: 10 additions & 10 deletions src/k8s/pkg/k8sd/database/cluster_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func TestClusterConfig(t *testing.T) {
// Write some config to the database
err := d.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
_, err := database.SetClusterConfig(context.Background(), tx, expectedClusterConfig)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))

// Retrieve it and map it to the struct
err = d.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
clusterConfig, err := database.GetClusterConfig(ctx, tx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(clusterConfig).To(Equal(expectedClusterConfig))
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})

t.Run("CannotUpdateCA", func(t *testing.T) {
Expand All @@ -65,11 +65,11 @@ func TestClusterConfig(t *testing.T) {

err = d.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
clusterConfig, err := database.GetClusterConfig(ctx, tx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(clusterConfig).To(Equal(expectedClusterConfig))
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})

t.Run("Update", func(t *testing.T) {
Expand Down Expand Up @@ -104,18 +104,18 @@ func TestClusterConfig(t *testing.T) {
},
})
g.Expect(returnedConfig).To(Equal(expectedClusterConfig))
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))

err = d.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
clusterConfig, err := database.GetClusterConfig(ctx, tx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(clusterConfig).To(Equal(expectedClusterConfig))
return nil
})
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
})
})
}
20 changes: 10 additions & 10 deletions src/k8s/pkg/k8sd/database/feature_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestFeatureStatus(t *testing.T) {
t.Run("ReturnNothingInitially", func(t *testing.T) {
g := NewWithT(t)
ss, err := database.GetFeatureStatuses(ctx, tx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(ss).To(BeEmpty())

})
Expand All @@ -53,12 +53,12 @@ func TestFeatureStatus(t *testing.T) {
g := NewWithT(t)

err := database.SetFeatureStatus(ctx, tx, features.Network, networkStatus)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
err = database.SetFeatureStatus(ctx, tx, features.DNS, dnsStatus)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))

ss, err := database.GetFeatureStatuses(ctx, tx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(ss).To(HaveLen(2))

g.Expect(ss[features.Network].Enabled).To(Equal(networkStatus.Enabled))
Expand All @@ -76,20 +76,20 @@ func TestFeatureStatus(t *testing.T) {
g := NewWithT(t)

err := database.SetFeatureStatus(ctx, tx, features.Network, networkStatus)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
err = database.SetFeatureStatus(ctx, tx, features.DNS, dnsStatus)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))

// set and update
err = database.SetFeatureStatus(ctx, tx, features.Network, networkStatus)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
err = database.SetFeatureStatus(ctx, tx, features.DNS, dnsStatus2)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
err = database.SetFeatureStatus(ctx, tx, features.Gateway, gatewayStatus)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))

ss, err := database.GetFeatureStatuses(ctx, tx)
g.Expect(err).To(BeNil())
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(ss).To(HaveLen(3))

// network stayed the same
Expand Down
Loading

0 comments on commit ed8525e

Please sign in to comment.