Skip to content

Commit

Permalink
Refactor HTTP client variable names and usage in eventgenerator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzofenix committed Jul 29, 2024
1 parent 080ece1 commit 8f7631a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ var (
conf config.Config
egPort int

httpClientForPublicApi *http.Client

healthHttpClient *http.Client
mockLogCache *testhelpers.MockLogCache
mockScalingEngine *ghttp.Server
breachDurationSecs = 10
Expand All @@ -66,11 +63,9 @@ var _ = SynchronizedBeforeSuite(func() []byte {
initDB()
return []byte(eg)
}, func(pathByte []byte) {
healthHttpClient = &http.Client{}
egPath = string(pathByte)
initHttpEndPoints()
initConfig()
httpClientForPublicApi = testhelpers.NewPublicApiClient()
})

var _ = SynchronizedAfterSuite(func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (

var _ = Describe("Eventgenerator", func() {
var (
runner *EventGeneratorRunner
httpsClient *http.Client
serverURL *url.URL
err error
runner *EventGeneratorRunner
httpClientForEventGenerator *http.Client
serverURL *url.URL
err error
)

BeforeEach(func() {
runner = NewEventGeneratorRunner()
httpsClient = testhelpers.NewEventGeneratorClient()
httpClientForEventGenerator = testhelpers.NewEventGeneratorClient()

serverURL, err = url.Parse("http://127.0.0.1:" + strconv.Itoa(conf.Server.Port))
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -142,7 +142,7 @@ var _ = Describe("Eventgenerator", func() {
})

It("returns with a 200", func() {
rsp, err := httpClientForPublicApi.Get(serverURL.String())
rsp, err := httpClientForEventGenerator.Get(serverURL.String())
Expect(err).NotTo(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
rsp.Body.Close()
Expand Down Expand Up @@ -170,7 +170,7 @@ var _ = Describe("Eventgenerator", func() {

When("a request to query health comes", func() {
It("returns with a 200", func() {
rsp, err := httpsClient.Get(fmt.Sprintf("%s/health", serverURL))
rsp, err := httpClientForEventGenerator.Get(fmt.Sprintf("%s/health", serverURL))
Expect(err).NotTo(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))

Expand Down Expand Up @@ -200,7 +200,7 @@ var _ = Describe("Eventgenerator", func() {

req.SetBasicAuth("wrongusername", "wrongpassword")

rsp, err := httpsClient.Do(req)
rsp, err := httpClientForEventGenerator.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusUnauthorized))
})
Expand All @@ -213,7 +213,7 @@ var _ = Describe("Eventgenerator", func() {

req.SetBasicAuth(conf.Health.BasicAuth.Username, conf.Health.BasicAuth.Password)

rsp, err := httpsClient.Do(req)
rsp, err := httpClientForEventGenerator.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
})
Expand All @@ -232,7 +232,7 @@ var _ = Describe("Eventgenerator", func() {

req.SetBasicAuth("wrongusername", "wrongpassword")

rsp, err := httpsClient.Do(req)
rsp, err := httpClientForEventGenerator.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusUnauthorized))
})
Expand All @@ -245,7 +245,7 @@ var _ = Describe("Eventgenerator", func() {

req.SetBasicAuth(conf.Health.BasicAuth.Username, conf.Health.BasicAuth.Password)

rsp, err := httpsClient.Do(req)
rsp, err := httpClientForEventGenerator.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
})
Expand Down

0 comments on commit 8f7631a

Please sign in to comment.