Skip to content

Commit

Permalink
Enable ginkgolinter and fix finding (#1689)
Browse files Browse the repository at this point in the history
Enable ginkgolinter in .golangci.yaml, and fix its findings.
  • Loading branch information
nunnatsa authored Mar 15, 2024
1 parent fe3bc2a commit 907f74f
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
linters-settings:
ginkgolinter:
forbid-focus-container: true
goimports:
local-prefixes: github.com/nginxinc/nginx-gateway-fabric
misspell:
Expand Down Expand Up @@ -41,6 +43,7 @@ linters:
- asciicheck
- errcheck
- errorlint
- ginkgolinter
- gocyclo
- gofmt
- gofumpt
Expand Down
2 changes: 1 addition & 1 deletion internal/framework/controller/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestRegister(t *testing.T) {
} else {
err := register()
if test.expectedErr == nil {
g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())
} else {
g.Expect(err).To(MatchError(test.expectedErr))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestEventLoop_SwapBatches(t *testing.T) {

eventLoop.swapBatches()

g.Expect(len(eventLoop.currentBatch)).To(Equal(len(nextBatch)))
g.Expect(eventLoop.currentBatch).To(HaveLen(len(nextBatch)))
g.Expect(eventLoop.currentBatch).To(Equal(nextBatch))
g.Expect(len(eventLoop.nextBatch)).To(Equal(0))
g.Expect(eventLoop.nextBatch).To(BeEmpty())
g.Expect(cap(eventLoop.nextBatch)).To(Equal(3))
}
4 changes: 2 additions & 2 deletions internal/framework/events/first_eventbatch_preparer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var _ = Describe("FirstEventBatchPreparer", func() {
batch, err := preparer.Prepare(context.Background())

Expect(batch).Should(BeEmpty())
Expect(err).Should(BeNil())
Expect(err).ToNot(HaveOccurred())
})

It("should prepare one event for each resource type", func() {
Expand Down Expand Up @@ -97,7 +97,7 @@ var _ = Describe("FirstEventBatchPreparer", func() {
batch, err := preparer.Prepare(context.Background())

Expect(batch).Should(Equal(expectedBatch))
Expect(err).Should(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})

Expand Down
4 changes: 2 additions & 2 deletions internal/framework/events/loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("EventLoop", func() {

var err error
Eventually(errorCh).Should(Receive(&err))
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})

// Because BeforeEach() creates the first batch and waits for it to be handled, in the tests below
Expand Down Expand Up @@ -138,7 +138,7 @@ var _ = Describe("EventLoop", func() {
cancel()
err := eventLoop.Start(ctx)

Expect(err).Should(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})
})
2 changes: 1 addition & 1 deletion internal/framework/runnables/runnables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestEnableAfterBecameLeader(t *testing.T) {
g.Expect(enabled).To(BeFalse())

err := enableAfterBecameLeader.Start(context.Background())
g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())

g.Expect(enabled).To(BeTrue())
}
4 changes: 2 additions & 2 deletions internal/mode/provisioner/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ var _ = Describe("handler", func() {
err := k8sclient.List(context.Background(), deps)

Expect(err).ToNot(HaveOccurred())
Expect(deps.Items).To(HaveLen(0))
Expect(deps.Items).To(BeEmpty())
})
})

Expand Down Expand Up @@ -370,7 +370,7 @@ var _ = Describe("handler", func() {
err := k8sclient.List(context.Background(), deps)

Expect(err).ToNot(HaveOccurred())
Expect(deps.Items).To(HaveLen(0))
Expect(deps.Items).To(BeEmpty())
})
})

