Skip to content

Commit

Permalink
fix tests that rely on net/http package appending "\n" to redirect …
Browse files Browse the repository at this point in the history
…link

PiperOrigin-RevId: 609660510
Change-Id: Ia4f512c9e7feca7dcf22c1317279a95be4218b44
  • Loading branch information
Google Cloud Healthcare Team authored and copybara-github committed Feb 23, 2024
1 parent 15ccd7c commit e7e585c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/httputils/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package httputils
import (
"net/http"
"net/url"
"strings"
"testing"

"github.com/google/go-cmp/cmp" /* copybara-comment */
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e7e585c

Please sign in to comment.