aboutsummaryrefslogtreecommitdiff
path: root/utils_test.go
diff options
context:
space:
mode:
authorAbhinav Gupta <mail@abhinavg.net>2023-01-23 10:27:10 -0800
committerGitHub <noreply@github.com>2023-01-23 10:27:10 -0800
commit86218534c831b3fc6fdfb98f5ad334262d7060ae (patch)
tree6e9d9b125daedce8ea736fed7e8750372c1569ee /utils_test.go
parent9a95dcbf6ef077808a8874beea9d8a2754e60051 (diff)
downloadsally-86218534c831b3fc6fdfb98f5ad334262d7060ae.tar.gz
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.
Diffstat (limited to '')
-rw-r--r--utils_test.go16
1 files changed, 14 insertions, 2 deletions
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()
}