Skip to content

Commit

Permalink
Fix test-suite metricsforwarder; integration still in progress as well;
Browse files Browse the repository at this point in the history
  • Loading branch information
joergdw committed Mar 13, 2023
1 parent d556e63 commit 472375b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ test-autoscaler: check-db_type init init-db test-certs
@make -C src/autoscaler test DBURL="${DBURL}" OPTS="${OPTS}"

# ⚠ The target dependencies "autoscaler" and "scheduler" are needed by the integration tests.
# TODO: Introduce make-target for the .war-file and the needed autoscaler-files instead?
test-autoscaler-suite: check-db_type init init-db test-certs autoscaler scheduler
@echo " - using DBURL=${DBURL} TEST=${TEST} OPTS=${OPTS}"
@make -C src/autoscaler testsuite TEST=${TEST} DBURL="${DBURL}" OPTS="${OPTS}"
Expand Down
3 changes: 2 additions & 1 deletion src/autoscaler/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ func deleteSchedule(appId string) (*http.Response, error) {

func getActiveSchedule(appId string) (*http.Response, error) {
By("getActiveSchedule")
req, err := http.NewRequest("GET", fmt.Sprintf("https://127.0.0.1:%d/v1/apps/%s/active_schedules", components.Ports[ScalingEngine], appId), strings.NewReader(""))
url := fmt.Sprintf("https://127.0.0.1:%d/v1/apps/%s/active_schedules", components.Ports[ScalingEngine], appId)
req, err := http.NewRequest("GET", url, strings.NewReader(""))
Expect(err).NotTo(HaveOccurred())
req.Header.Set("Content-Type", "application/json")
return httpClient.Do(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/db"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"

. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -139,18 +140,19 @@ var _ = Describe("Metricsforwarder", func() {

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() {
Context("when a request to query prometheus 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 @@ -174,9 +176,9 @@ var _ = Describe("Metricsforwarder", 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)
It("should return 401 for liveness-path", 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("wrongusername", "wrongpassword")
Expand All @@ -188,9 +190,9 @@ var _ = Describe("Metricsforwarder", func() {
})

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

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil)
It("should return 200 for liveness-path", 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)
Expand All @@ -200,8 +202,12 @@ var _ = Describe("Metricsforwarder", func() {
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
})
It("should return 200 for /health/readiness", func() {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health/readiness", healthport), nil)
url := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.ReadinessPath)
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))
Expand All @@ -223,8 +229,8 @@ var _ = Describe("Metricsforwarder", 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 @@ -237,8 +243,8 @@ var _ = Describe("Metricsforwarder", 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 472375b

Please sign in to comment.