Go · 1509 bytes Raw Blame History
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2
3 package handlers
4
5 import (
6 "io/fs"
7 "testing"
8 "testing/fstest"
9 )
10
11 // testTemplatesFS returns a minimal in-memory templates filesystem matching
12 // the layout the production embed produces (after Sub-rooting).
13 func testTemplatesFS(t *testing.T) fs.FS {
14 t.Helper()
15 return fstest.MapFS{
16 "_layout.html": &fstest.MapFile{
17 Data: []byte(`{{ define "layout" }}<!DOCTYPE html><html><head>{{ if stringField . "MetaDescription" }}<meta name="description" content="{{ stringField . "MetaDescription" }}">{{ end }}{{ with stringField . "CanonicalURL" }}<link rel="canonical" href="{{ . }}">{{ end }}<title>{{ .Title }} · shithub</title></head><body>{{ template "page" . }}</body></html>{{ end }}`),
18 },
19 "hello.html": &fstest.MapFile{
20 Data: []byte(`{{ define "page" }}<main>shithub - GitHub. Open source. Without Copilot. Sprint 00 v{{ .Version }}</main>{{ end }}`),
21 },
22 "about.html": &fstest.MapFile{
23 Data: []byte(`{{ define "page" }}<main>No hard feelings to GitHub. I just don't want AI training on my code.</main>{{ end }}`),
24 },
25 }
26 }
27
28 // testStaticFS returns a minimal in-memory static filesystem matching the
29 // layout the production embed produces.
30 func testStaticFS(t *testing.T) fs.FS {
31 t.Helper()
32 return fstest.MapFS{
33 "logo/shithub.svg": &fstest.MapFile{
34 Data: []byte(`<svg xmlns="http://www.w3.org/2000/svg"><title>shithub</title></svg>`),
35 },
36 "css/shithub.css": &fstest.MapFile{
37 Data: []byte(`body { color: black; }`),
38 },
39 }
40 }
41