Skip to content

Commit

Permalink
ci(golangci-lint): Add ginkgolinter (#411)
Browse files Browse the repository at this point in the history
* ci(golangci-lint): Add ginkgolinter
* Fix ginkgolinter warnings
  • Loading branch information
ctlong authored Dec 19, 2023
1 parent f898aef commit 07da6a9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ linters:
- gocyclo
# Inspects source code for security problems.
- gosec
# Enforces standards of using ginkgo and gomega.
- ginkgolinter

issues:
# Disable max issues per linter.
Expand Down
16 changes: 8 additions & 8 deletions src/internal/auth/capi_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ var _ = Describe("CAPIClient", func() {

By("calling isAuthorized the first time and caching response")
Expect(tc.client.IsAuthorized("37cbff06-79ef-4146-a7b0-01838940f185", "some-token")).To(BeTrue())
Expect(len(tc.capiClient.requests)).To(Equal(1))
Expect(tc.capiClient.requests).To(HaveLen(1))

By("calling isAuthorized the second time and pulling from the cache")
Expect(tc.client.IsAuthorized("37cbff06-79ef-4146-a7b0-01838940f185", "some-token")).To(BeTrue())
Expect(len(tc.capiClient.requests)).To(Equal(1))
Expect(tc.capiClient.requests).To(HaveLen(1))
})

It("sourceIDs from expired cached tokens are not authorized", func() {
Expand Down Expand Up @@ -176,14 +176,14 @@ var _ = Describe("CAPIClient", func() {
}

authorized := tc.client.IsAuthorized("app-guid", "some-token")
Expect(len(tc.capiClient.requests)).To(Equal(1))
Expect(tc.capiClient.requests).To(HaveLen(1))
Expect(authorized).To(BeTrue())

tc.capiClient.resps = []response{
newCapiResp(http.StatusOK),
}
Expect(tc.client.IsAuthorized("service-guid", "some-token")).To(BeTrue())
Expect(len(tc.capiClient.requests)).To(Equal(2))
Expect(tc.capiClient.requests).To(HaveLen(2))
})

It("stores the latency", func() {
Expand Down Expand Up @@ -501,7 +501,7 @@ var _ = Describe("CAPIClient", func() {
tc := setup()

tc.client.GetRelatedSourceIds([]string{}, "some-token")
Expect(tc.capiClient.requests).To(HaveLen(0))
Expect(tc.capiClient.requests).To(BeEmpty())
})

It("stores the latency", func() {
Expand All @@ -524,7 +524,7 @@ var _ = Describe("CAPIClient", func() {
{status: http.StatusNotFound},
}
sourceIds := tc.client.GetRelatedSourceIds([]string{"app-name"}, "some-token")
Expect(sourceIds).To(HaveLen(0))
Expect(sourceIds).To(BeEmpty())
})

It("returns no source IDs when the request returns a non-200 status code", func() {
Expand All @@ -534,7 +534,7 @@ var _ = Describe("CAPIClient", func() {
{err: errors.New("intentional error")},
}
sourceIds := tc.client.GetRelatedSourceIds([]string{"app-name"}, "some-token")
Expect(sourceIds).To(HaveLen(0))
Expect(sourceIds).To(BeEmpty())
})

It("returns no source IDs when JSON decoding fails", func() {
Expand All @@ -544,7 +544,7 @@ var _ = Describe("CAPIClient", func() {
{status: http.StatusOK, body: []byte(`{`)},
}
sourceIds := tc.client.GetRelatedSourceIds([]string{"app-name"}, "some-token")
Expect(sourceIds).To(HaveLen(0))
Expect(sourceIds).To(BeEmpty())
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/internal/auth/cf_auth_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ var _ = Describe("CfAuthMiddleware", func() {

var m rpc.MetaResponse
msg, err := io.ReadAll(tc.recorder.Body)
Expect(err).To(BeNil())
Expect(err).NotTo(HaveOccurred())
Expect(protojson.Unmarshal(msg, &m)).To(Succeed())

Expect(m.Meta).To(HaveLen(2))
Expand All @@ -182,7 +182,7 @@ var _ = Describe("CfAuthMiddleware", func() {
Expect(tc.recorder.Code).To(Equal(http.StatusOK))
var m rpc.MetaResponse
msg, err := io.ReadAll(tc.recorder.Body)
Expect(err).To(BeNil())
Expect(err).NotTo(HaveOccurred())
Expect(protojson.Unmarshal(msg, &m)).To(Succeed())
Expect(m.Meta).To(HaveLen(2))
Expect(m.Meta).To(HaveKey("source-0"))
Expand Down
24 changes: 12 additions & 12 deletions src/internal/auth/uaa_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = Describe("UAAClient", func() {
_, err = tc.uaaClient.Read(withBearer(token))
Expect(err).ToNot(HaveOccurred())

Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount))
})

It("does not allow use of an expired token", func() {
Expand Down Expand Up @@ -147,7 +147,7 @@ var _ = Describe("UAAClient", func() {
Expect(err).ToNot(HaveOccurred())
Expect(c.Token).To(Equal(withBearer(token)))

Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))
})

It("returns an error when the matching public key cannot be retrieved from UAA", func() {
Expand All @@ -161,7 +161,7 @@ var _ = Describe("UAAClient", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to decode token: using unknown token key"))

Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))
})

It("returns an error when given a token signed by an public key that was purged from UAA", func() {
Expand All @@ -182,7 +182,7 @@ var _ = Describe("UAAClient", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to decode token: using unknown token key"))

Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 2))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 2))
})

It("continues to accept previously signed tokens when retrieving public keys from UAA fails", func() {
Expand All @@ -193,7 +193,7 @@ var _ = Describe("UAAClient", func() {

_, err := tc.uaaClient.Read(withBearer(toBeExpiredToken))
Expect(err).ToNot(HaveOccurred())
Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount))

newTokenKey := generateLegitTokenKey("testKey2")
refreshedToken := tc.CreateSignedTokenUsingPrivateKey(payload, newTokenKey)
Expand All @@ -202,11 +202,11 @@ var _ = Describe("UAAClient", func() {

_, err = tc.uaaClient.Read(withBearer(refreshedToken))
Expect(err).To(HaveOccurred())
Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))

_, err = tc.uaaClient.Read(withBearer(toBeExpiredToken))
Expect(err).ToNot(HaveOccurred())
Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))
})
})

Expand All @@ -221,7 +221,7 @@ var _ = Describe("UAAClient", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to decode token: using unknown token key"))

Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))
})

