From fda104a04a96df7fdf5df8944293ba14bd85f587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Thu, 9 Mar 2023 17:08:27 +0100 Subject: [PATCH] WIP progress on test-suite metricsforwarder; integration still in progress as well; --- Makefile | 1 + .../integration/integration_suite_test.go | 3 ++- .../metricsforwarder/metricsforwarder_test.go | 26 +++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index f491ff9520..2f2d5d77f2 100644 --- a/Makefile +++ b/Makefile @@ -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}" diff --git a/src/autoscaler/integration/integration_suite_test.go b/src/autoscaler/integration/integration_suite_test.go index a8013c7af5..b999b8d539 100644 --- a/src/autoscaler/integration/integration_suite_test.go +++ b/src/autoscaler/integration/integration_suite_test.go @@ -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) diff --git a/src/autoscaler/metricsforwarder/cmd/metricsforwarder/metricsforwarder_test.go b/src/autoscaler/metricsforwarder/cmd/metricsforwarder/metricsforwarder_test.go index c9da9aaf03..525d4e1102 100644 --- a/src/autoscaler/metricsforwarder/cmd/metricsforwarder/metricsforwarder_test.go +++ b/src/autoscaler/metricsforwarder/cmd/metricsforwarder/metricsforwarder_test.go @@ -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" @@ -139,14 +140,12 @@ 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 = "" runner.configPath = writeConfig(&basicAuthConfig).Name() runner.Start() - }) Context("when a request to query health comes", func() { It("returns with a 200", func() { @@ -174,9 +173,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") @@ -188,9 +187,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) @@ -200,7 +199,8 @@ 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()) rsp, err := healthHttpClient.Do(req) Expect(err).ToNot(HaveOccurred()) @@ -223,8 +223,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") @@ -237,8 +237,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)