From e7e585c39877e1d04b9156483762b70d1f8a1cf8 Mon Sep 17 00:00:00 2001 From: Google Cloud Healthcare Team Date: Fri, 23 Feb 2024 02:19:00 -0800 Subject: [PATCH] fix tests that rely on `net/http` package appending "\n" to redirect link PiperOrigin-RevId: 609660510 Change-Id: Ia4f512c9e7feca7dcf22c1317279a95be4218b44 --- lib/httputils/handle_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/httputils/handle_test.go b/lib/httputils/handle_test.go index 4b49fda..3f02a15 100644 --- a/lib/httputils/handle_test.go +++ b/lib/httputils/handle_test.go @@ -17,6 +17,7 @@ package httputils import ( "net/http" "net/url" + "strings" "testing" "github.com/google/go-cmp/cmp" /* copybara-comment */ @@ -193,6 +194,11 @@ func TestWriteRedirect(t *testing.T) { Body: RedirectHTMLPage(dst), Code: http.StatusSeeOther, } + // TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3. + // https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail. + // Remove all '\n' symbols from both string before comparing. + want.Body = strings.ReplaceAll(want.Body, "\n", "") + w.Body = strings.ReplaceAll(w.Body, "\n", "") if diff := cmp.Diff(want, w); diff != "" { t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff) } @@ -226,6 +232,11 @@ func TestWriteRedirect_ParsedDestination(t *testing.T) { Body: RedirectHTMLPage(dst), Code: http.StatusSeeOther, } + // TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3. + // https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail. + // Remove all '\n' symbols from both string before comparing. + want.Body = strings.ReplaceAll(want.Body, "\n", "") + w.Body = strings.ReplaceAll(w.Body, "\n", "") if diff := cmp.Diff(want, w); diff != "" { t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff) } @@ -254,6 +265,11 @@ func TestWriteRedirect_RelativeDestination(t *testing.T) { Body: RedirectHTMLPage("/srcresources/" + dst), Code: http.StatusSeeOther, } + // TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3. + // https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail. + // Remove all '\n' symbols from both string before comparing. + want.Body = strings.ReplaceAll(want.Body, "\n", "") + w.Body = strings.ReplaceAll(w.Body, "\n", "") if diff := cmp.Diff(want, w); diff != "" { t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff) } @@ -282,6 +298,11 @@ func TestWriteRedirect_RelativeDestinationAtRoot(t *testing.T) { Body: RedirectHTMLPage(dst), Code: http.StatusSeeOther, } + // TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3. + // https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail. + // Remove all '\n' symbols from both string before comparing. + want.Body = strings.ReplaceAll(want.Body, "\n", "") + w.Body = strings.ReplaceAll(w.Body, "\n", "") if diff := cmp.Diff(want, w); diff != "" { t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff) } @@ -329,6 +350,11 @@ func TestWriteRedirect_FullyEncodedRedirectURLParameter(t *testing.T) { Body: RedirectHTMLPage(dst), Code: http.StatusSeeOther, } + // TODO: remove this workaround after we submit new Go toolchain (b/324535216) to google3. + // https://go.dev/cl/562356 removes superfluous newline on redirects and makes this test fail. + // Remove all '\n' symbols from both string before comparing. + want.Body = strings.ReplaceAll(want.Body, "\n", "") + w.Body = strings.ReplaceAll(w.Body, "\n", "") if diff := cmp.Diff(want, w); diff != "" { t.Errorf("WriteRedirect(); Writer diff (-want +got):\n%s", diff) }