Skip to content

Commit

Permalink
Enable ginkgolinter and fix findings
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
  • Loading branch information
killianmuldoon committed Jul 6, 2023
1 parent dafdcb6 commit 4a447a4
Show file tree
Hide file tree
Showing 150 changed files with 826 additions and 832 deletions.
8 changes: 1 addition & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- errchkjson
- exportloopref
- gci
- ginkgolinter
- goconst
- gocritic
- godot
Expand Down Expand Up @@ -58,13 +59,6 @@ linters:
linters-settings:
gci:
local-prefixes: "sigs.k8s.io/cluster-api"
ginkgolinter:
# Suppress the wrong length assertion warning.
suppress-len-assertion: false
# Suppress the wrong nil assertion warning.
suppress-nil-assertion: false
# Suppress the wrong error assertion warning.
suppress-err-assertion: true
godot:
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha4/cluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestClusterIPFamily(t *testing.T) {
g := NewWithT(t)
ipFamily, err := tt.c.GetIPFamily()
g.Expect(ipFamily).To(Equal(tt.expectRes))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
})
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func TestClusterIPFamily(t *testing.T) {
g := NewWithT(t)
ipFamily, err := tt.c.GetIPFamily()
g.Expect(ipFamily).To(Equal(tt.expectRes))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
})
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/cluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestClusterIPFamily(t *testing.T) {
g := NewWithT(t)
ipFamily, err := tt.c.GetIPFamily()
g.Expect(ipFamily).To(Equal(tt.expectRes))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
})
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func TestClusterIPFamily(t *testing.T) {
g := NewWithT(t)
ipFamily, err := tt.c.GetIPFamily()
g.Expect(ipFamily).To(Equal(tt.expectRes))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
})
}

Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/machine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestMachineClusterNameImmutable(t *testing.T) {
g.Expect(err).To(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down
12 changes: 6 additions & 6 deletions api/v1beta1/machinedeployment_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ func TestMachineDeploymentValidation(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := md.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = md.ValidateUpdate(md)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down Expand Up @@ -519,7 +519,7 @@ func TestMachineDeploymentClusterNameImmutable(t *testing.T) {
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(warnings).To(BeEmpty())
})
Expand Down Expand Up @@ -549,22 +549,22 @@ func defaultValidateTestCustomDefaulter(object admission.Validator, customDefaul
g := NewWithT(t)
g.Expect(customDefaulter.Default(ctx, createCopy)).To(Succeed())
warnings, err := createCopy.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
})
t.Run("validate-on-update", func(t *testing.T) {
g := NewWithT(t)
g.Expect(customDefaulter.Default(ctx, defaultingUpdateCopy)).To(Succeed())
g.Expect(customDefaulter.Default(ctx, updateCopy)).To(Succeed())
warnings, err := defaultingUpdateCopy.ValidateUpdate(updateCopy)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
})
t.Run("validate-on-delete", func(t *testing.T) {
g := NewWithT(t)
g.Expect(customDefaulter.Default(ctx, deleteCopy)).To(Succeed())
warnings, err := deleteCopy.ValidateDelete()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
})
}
Expand Down
20 changes: 10 additions & 10 deletions api/v1beta1/machinehealthcheck_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func TestMachineHealthCheckLabelSelectorAsSelectorValidation(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := mhc.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = mhc.ValidateUpdate(mhc)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestMachineHealthCheckClusterNameImmutable(t *testing.T) {
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(warnings).To(BeEmpty())
})
Expand Down Expand Up @@ -229,10 +229,10 @@ func TestMachineHealthCheckUnhealthyConditions(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := mhc.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = mhc.ValidateUpdate(mhc)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down Expand Up @@ -312,10 +312,10 @@ func TestMachineHealthCheckNodeStartupTimeout(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := mhc.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = mhc.ValidateUpdate(mhc)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
}
Expand Down Expand Up @@ -379,10 +379,10 @@ func TestMachineHealthCheckMaxUnhealthy(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := mhc.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = mhc.ValidateUpdate(mhc)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
}
Expand All @@ -401,7 +401,7 @@ func TestMachineHealthCheckSelectorValidation(t *testing.T) {
},
}
err := mhc.validate(nil)
g.Expect(err).ToNot(BeNil())
g.Expect(err).To(HaveOccurred())
g.Expect(err.Error()).To(ContainSubstring("selector must not be empty"))
}

