Skip to content

Commit

Permalink
Enable ginkgolinter and fix findings
Browse files Browse the repository at this point in the history
ginkgolinter finds bugs and enforces standards of using the ginkgo and
gomega packages. See more details here:
https://github.com/nunnatsa/ginkgolinter

This PR enables the ginkgolinter in the .golangci.yml, and fixes all the
new finding from running golangci-lint.

Note: all the finding were auto fixed by running the ginkgolinter cli
with the `-fix` flag.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
  • Loading branch information
nunnatsa committed Jan 10, 2024
1 parent b51f67c commit d802165
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 144 deletions.
29 changes: 15 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ issues:
linters:
disable-all: true
enable:
- nakedret
- interfacer
- varcheck
- deadcode
- structcheck
- misspell
- maligned
- ineffassign
- dupl
- errcheck
- ginkgolinter
- goconst
- gocyclo
- gofmt
- goimports
- errcheck
- unparam
- golint
- staticcheck
- gosimple
- unused
- govet
- ineffassign
- interfacer
- maligned
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- gocyclo
- gofmt
- dupl
- unparam
- unused
- varcheck

run:
deadline: 5m
18 changes: 9 additions & 9 deletions handler/enqueue_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {
podOwner.SetGroupVersionKind(schema.GroupVersionKind{Group: "", Kind: "Pod"})

err := SetOwnerAnnotations(podOwner, pod)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
instance = EnqueueRequestForAnnotation{
Type: schema.GroupKind{
Group: "",
Expand Down Expand Up @@ -93,7 +93,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {
}

err := SetOwnerAnnotations(podOwner, repl)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

evt := event.CreateEvent{
Object: repl,
Expand Down Expand Up @@ -249,7 +249,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {
newPod.Namespace = pod.Namespace + "2"

err := SetOwnerAnnotations(podOwner, pod)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

evt := event.UpdateEvent{
ObjectOld: pod,
Expand Down Expand Up @@ -338,7 +338,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {
newPod.Namespace = pod.Namespace + "2"

err := SetOwnerAnnotations(podOwner, pod)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

var podOwner2 = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -349,7 +349,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {
podOwner2.SetGroupVersionKind(schema.GroupVersionKind{Group: "", Kind: "Pod"})

err = SetOwnerAnnotations(podOwner2, newPod)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

evt := event.UpdateEvent{
ObjectOld: pod,
Expand Down Expand Up @@ -390,15 +390,15 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {
}

err := SetOwnerAnnotations(podOwner, nd)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

expected := map[string]string{
"my-test-annotation": "should-keep",
NamespacedNameAnnotation: "podOwnerNs/podOwnerName",
TypeAnnotation: schema.GroupKind{Group: "", Kind: "Pod"}.String(),
}

Expect(len(nd.GetAnnotations())).To(Equal(3))
Expect(nd.GetAnnotations()).To(HaveLen(3))
Expect(nd.GetAnnotations()).To(Equal(expected))
})
It("should return error when the owner Kind is not present", func() {
Expand All @@ -410,7 +410,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {

podOwner.SetGroupVersionKind(schema.GroupVersionKind{Group: "Pod", Kind: ""})
err := SetOwnerAnnotations(podOwner, nd)
Expect(err).NotTo(BeNil())
Expect(err).To(HaveOccurred())
})
It("should return an error when the owner Name is not set", func() {
nd := &corev1.Node{
Expand All @@ -427,7 +427,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() {

ownerNew.SetGroupVersionKind(schema.GroupVersionKind{Group: "Pod", Kind: ""})
err := SetOwnerAnnotations(ownerNew, nd)
Expect(err).NotTo(BeNil())
Expect(err).To(HaveOccurred())
})
})
})
22 changes: 11 additions & 11 deletions handler/instrumented_enqueue_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() {
// verify metrics
gauges, err := registry.Gather()
Expect(err).NotTo(HaveOccurred())
Expect(len(gauges)).To(Equal(1))
Expect(gauges).To(HaveLen(1))
assertMetrics(gauges[0], 1, []*corev1.Pod{pod})
})
})
Expand Down Expand Up @@ -114,7 +114,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() {
// verify metrics
gauges, err := registry.Gather()
Expect(err).NotTo(HaveOccurred())
Expect(len(gauges)).To(Equal(0))
Expect(gauges).To(BeEmpty())
})
})
Context("when a gauge does not exist", func() {
Expand All @@ -139,7 +139,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() {
// verify metrics
gauges, err := registry.Gather()
Expect(err).NotTo(HaveOccurred())
Expect(len(gauges)).To(Equal(0))
Expect(gauges).To(BeEmpty())
})
})