Expand Down
4 changes: 2 additions & 2 deletions internal/mode/static/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ var _ = Describe("eventHandler", func() {
"Failed to update control plane configuration: logging.level: Unsupported value: " +
"\"invalid\": supported values: \"info\", \"debug\", \"error\"")
Expect(statuses).To(Equal(expStatuses(cond)))
Expect(len(fakeEventRecorder.Events)).To(Equal(1))
Expect(fakeEventRecorder.Events).To(HaveLen(1))
event := <-fakeEventRecorder.Events
Expect(event).To(Equal(
"Warning UpdateFailed Failed to update control plane configuration: logging.level: Unsupported value: " +
Expand All @@ -252,7 +252,7 @@ var _ = Describe("eventHandler", func() {

Expect(handler.GetLatestConfiguration()).To(BeNil())

Expect(len(fakeEventRecorder.Events)).To(Equal(1))
Expect(fakeEventRecorder.Events).To(HaveLen(1))
event := <-fakeEventRecorder.Events
Expect(event).To(Equal("Warning ResourceDeleted NginxGateway configuration was deleted; using defaults"))
Expect(zapLogLevelSetter.Enabled(zap.InfoLevel)).To(BeTrue())
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/sort/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestLessObjectMeta(t *testing.T) {
invertedResult := LessObjectMeta(test.meta2, test.meta1)

g.Expect(result).To(Equal(test.expected))
g.Expect(invertedResult).To(Equal(false))
g.Expect(invertedResult).To(BeFalse())
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func TestValidateBackendTLSPolicy(t *testing.T) {
if !test.isValid && !test.ignored {
g.Expect(conds).To(HaveLen(1))
} else {
g.Expect(conds).To(HaveLen(0))
g.Expect(conds).To(BeEmpty())
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/state/graph/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestBuildSectionNameRefs(t *testing.T) {
if test.expectedError != nil {
g.Expect(err).To(Equal(test.expectedError))
} else {
g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/state/graph/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestSecretResolver(t *testing.T) {
for _, test := range tests {
err := resolver.resolve(test.nsname)
if test.expectedErrMsg == "" {
g.Expect(err).To(BeNil(), fmt.Sprintf("case %q", test.name))
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("case %q", test.name))
} else {
g.Expect(err).To(MatchError(test.expectedErrMsg), fmt.Sprintf("case %q", test.name))
}
Expand Down
12 changes: 6 additions & 6 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var _ = Describe("Collector", Ordered, func() {

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(expData).To(Equal(data))
})
})
Expand Down Expand Up @@ -414,7 +414,7 @@ var _ = Describe("Collector", Ordered, func() {

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(expData).To(Equal(data))
})
})
Expand All @@ -430,7 +430,7 @@ var _ = Describe("Collector", Ordered, func() {

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(expData).To(Equal(data))
})

Expand Down Expand Up @@ -539,7 +539,7 @@ var _ = Describe("Collector", Ordered, func() {

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(expData).To(Equal(data))
})

Expand All @@ -558,7 +558,7 @@ var _ = Describe("Collector", Ordered, func() {

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(expData).To(Equal(data))
})

Expand All @@ -576,7 +576,7 @@ var _ = Describe("Collector", Ordered, func() {

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(expData).To(Equal(data))
})

Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/telemetry/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLoggingExporter(t *testing.T) {

err := exporter.Export(context.Background(), &Data{})

g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(buffer.String()).To(ContainSubstring(`"level":"info"`))
g.Expect(buffer.String()).To(ContainSubstring(`"msg":"Exporting telemetry"`))
}
2 changes: 1 addition & 1 deletion tests/suite/longevity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var _ = Describe("Longevity", Label("longevity-setup", "longevity-teardown"), fu
homeDir, err := os.UserHomeDir()
Expect(err).ToNot(HaveOccurred())

Expect(framework.WriteContent(resultsFile, "\n## Traffic\n"))
Expect(framework.WriteContent(resultsFile, "\n## Traffic\n")).To(Succeed())
Expect(writeTrafficResults(resultsFile, homeDir, "coffee.txt", "HTTP")).To(Succeed())
Expect(writeTrafficResults(resultsFile, homeDir, "tea.txt", "HTTPS")).To(Succeed())

Expand Down
2 changes: 1 addition & 1 deletion tests/suite/system_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func setup(cfg setupConfig, extraInstallArgs ...string) {
timeoutConfig.CreateTimeout,
)
Expect(err).ToNot(HaveOccurred())
Expect(podNames).ToNot(HaveLen(0))
Expect(podNames).ToNot(BeEmpty())

if *serviceType != "LoadBalancer" {
portFwdPort, err = framework.PortForward(k8sConfig, installCfg.Namespace, podNames[0], portForwardStopCh)
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var _ = Describe("Upgrade testing", Label("nfr", "upgrade"), func() {

podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
Expect(err).ToNot(HaveOccurred())
Expect(podNames).ToNot(HaveLen(0))
Expect(podNames).ToNot(BeEmpty())

// ensure that the leader election lease has been updated to the new pods
leaseCtx, leaseCancel := context.WithTimeout(context.Background(), 1*time.Minute)
Expand Down

0 comments on commit 907f74f

Please sign in to comment.