diff --git a/cmd/server/application.go b/cmd/server/application.go index 36910ad..b3beaf1 100644 --- a/cmd/server/application.go +++ b/cmd/server/application.go @@ -8,17 +8,18 @@ import ( "os" "time" - "github.com/a-h/templ" "github.com/alexedwards/scs/v2" "github.com/go-playground/form/v4" - "github.com/m1yon/jobsummoner/internal/components" "github.com/m1yon/jobsummoner/internal/models" "github.com/m1yon/jobsummoner/internal/sqlite3store" ) +type Renderer interface { + Render(ctx context.Context, w io.Writer) error +} + type application struct { logger *slog.Logger - Render func(component templ.Component, ctx context.Context, w io.Writer) error jobs models.JobModelInterface users models.UserModelInterface sessionManager *scs.SessionManager @@ -35,7 +36,6 @@ func newApplication(logger *slog.Logger, jobs models.JobModelInterface, users mo app := &application{ logger: logger, - Render: components.Render, jobs: jobs, users: users, sessionManager: sessionManager, diff --git a/cmd/server/handlers_test.go b/cmd/server/handlers_test.go index a8d1be7..3e22239 100644 --- a/cmd/server/handlers_test.go +++ b/cmd/server/handlers_test.go @@ -2,15 +2,11 @@ package main import ( "context" - "errors" "fmt" - "io" - "net/http" "strings" "testing" "github.com/PuerkitoBio/goquery" - "github.com/a-h/templ" "github.com/m1yon/jobsummoner/internal/models" _ "github.com/m1yon/jobsummoner/internal/testing" "github.com/stretchr/testify/assert" @@ -51,21 +47,6 @@ func TestHomepage(t *testing.T) { assert.Equal(t, 200, code) assertHeadingExists(t, body, "m1yon/jobsummoner") }) - - t.Run("handles a template rendering failure", func(t *testing.T) { - app := newTestApplication(t) - app.Render = func(component templ.Component, ctx context.Context, w io.Writer) error { - return errors.New("could not render template") - } - - ts := newTestServer(t, app.routes()) - defer ts.Close() - - code, _, body := ts.get(t, "/") - - assert.Equal(t, http.StatusOK, code) - assert.Contains(t, body, "Internal Server Error") - }) } func assertHeadingExists(t *testing.T, body string, text string) { diff --git a/cmd/server/helpers.go b/cmd/server/helpers.go index e4bdfe7..1ddccc6 100644 --- a/cmd/server/helpers.go +++ b/cmd/server/helpers.go @@ -47,7 +47,7 @@ func (app *application) decodePostForm(r *http.Request, dst any) error { func (app *application) render(w http.ResponseWriter, r *http.Request, status int, component templ.Component) { w.WriteHeader(status) - err := app.Render(component, context.Background(), w) + err := templ.Component.Render(component, context.Background(), w) if err != nil { app.serverError(w, r, err) return diff --git a/internal/components/components.go b/internal/components/components.go deleted file mode 100644 index 5161d53..0000000 --- a/internal/components/components.go +++ /dev/null @@ -1,12 +0,0 @@ -package components - -import ( - "context" - "io" - - "github.com/a-h/templ" -) - -func Render(component templ.Component, ctx context.Context, w io.Writer) error { - return component.Render(ctx, w) -}