(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func 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 | |
| 66 | func TestRender_HTML_SubdirectoryTemplate(t *testing.T) { |
| 67 | dir := makeViewDir(t, map[string]string{ |
nothing calls this directly
no test coverage detected