test: check parsing of templates

This commit is contained in:
Ivan R. 2024-03-25 16:09:55 +05:00
parent ac54a6f854
commit 76275010a8
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C
3 changed files with 39 additions and 3 deletions

View file

@ -1,10 +1,13 @@
all: fmt vet
all: fmt test
fmt:
gofmt -s -w .
vet:
go vet ./...
test:
go test ./...
run:
go run .
favicons:
convert -background none assets/favicons/favicon.svg -resize 16x16 assets/favicons/favicon-16.png

15
testutils/workingdir.go Normal file
View file

@ -0,0 +1,15 @@
package testutils
import (
"os"
"path"
"runtime"
)
// Change the current directory to the project directory.
// Useful for tests that work with files.
func ResetWorkingDir() error {
_, filename, _, _ := runtime.Caller(0)
dir := path.Join(path.Dir(filename), "..")
return os.Chdir(dir)
}

View file

@ -0,0 +1,18 @@
package pages
import (
"testing"
"github.com/ordinary-dev/phoenix/testutils"
)
// Check that all templates can be loaded.
func TestLoadTemplates(t *testing.T) {
if err := testutils.ResetWorkingDir(); err != nil {
t.Fatal(err)
}
if err := LoadTemplates(); err != nil {
t.Fatal(err)
}
}