MCPcopy Create free account
hub / github.com/BryanMwangi/pine / TestRender_HTML_SimpleTemplate

Function TestRender_HTML_SimpleTemplate

render/engine_test.go:41–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestRender_HTML_SimpleTemplate(t *testing.T) {
42 dir := makeViewDir(t, map[string]string{
43 "index.html": `<h1>Hello, {{.Name}}!</h1>`,
44 })
45
46 server := setupServer(t, dir)
47 server.Get("/", func(c *pine.Ctx) error {
48 return c.Render("index.html", map[string]string{"Name": "Pine"})
49 })
50
51 req := httptest.NewRequest(http.MethodGet, "/", nil)
52 rr := httptest.NewRecorder()
53 server.ServeHTTP(rr, req)
54
55 if rr.Code != http.StatusOK {
56 t.Fatalf("expected 200, got %d", rr.Code)
57 }
58 if ct := rr.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/html") {
59 t.Errorf("expected text/html content-type, got %q", ct)
60 }
61 if body := rr.Body.String(); !strings.Contains(body, "Hello, Pine!") {
62 t.Errorf("expected 'Hello, Pine!' in body, got %q", body)
63 }
64}
65
66func TestRender_HTML_SubdirectoryTemplate(t *testing.T) {
67 dir := makeViewDir(t, map[string]string{

Callers

nothing calls this directly

Calls 6

makeViewDirFunction · 0.85
setupServerFunction · 0.85
ServeHTTPMethod · 0.80
HeaderMethod · 0.80
RenderMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected