From 86218534c831b3fc6fdfb98f5ad334262d7060ae Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Mon, 23 Jan 2023 10:27:10 -0800 Subject: Drop gohtml dependency (#70) This dependency is used to format and compare HTML. An additional dependency isn't needed; we can use the existing (previously transitive) x/net package to reformat and compare the HTML. --- utils_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'utils_test.go') diff --git a/utils_test.go b/utils_test.go index 1388475..5eaf0ba 100644 --- a/utils_test.go +++ b/utils_test.go @@ -1,13 +1,16 @@ package main import ( + "bytes" "net/http" "net/http/httptest" "os" + "strings" "testing" "github.com/stretchr/testify/assert" - "github.com/yosssi/gohtml" + "github.com/stretchr/testify/require" + "golang.org/x/net/html" ) // TempFile persists contents and returns the path and a clean func @@ -61,5 +64,14 @@ func CallAndRecord(t *testing.T, config string, uri string) *httptest.ResponseRe // AssertResponse normalizes and asserts the body from rr against want func AssertResponse(t *testing.T, rr *httptest.ResponseRecorder, code int, want string) { assert.Equal(t, rr.Code, code) - assert.Equal(t, gohtml.Format(want), gohtml.Format(rr.Body.String())) + assert.Equal(t, reformatHTML(t, want), reformatHTML(t, rr.Body.String())) +} + +func reformatHTML(t *testing.T, s string) string { + n, err := html.Parse(strings.NewReader(s)) + require.NoError(t, err) + + var buff bytes.Buffer + require.NoError(t, html.Render(&buff, n)) + return buff.String() } -- cgit v1.2.3