From 052f6b6fff93f91d234404b76d76148bfa285570 Mon Sep 17 00:00:00 2001 From: Andrew McDermott Date: Wed, 20 Nov 2024 10:58:51 +0000 Subject: [PATCH] test/http2: Add custom-response endpoint for flexible e2e testing Add a `/custom-response` endpoint that returns a configurable response via the `CUSTOM_RESPONSE` environment variable. Enable flexible e2e testing by allowing customised backend responses to simulate various routing and behaviour scenarios without modifying the application or rebuilding the container. --- test/http2/server.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/http2/server.go b/test/http2/server.go index d50c05897..b06acb6d5 100644 --- a/test/http2/server.go +++ b/test/http2/server.go @@ -24,6 +24,7 @@ func lookupEnv(key, defaultVal string) string { func Serve() { crtFile := lookupEnv("TLS_CRT", defaultTLSCrt) keyFile := lookupEnv("TLS_KEY", defaultTLSKey) + customResponse := lookupEnv("CUSTOM_RESPONSE", "custom response") http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { fmt.Fprint(w, req.Proto) @@ -33,6 +34,10 @@ func Serve() { fmt.Fprint(w, "ready") }) + http.HandleFunc("/custom-response", func(w http.ResponseWriter, req *http.Request) { + fmt.Fprint(w, customResponse) + }) + go func() { port := lookupEnv("HTTP_PORT", defaultHTTPPort) log.Printf("Listening on port %v\n", port)