rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1package gallery
2
3import (
4 "slices"
5 "testing"
6)
7
8// TestFingerprintedNamesTheHashedTwinsOnly: an asset's hashed name is
9// listed under the mount when the tree holds it beside its plain twin
10// with the same bytes. The plain twin is not listed, since its bytes
11// change under the same name, and neither is a name that merely looks
12// hashed: one whose hex is not its own bytes' hash, or one with no
13// plain twin, could be replaced by other bytes under the same name.
14// Nor is a twin under the plain file's true hashed name that holds
15// other bytes, a corrupted copy: the name is right, so only comparing
16// the bytes keeps a browser from holding the wrong ones for a year.
17func TestFingerprintedNamesTheHashedTwinsOnly(t *testing.T) {
18 css, js, pic := []byte("body{}\n"), []byte("0\n"), []byte("GIF89a")
19 plain, corrupted := []byte("main{}\n"), []byte("main{color:red}\n")
20 tree := map[string][]byte{
21 "assets/css/fiesta.css": css,
22 "assets/css/" + hashedName("fiesta.css", css): css,
23 "assets/gallery.js": js,
24 "assets/" + hashedName("gallery.js", js): js,
25 "assets/images/a.gif": pic,
26 "assets/images/" + hashedName("a.gif", pic): pic,
27 "assets/lone.0123456789abcdef.css": css,
28 "assets/wrong.css": css,
29 "assets/wrong.0123456789abcdef.css": css,
30 "assets/torn.css": plain,
31 "assets/" + hashedName("torn.css", plain): corrupted,
32 "day/en/" + hashedName("page.html", js): js,
33 "day/en/page.html": js,
34 }
35 want := []string{
36 "/x/assets/" + hashedName("gallery.js", js),
37 "/x/assets/css/" + hashedName("fiesta.css", css),
38 "/x/assets/images/" + hashedName("a.gif", pic),
39 }
40 slices.Sort(want)
41 if got := Fingerprinted("/x/", tree); !slices.Equal(got, want) {
42 t.Errorf("Fingerprinted is\n%q\nwant\n%q", got, want)
43 }
44}
45