From d3e352964a46005eebcc934381643015ac1709ac Mon Sep 17 00:00:00 2001 From: mihir Date: Wed, 13 Mar 2024 19:50:46 +0530 Subject: [PATCH] export config BE http request handler for transformer --- testhelper/docker/resource/transformer/transformer.go | 4 ++-- .../resource/transformer/transformer_backend_config.go | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/testhelper/docker/resource/transformer/transformer.go b/testhelper/docker/resource/transformer/transformer.go index f73bcd91..28030ab8 100644 --- a/testhelper/docker/resource/transformer/transformer.go +++ b/testhelper/docker/resource/transformer/transformer.go @@ -56,7 +56,7 @@ func (c *config) setBackendConfigURL(url string) { // }) func WithUserTransformations(transformations map[string]string, cleaner resource.Cleaner) func(*config) { return func(conf *config) { - backendConfigSvc := NewTestBackendConfigServer(transformations) + backendConfigSvc := newTestBackendConfigServer(transformations) conf.setBackendConfigURL(dockerTestHelper.ToInternalDockerHost(backendConfigSvc.URL)) conf.extraHosts = append(conf.extraHosts, "host.docker.internal:host-gateway") @@ -78,7 +78,7 @@ func WithConnectionToHostEnabled() func(*config) { // WithConfigBackendURL should not be used with WithUserTransformations option func WithConfigBackendURL(url string) func(*config) { return func(conf *config) { - conf.setBackendConfigURL(url) + conf.setBackendConfigURL(dockerTestHelper.ToInternalDockerHost(url)) } } diff --git a/testhelper/docker/resource/transformer/transformer_backend_config.go b/testhelper/docker/resource/transformer/transformer_backend_config.go index dcfc7520..12c0edbc 100644 --- a/testhelper/docker/resource/transformer/transformer_backend_config.go +++ b/testhelper/docker/resource/transformer/transformer_backend_config.go @@ -14,10 +14,15 @@ const ( versionIDKey = "versionId" ) -func NewTestBackendConfigServer(transformations map[string]string) *kithttptest.Server { +func newTestBackendConfigServer(transformations map[string]string) *kithttptest.Server { + return kithttptest.NewServer(NewTransformerBackendConfigHandler(transformations)) +} + +// NewTransformerBackendConfigHandler returns http request handler to handle all backend config requests by transformer +func NewTransformerBackendConfigHandler(transformations map[string]string) http.Handler { mux := http.NewServeMux() mux.HandleFunc(getByVersionIdEndPoint, getByVersionIdHandler(transformations)) - return kithttptest.NewServer(mux) + return mux } func getByVersionIdHandler(transformations map[string]string) func(http.ResponseWriter, *http.Request) {