It("returns an error when the provided token cannot be decoded", func() {
Expand Down Expand Up @@ -273,7 +273,7 @@ var _ = Describe("UAAClient", func() {

wg.Wait()

Expect(len(tc.httpClient.requests)).To(Equal(numRequests + 4))
Expect(tc.httpClient.requests).To(HaveLen(numRequests + 4))
})

It("calls UAA correctly", func() {
Expand Down Expand Up @@ -427,17 +427,17 @@ var _ = Describe("UAAClient", func() {

err := tc.uaaClient.RefreshTokenKeys()
Expect(err).ToNot(HaveOccurred())
Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))

time.Sleep(100 * time.Millisecond)
err = tc.uaaClient.RefreshTokenKeys()
Expect(err).To(HaveOccurred())
Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 1))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 1))

time.Sleep(101 * time.Millisecond)
err = tc.uaaClient.RefreshTokenKeys()
Expect(err).To(HaveOccurred())
Expect(len(tc.httpClient.requests)).To(Equal(initialRequestCount + 2))
Expect(tc.httpClient.requests).To(HaveLen(initialRequestCount + 2))
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/internal/cache/log_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ var _ = Describe("LogCache", func() {
return err
}

Expect(len(resp.GetMatrix().GetSeries())).To(Equal(1))
Expect(len(resp.GetMatrix().GetSeries()[0].GetPoints())).To(Equal(1))
Expect(resp.GetMatrix().GetSeries()).To(HaveLen(1))
Expect(resp.GetMatrix().GetSeries()[0].GetPoints()).To(HaveLen(1))

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/nozzle/nozzle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var _ = Describe("Nozzle", func() {
},
))

Eventually(streamConnector.envelopes).Should(HaveLen(0))
Eventually(streamConnector.envelopes).Should(BeEmpty())
})
})

Expand Down Expand Up @@ -167,7 +167,7 @@ var _ = Describe("Nozzle", func() {
},
))

Eventually(streamConnector.envelopes).Should(HaveLen(0))
Eventually(streamConnector.envelopes).Should(BeEmpty())
})

It("writes each envelope to the LogCache", func() {
Expand Down
12 changes: 6 additions & 6 deletions src/pkg/marshaler/marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ var _ = Describe("PromqlMarshaler", func() {
}`), &result)
Expect(err).ToNot(HaveOccurred())

Expect(len(result.GetVector().GetSamples())).To(Equal(2))
Expect(result.GetVector().GetSamples()).To(HaveLen(2))
Expect(result.GetVector().GetSamples()[0].GetMetric()).To(Equal(map[string]string{
"deployment": "cf",
"tag-name": "tag-value",
Expand Down Expand Up @@ -606,7 +606,7 @@ var _ = Describe("PromqlMarshaler", func() {
}`), &result)
Expect(err).ToNot(HaveOccurred())

Expect(len(result.GetMatrix().GetSeries())).To(Equal(2))
Expect(result.GetMatrix().GetSeries()).To(HaveLen(2))
Expect(result.GetMatrix().GetSeries()[0].GetMetric()).To(Equal(map[string]string{
"deployment": "cf",
"tag-name": "tag-value",
Expand All @@ -615,12 +615,12 @@ var _ = Describe("PromqlMarshaler", func() {
"deployment": "cf",
"tag-name2": "tag-value2",
}))
Expect(len(result.GetMatrix().GetSeries()[0].GetPoints())).To(Equal(2))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()).To(HaveLen(2))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[0].GetTime()).To(Equal("1.987"))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[0].GetValue()).To(Equal(2.5))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[1].GetTime()).To(Equal("2.000"))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[1].GetValue()).To(Equal(3.5))
Expect(len(result.GetMatrix().GetSeries()[1].GetPoints())).To(Equal(2))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()).To(HaveLen(2))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()[0].GetTime()).To(Equal("1.000"))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()[0].GetValue()).To(Equal(4.5))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()[1].GetTime()).To(Equal("2.000"))
Expand Down Expand Up @@ -661,12 +661,12 @@ var _ = Describe("PromqlMarshaler", func() {
}`), &result)
Expect(err).ToNot(HaveOccurred())

Expect(len(result.GetMatrix().GetSeries()[0].GetPoints())).To(Equal(2))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()).To(HaveLen(2))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[0].GetTime()).To(Equal("1.987"))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[0].GetValue()).To(Equal(2.5))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[1].GetTime()).To(Equal("2.000"))
Expect(result.GetMatrix().GetSeries()[0].GetPoints()[1].GetValue()).To(Equal(3.5))
Expect(len(result.GetMatrix().GetSeries()[1].GetPoints())).To(Equal(2))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()).To(HaveLen(2))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()[0].GetTime()).To(Equal("1.000"))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()[0].GetValue()).To(Equal(4.5))
Expect(result.GetMatrix().GetSeries()[1].GetPoints()[1].GetTime()).To(Equal("2.000"))
Expand Down

0 comments on commit 07da6a9

Please sign in to comment.