Expand Down Expand Up @@ -174,7 +174,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() {
// verify metrics
gauges, err := registry.Gather()
Expect(err).NotTo(HaveOccurred())
Expect(len(gauges)).To(Equal(1))
Expect(gauges).To(HaveLen(1))
assertMetrics(gauges[0], 2, []*corev1.Pod{newpod, pod})
})
})
Expand All @@ -183,7 +183,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() {
It("should fill out map with values from given objects", func() {
labelMap := getResourceLabels(pod)
Expect(labelMap).ShouldNot(BeEmpty())
Expect(len(labelMap)).To(Equal(5))
Expect(labelMap).To(HaveLen(5))
Expect(labelMap["name"]).To(Equal(pod.GetObjectMeta().GetName()))
Expect(labelMap["namespace"]).To(Equal(pod.GetObjectMeta().GetNamespace()))
Expect(labelMap["group"]).To(Equal(pod.GetObjectKind().GroupVersionKind().Group))
Expand All @@ -201,22 +201,22 @@ func assertMetrics(gauge *dto.MetricFamily, count int, pods []*corev1.Pod) {
v := "version"
k := "kind"

Expect(len(gauge.Metric)).To(Equal(count))
Expect(gauge.Metric).To(HaveLen(count))
for i := 0; i < count; i++ {
Expect(*gauge.Metric[i].Gauge.Value).To(Equal(float64(pods[i].GetObjectMeta().GetCreationTimestamp().UTC().Unix())))

for _, l := range gauge.Metric[i].Label {
switch l.Name {
case &name:
Expect(l.Value).To(Equal(pods[i].GetObjectMeta().GetName()))
Expect(l.Value).To(HaveValue(Equal(pods[i].GetObjectMeta().GetName())))
case &namespace:
Expect(l.Value).To(Equal(pods[i].GetObjectMeta().GetNamespace()))
Expect(l.Value).To(HaveValue(Equal(pods[i].GetObjectMeta().GetNamespace())))
case &g:
Expect(l.Value).To(Equal(pods[i].GetObjectKind().GroupVersionKind().Group))
Expect(l.Value).To(HaveValue(Equal(pods[i].GetObjectKind().GroupVersionKind().Group)))
case &v:
Expect(l.Value).To(Equal(pods[i].GetObjectKind().GroupVersionKind().Version))
Expect(l.Value).To(HaveValue(Equal(pods[i].GetObjectKind().GroupVersionKind().Version)))
case &k:
Expect(l.Value).To(Equal(pods[i].GetObjectKind().GroupVersionKind().Kind))
Expect(l.Value).To(HaveValue(Equal(pods[i].GetObjectKind().GroupVersionKind().Kind)))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = Describe("Helpers test", func() {

// test
namespace, err := GetOperatorNamespace()
Expect(err).Should(BeNil())
Expect(err).ShouldNot(HaveOccurred())
Expect(namespace).To(Equal("testnamespace"))
})
It("should trim whitespace from namespace", func() {
Expand All @@ -48,7 +48,7 @@ var _ = Describe("Helpers test", func() {

// test
namespace, err := GetOperatorNamespace()
Expect(err).Should(BeNil())
Expect(err).ShouldNot(HaveOccurred())
Expect(namespace).To(Equal("testnamespace"))
})
})
Expand Down
Loading

0 comments on commit d802165

Please sign in to comment.