Expand Down
14 changes: 7 additions & 7 deletions api/v1beta1/machineset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func TestMachineSetLabelSelectorMatchValidation(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := ms.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = ms.ValidateUpdate(ms)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestMachineSetClusterNameImmutable(t *testing.T) {
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(warnings).To(BeEmpty())
})
Expand Down Expand Up @@ -228,10 +228,10 @@ func TestMachineSetVersionValidation(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := md.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = md.ValidateUpdate(md)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down Expand Up @@ -300,9 +300,9 @@ func TestValidateSkippedMachineSetPreflightChecks(t *testing.T) {
g := NewWithT(t)
err := validateSkippedMachineSetPreflightChecks(tt.ms)
if tt.expectErr {
g.Expect(err).NotTo(BeNil())
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/kubeadm/api/v1alpha4/kubeadm_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMarshalJSON(t *testing.T) {
g := NewWithT(t)

b, err := json.Marshal(rt.bts)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(string(b)).To(Equal(rt.expected))
})
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestUnmarshalJSON(t *testing.T) {
if rt.expectedError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(newbts).To(Equal(rt.bts))
})
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
if rt.expectedError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(actual).To(Equal(rt.bts))
})
Expand Down
8 changes: 4 additions & 4 deletions bootstrap/kubeadm/api/v1beta1/kubeadm_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestNodeRegistrationOptionsMarshalJSON(t *testing.T) {
g := NewWithT(t)

b, err := tt.opts.MarshalJSON()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(string(b)).To(Equal(tt.expected))
})
}
Expand All @@ -97,7 +97,7 @@ func TestBootstrapTokenStringMarshalJSON(t *testing.T) {
g := NewWithT(t)

b, err := json.Marshal(rt.bts)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(string(b)).To(Equal(rt.expected))
})
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestBootstrapTokenStringUnmarshalJSON(t *testing.T) {
if rt.expectedError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(newbts).To(Equal(rt.bts))
})
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
if rt.expectedError {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
}
g.Expect(actual).To(Equal(rt.bts))
})
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/kubeadm/api/v1beta1/kubeadmconfig_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ func TestKubeadmConfigValidate(t *testing.T) {
g.Expect(warnings).To(BeEmpty())
} else {
warnings, err := tt.in.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = tt.in.ValidateUpdate(nil)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func TestKubeadmConfigTemplateValidation(t *testing.T) {
t.Run(name, func(t *testing.T) {
g := NewWithT(t)
warnings, err := tt.in.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
warnings, err = tt.in.ValidateUpdate(nil)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(warnings).To(BeEmpty())
})
}
Expand Down
10 changes: 5 additions & 5 deletions bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestNewInitControlPlaneAdditionalFileEncodings(t *testing.T) {
}

out, err := NewInitControlPlane(cpinput)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())

expectedFiles := []string{
`- path: /tmp/my-path
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestNewInitControlPlaneCommands(t *testing.T) {
}

out, err := NewInitControlPlane(cpinput)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())

expectedCommands := []string{
`"\"echo $(date) ': hello world!'\""`,
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestNewInitControlPlaneDiskMounts(t *testing.T) {
}

out, err := NewInitControlPlane(cpinput)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())

expectedDiskSetup := `disk_setup:
test-device:
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestNewJoinControlPlaneAdditionalFileEncodings(t *testing.T) {
}

out, err := NewJoinControlPlane(cpinput)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())

expectedFiles := []string{
`- path: /tmp/my-path
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestNewJoinControlPlaneExperimentalRetry(t *testing.T) {
}

out, err := NewJoinControlPlane(cpinput)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(err).ToNot(HaveOccurred())

expectedFiles := []string{
`- path: ` + retriableJoinScriptName + `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestKubeadmConfigReconciler(t *testing.T) {
g := NewWithT(t)

ns, err := env.CreateNamespace(ctx, "test-kubeadm-config-reconciler")
g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())

cluster := builder.Cluster(ns.Name, "cluster1").Build()
g.Expect(env.Create(ctx, cluster)).To(Succeed())
Expand Down
Loading

0 comments on commit 4a447a4

Please sign in to comment.