oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipotest
2
3import (
4 "bytes"
5 "os"
6 "path/filepath"
7 "testing"
8
9 "amadan.net/rastrillo/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 // "tokens.css": true,
24 //
25 // Only the sidebar and console shells link shell.js and shell.css.
26 // An app on another shell that deletes them records it here, or this
27 // test fails on the missing files:
28 // "shell.js": true, "shell.css": true,
29}
30
31// The scaffold delivered these files once; they are app-owned from
32// then on. This test pins each vendored copy byte-identical to the
33// library it came from: a reviewer runs the suite instead of reading
34// ~56KB of assets as app diff, and a framework upgrade that forgets
35// to re-copy is caught instead of drifting silently.
36//
37// The list is ui.VendoredAssets — the same function rastrillo new
38// wrote these files from and rastrillo doctor compares them against —
39// so a file added to the library's vendored set is pinned here without
40// this file changing.
41func TestVendoredAssetsMatchTheLibrary(t *testing.T) {
42 t.Parallel()
43 assets, ok := ui.VendoredAssets(vendoredTheme)
44 if !ok {
45 t.Fatalf("unknown theme %q", vendoredTheme)
46 }
47 for name, lib := range assets {
48 if vendoredIsMine[name] {
49 continue
50 }
51 vendored, err := os.ReadFile(filepath.Join("..", "equipo", "static", name))
52 if err != nil {
53 t.Errorf("read vendored %s: %v", name, err)
54 continue
55 }
56 if !bytes.Equal(vendored, lib) {
57 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)
58 }
59 }
60}
61