diff --git a/handler_test.go b/handler_test.go index 36ab1e7..dfddfcc 100644 --- a/handler_test.go +++ b/handler_test.go @@ -274,7 +274,7 @@ func TestIndexHandler_rangeOf(t *testing.T) { } func TestCustomTemplates(t *testing.T) { - t.Run("fails to create handler if template is missing", func(t *testing.T) { + t.Run("missing", func(t *testing.T) { for _, name := range []string{"index.html", "package.html", "404.html"} { templatesText := map[string]string{ "index.html": "index", @@ -295,7 +295,7 @@ func TestCustomTemplates(t *testing.T) { } }) - t.Run("only replaces correct templates", func(t *testing.T) { + t.Run("replace", func(t *testing.T) { templates := getTestTemplates(t, map[string]string{ "404.html": "not found: {{ .Path }}", }) @@ -332,7 +332,7 @@ func BenchmarkHandlerDispatch(b *testing.B) { Repo: "github.com/yarpc/metrics", }, }, - }, template.Must(_templates.Clone())) + }, getTestTemplates(b, nil)) require.NoError(b, err) resw := new(nopResponseWriter) diff --git a/main.go b/main.go index 8d2af3f..522ecf8 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,5 @@ func getCombinedTemplates(dir string) (*template.Template, error) { if err != nil { return nil, err } - templates, err = templates.ParseGlob(filepath.Join(dir, "*.html")) - return templates, err + return templates.ParseGlob(filepath.Join(dir, "*.html")) } diff --git a/utils_test.go b/utils_test.go index 79a6fea..56eadfd 100644 --- a/utils_test.go +++ b/utils_test.go @@ -69,23 +69,23 @@ func AssertResponse(t *testing.T, rr *httptest.ResponseRecorder, code int, want // getTestTemplates returns a [template.Template] object with the default templates, // overwritten by the [overrideTemplates]. If [overrideTemplates] is nil, the returned // templates are a clone of the global [_templates]. -func getTestTemplates(t *testing.T, overrideTemplates map[string]string) *template.Template { +func getTestTemplates(tb testing.TB, overrideTemplates map[string]string) *template.Template { if len(overrideTemplates) == 0 { // We must clone! Cloning can only be done before templates are executed. Therefore, // we cannot run some tests without cloning, and then attempt cloning it. It'll panic. templates, err := _templates.Clone() - require.NoError(t, err) + require.NoError(tb, err) return templates } - templatesDir := t.TempDir() // This is automatically removed at the end of the test. + templatesDir := tb.TempDir() // This is automatically removed at the end of the test. for name, content := range overrideTemplates { err := os.WriteFile(filepath.Join(templatesDir, name), []byte(content), 0666) - require.NoError(t, err) + require.NoError(tb, err) } templates, err := getCombinedTemplates(templatesDir) - require.NoError(t, err) + require.NoError(tb, err) return templates }