From d91d73a4850b9473d103052e7ca6649fa802453c Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Mon, 7 Feb 2022 23:32:11 +0300 Subject: [PATCH] Refactor the test environment lookup --- tap/api/api.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tap/api/api.go b/tap/api/api.go index 6c679c590..12240d3ff 100644 --- a/tap/api/api.go +++ b/tap/api/api.go @@ -16,6 +16,8 @@ import ( "github.com/google/martian/har" ) +const mizuTestEnvVar = "MIZU_TEST" + type Protocol struct { Name string `json:"name"` LongName string `json:"longName"` @@ -262,6 +264,7 @@ type HTTPWrapper struct { } func (h HTTPPayload) MarshalJSON() ([]byte, error) { + _, testEnvEnabled := os.LookupEnv("MIZU_TEST") switch h.Type { case TypeHttpRequest: harRequest, err := har.NewRequest(h.Data.(*http.Request), true) @@ -286,12 +289,11 @@ func (h HTTPPayload) MarshalJSON() ([]byte, error) { } return harRequest.QueryString[i].Value < harRequest.QueryString[j].Value }) - _, present := os.LookupEnv("MIZU_TEST") - if present { + if testEnvEnabled { harRequest.URL = "" } var reqWrapper *HTTPRequestWrapper - if !present { + if !testEnvEnabled { reqWrapper = &HTTPRequestWrapper{Request: h.Data.(*http.Request)} } return json.Marshal(&HTTPWrapper{ @@ -322,9 +324,8 @@ func (h HTTPPayload) MarshalJSON() ([]byte, error) { } return harResponse.Cookies[i].Value < harResponse.Cookies[j].Value }) - _, present := os.LookupEnv("MIZU_TEST") var resWrapper *HTTPResponseWrapper - if !present { + if !testEnvEnabled { resWrapper = &HTTPResponseWrapper{Response: h.Data.(*http.Response)} } return json.Marshal(&HTTPWrapper{