Skip to content

Commit

Permalink
WIP: Fix metricsserver-test-suite;
Browse files Browse the repository at this point in the history
  • Loading branch information
joergdw committed Mar 13, 2023
1 parent 96022b2 commit d5d8d81
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -103,28 +104,29 @@ var _ = Describe("MetricsServer", func() {
})

It("returns with a 200", func() {
rsp, err := httpClient.Get(fmt.Sprintf("http://127.0.0.1:%d/v1/apps/an-app-id/metric_histories/a-metric-type", msPort))
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)
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() {
BeforeEach(func() {

basicAuthConfig := cfg
basicAuthConfig.Health.HealthCheckUsername = ""
basicAuthConfig.Health.HealthCheckPassword = ""
basicAuthConfig.Health.UnprotectedEndpoints = []string{"/", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}
runner.configPath = writeConfig(&basicAuthConfig).Name()
runner.Start()

})
Context("when a request to query health comes", func() {
It("returns with a 200", func() {
rsp, err := healthHttpClient.Get(fmt.Sprintf("http://127.0.0.1:%d", healthport))
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.PrometheusPath)
rsp, err := healthHttpClient.Get(url)
Expect(err).NotTo(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
raw, _ := io.ReadAll(rsp.Body)
Expand All @@ -135,7 +137,6 @@ var _ = Describe("MetricsServer", func() {
Expect(healthData).To(ContainSubstring("go_goroutines"))
Expect(healthData).To(ContainSubstring("go_memstats_alloc_bytes"))
rsp.Body.Close()

})
})
})
Expand All @@ -147,8 +148,8 @@ var _ = Describe("MetricsServer", func() {

Context("when username and password are incorrect for basic authentication during health check", func() {
It("should return 401", func() {

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil)
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("wrongusername", "wrongpassword")
Expand All @@ -161,8 +162,8 @@ var _ = Describe("MetricsServer", func() {

Context("when username and password are correct for basic authentication during health check", func() {
It("should return 200", func() {

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil)
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)
Expand All @@ -180,9 +181,10 @@ 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, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil)
It("should return 401", func() {
req, err := http.NewRequest(http.MethodGet, url, nil)
Expect(err).NotTo(HaveOccurred())

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

Context("when username and password are correct for basic authentication during health check", func() {
It("should return 200", func() {

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil)
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)
Expand Down

0 comments on commit d5d8d81

Please sign in to comment.