Skip to content

Commit

Permalink
metricsserver -> fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Mar 13, 2023
1 parent d5d8d81 commit 3a70a0b
Showing 1 changed file with 9 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@ var _ = Describe("MetricsServer", func() {
})

It("returns with a 200", func() {
url := fmt.Sprintf("http://127.0.0.1:%d/v1/apps/an-app-id/metric_histories/a-metric-type", msPort)
rsp, err := httpClient.Get(url)
metricsHistoryUrl := fmt.Sprintf(
"http://127.0.0.1:%d/v1/apps/an-app-id/metric_histories/a-metric-type", msPort)
rsp, err := httpClient.Get(metricsHistoryUrl)
Expect(err).NotTo(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
rsp.Body.Close()
})
})
})

Describe("when Health server is ready to serve RESTful API", func() {
Describe("when Health server is ready to serve RESTful API without basic auth", func() {
BeforeEach(func() {
basicAuthConfig := cfg
basicAuthConfig.Health.HealthCheckUsername = ""
Expand All @@ -123,7 +124,7 @@ var _ = Describe("MetricsServer", func() {
runner.configPath = writeConfig(&basicAuthConfig).Name()
runner.Start()
})
Context("when a request to query health comes", func() {
Context("when a request to query prometheus comes", func() {
It("returns with a 200", func() {
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.PrometheusPath)
rsp, err := healthHttpClient.Get(url)
Expand All @@ -148,8 +149,8 @@ var _ = Describe("MetricsServer", func() {

Context("when username and password are incorrect for basic authentication during health check", func() {
It("should return 401", func() {
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath)
req, err := http.NewRequest(http.MethodGet, url, nil)
livenessUrl := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath)
req, err := http.NewRequest(http.MethodGet, livenessUrl, nil)
Expect(err).NotTo(HaveOccurred())

req.SetBasicAuth("wrongusername", "wrongpassword")
Expand All @@ -162,8 +163,8 @@ var _ = Describe("MetricsServer", func() {

Context("when username and password are correct for basic authentication during health check", func() {
It("should return 200", func() {
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath)
req, err := http.NewRequest(http.MethodGet, url, nil)
livenessUrl := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath)
req, err := http.NewRequest(http.MethodGet, livenessUrl, nil)
Expect(err).NotTo(HaveOccurred())

req.SetBasicAuth(cfg.Health.HealthCheckUsername, cfg.Health.HealthCheckPassword)
Expand All @@ -174,41 +175,5 @@ var _ = Describe("MetricsServer", func() {
})
})
})

Describe("when Health server is ready to serve RESTful API with basic Auth", func() {
BeforeEach(func() {
runner.Start()
})

Context("when username and password are incorrect for basic authentication during health check", func() {
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath)

It("should return 401", func() {
req, err := http.NewRequest(http.MethodGet, url, nil)
Expect(err).NotTo(HaveOccurred())

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

rsp, err := healthHttpClient.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusUnauthorized))
})
})

Context("when username and password are correct for basic authentication during health check", func() {
It("should return 200", func() {
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath)
req, err := http.NewRequest(http.MethodGet, url, nil)
Expect(err).NotTo(HaveOccurred())

req.SetBasicAuth(cfg.Health.HealthCheckUsername, cfg.Health.HealthCheckPassword)

rsp, err := healthHttpClient.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
})
})
})

//TODO : Add test cases for testing WebServer endpoints
})

0 comments on commit 3a70a0b

Please sign in to comment.