Add fast iteration tooling
nix run .#fast, .#test and .#webui-dev; see DEVELOPING.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDevAssetsAreReloaded(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.CopyFS(dir, os.DirFS(".")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := assets
|
||||
assets = os.DirFS(dir)
|
||||
defer func() { assets = old }()
|
||||
|
||||
sys := System{ConfigDir: filepath.Join(dir, "config"), StateDir: dir}
|
||||
a := newApp(sys, newCollector(sys, ""), true)
|
||||
h := a.routes()
|
||||
if strings.Contains(do(h, "GET", "/login", nil, nil).Body.String(), "reloaded-marker") {
|
||||
t.Fatal("marker already there")
|
||||
}
|
||||
|
||||
login := filepath.Join(dir, "templates", "login.html")
|
||||
data, _ := os.ReadFile(login)
|
||||
i := strings.LastIndex(string(data), "{{end}}")
|
||||
os.WriteFile(login, []byte(string(data)[:i]+"<p>reloaded-marker</p>"+string(data)[i:]), 0o600)
|
||||
if !strings.Contains(do(h, "GET", "/login", nil, nil).Body.String(), "reloaded-marker") {
|
||||
t.Fatal("an edited template is not picked up")
|
||||
}
|
||||
|
||||
// A typo keeps the last good version.
|
||||
os.WriteFile(login, []byte("{{define \"content\"}}{{ broken"), 0o600)
|
||||
if !strings.Contains(do(h, "GET", "/login", nil, nil).Body.String(), "reloaded-marker") {
|
||||
t.Fatal("a broken template replaced the working one")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user