carlos / movement Public

Clone
git clone https://amadan.net/carlos/movement

Plain git — no account needed to clone.

Download

Download this file

1package movementtest
2
3import (
4 "bytes"
5 "os"
6 "path/filepath"
7 "testing"
8
9 "github.com/carlosframework/rastrillo/ui"
10)
11
12// vendoredTheme is the theme this app was scaffolded with. Change it
13// here when you swap static/theme.css for another of ui.ThemeNames().
14const vendoredTheme = "day"
15
16// vendoredIsMine names the vendored files this app has edited
17// DELIBERATELY. Add one here when you mean to diverge: this test stops
18// pinning it, and rastrillo doctor leaves it alone too. The file was
19// yours from the moment the scaffold wrote it — this is only where you
20// record that the edit was on purpose, so the next reader (and the next
21// upgrade) can tell it from drift.
22var vendoredIsMine = map[string]bool{
23 // theme.css is the whole visual identity now, not the scaffold's "day".
24 // The scaffold's own header called day "the theme an app ships on while
25 // it works out what it wants to look like" — this app worked it out, and
26 // what replaced it is the flyposted bill: acid stock, two inks, and the
27 // green that only exists where they overprint.
28 //
29 // tokens.css stays pinned. Structure is still the framework's, and an
30 // upgrade that changes it should still be caught.
31 "theme.css": true,
32}
33
34// The scaffold delivered these files once; they are app-owned from
35// then on. This test pins each vendored copy byte-identical to the
36// library it came from: a reviewer runs the suite instead of reading
37// ~56KB of assets as app diff, and a framework upgrade that forgets
38// to re-copy is caught instead of drifting silently.
39//
40// The list is ui.VendoredAssets — the same function rastrillo new
41// wrote these files from and rastrillo doctor compares them against —
42// so a file added to the library's vendored set is pinned here without
43// this file changing.
44func TestVendoredAssetsMatchTheLibrary(t *testing.T) {
45 assets, ok := ui.VendoredAssets(vendoredTheme)
46 if !ok {
47 t.Fatalf("unknown theme %q", vendoredTheme)
48 }
49 for name, lib := range assets {
50 if vendoredIsMine[name] {
51 continue
52 }
53 vendored, err := os.ReadFile(filepath.Join("..", "movement", "static", name))
54 if err != nil {
55 t.Errorf("read vendored %s: %v", name, err)
56 continue
57 }
58 if !bytes.Equal(vendored, lib) {
59 t.Errorf("static/%s differs from the library copy; re-copy it with rastrillo doctor --fix (or add it to vendoredIsMine if the edit was deliberate)", name)
60 }
61 }
62}
63