Skip to content

Commit

Permalink
[YUNIKORN-2973] Adding GinkgoLinter (#941)
Browse files Browse the repository at this point in the history
Fix issues raised by the linter in the tests.

Closes: #941

Signed-off-by: Wilfred Spiegelenburg <wilfreds@apache.org>
  • Loading branch information
rrajesh-cloudera authored and wilfred-s committed Dec 13, 2024
1 parent badbb16 commit 76aaf7e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ linters-settings:
funlen:
lines: 120
statements: 80
ginkgolinter:
enabled: true
path : ./test
depguard:
rules:
main:
Expand Down Expand Up @@ -74,6 +77,7 @@ linters:
- gosec
- dogsled
- whitespace
- ginkgolinter

issues:
exclude-use-default: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ var _ = BeforeSuite(func() {
restClient = yunikorn.RClient{}

kubeClient = k8s.KubeCtl{}
Expect(kubeClient.SetClient()).To(BeNil())
Expect(kubeClient.SetClient()).To(Succeed())

yunikorn.EnsureYuniKornConfigsPresent()
yunikorn.UpdateConfigMapWrapper(oldConfigMap, "")
Expand All @@ -218,7 +218,7 @@ var _ = BeforeSuite(func() {

var _ = AfterSuite(func() {
kubeClient = k8s.KubeCtl{}
Expect(kubeClient.SetClient()).To(BeNil())
Expect(kubeClient.SetClient()).To(Succeed())

By(fmt.Sprintf("Removing priority class %s", testNonYkPriorityClass.Name))
err := kubeClient.DeletePriorityClass(testNonYkPriorityClass.Name)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/admission_controller/admission_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const cronJobPodTimeout = 65 * time.Second
var _ = ginkgo.Describe("AdmissionController", func() {
ginkgo.BeforeEach(func() {
kubeClient = k8s.KubeCtl{}
gomega.Expect(kubeClient.SetClient()).To(gomega.BeNil())
gomega.Expect(kubeClient.SetClient()).To(gomega.Succeed())
ns = "ns-" + common.RandSeq(10)
ginkgo.By(fmt.Sprintf("Creating namespace: %s for admission controller tests", ns))
var ns1, err1 = kubeClient.CreateNamespace(ns, nil)
Expand Down Expand Up @@ -445,7 +445,7 @@ var _ = ginkgo.Describe("AdmissionController", func() {
rs.Status.ReadyReplicas,
rs.Status.AvailableReplicas)
}
gomega.Ω(len(replicaSetList.Items)).To(gomega.Equal(2))
gomega.Ω(replicaSetList.Items).To(gomega.HaveLen(2))
})

ginkgo.AfterEach(func() {
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/basic_scheduling/basic_scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = ginkgo.BeforeSuite(func() {
suiteName = common.GetSuiteName(filename)
// Initializing kubectl client
kClient = k8s.KubeCtl{}
gomega.Ω(kClient.SetClient()).To(gomega.BeNil())
gomega.Ω(kClient.SetClient()).To(gomega.Succeed())
// Initializing rest client
restClient = yunikorn.RClient{}
yunikorn.EnsureYuniKornConfigsPresent()
Expand Down Expand Up @@ -101,8 +101,7 @@ var _ = ginkgo.Describe("", func() {

ginkgo.It("Verify_Pod_Alloc_Props", func() {
ginkgo.By("Verify the pod allocation properties")
gomega.Ω(appsInfo.Allocations).NotTo(gomega.BeNil())
gomega.Ω(len(appsInfo.Allocations)).NotTo(gomega.BeZero())
gomega.Ω(appsInfo.Allocations).NotTo(gomega.BeEmpty())
allocation := appsInfo.Allocations[0]
gomega.Ω(allocation).NotTo(gomega.BeNil())
gomega.Ω(allocation.AllocationKey).NotTo(gomega.BeNil())
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/helpers/k8s/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (e *EventHandler) WaitForUpdate(timeout time.Duration) bool {

func ObserveConfigMapInformerUpdateAfterAction(action func()) {
kubeClient := KubeCtl{}
gomega.Expect(kubeClient.SetClient()).To(gomega.BeNil())
gomega.Expect(kubeClient.SetClient()).To(gomega.Succeed())

// Setup ConfigMap informer
stopChan := make(chan struct{})
Expand All @@ -156,5 +156,5 @@ func ObserveConfigMapInformerUpdateAfterAction(action func()) {

// Wait for ConfigMap informer recevie update event.
updateOk := eventHandler.WaitForUpdate(30 * time.Second)
gomega.Ω(updateOk).To(gomega.Equal(true))
gomega.Ω(updateOk).To(gomega.BeTrue())
}
4 changes: 2 additions & 2 deletions test/e2e/recovery_and_restart/recovery_and_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var _ = ginkgo.Describe("", func() {
gomega.Ω(appsInfo).NotTo(gomega.BeNil())
ginkgo.By("Verify the pod allocation properties")
gomega.Ω(appsInfo).NotTo(gomega.BeNil())
gomega.Ω(len(appsInfo.Allocations)).NotTo(gomega.BeZero())
gomega.Ω(appsInfo.Allocations).NotTo(gomega.BeNil())
allocations := appsInfo.Allocations[0]
gomega.Ω(allocations).NotTo(gomega.BeNil())
gomega.Ω(allocations.AllocationKey).NotTo(gomega.BeNil())
Expand All @@ -149,7 +149,7 @@ var _ = ginkgo.Describe("", func() {
core := sleepRespPod.Spec.Containers[0].Resources.Requests.Cpu().MilliValue()
mem := sleepRespPod.Spec.Containers[0].Resources.Requests.Memory().Value()
resMap := allocations.ResourcePerAlloc
gomega.Ω(len(resMap)).NotTo(gomega.BeZero())
gomega.Ω(resMap).NotTo(gomega.BeEmpty())
gomega.Ω(resMap["memory"]).To(gomega.Equal(mem))
gomega.Ω(resMap["vcore"]).To(gomega.Equal(core))
})
Expand Down

0 comments on commit 76aaf7e

Please sign in to comment.