oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1package slides
2
3import (
4 "strings"
5 "testing"
6
7 "amadan.net/oficina/slides/internal/slides/deck"
8)
9
10// TestSceneRefusal: what a posted update may leave in a scene it added
11// or changed, and that a scene it did not touch is not its doing.
12func TestSceneRefusal(t *testing.T) {
13 ok := deck.Scene{Code: strings.Repeat("ab", 32), States: []deck.SceneState{{ID: "a"}}, Words: map[string]string{"k": "__proto__"}, Data: []any{"__proto__"}}
14 with := func(id string, f func(*deck.Scene)) *deck.Deck {
15 s := ok
16 if f != nil {
17 f(&s)
18 }
19 return &deck.Deck{Scenes: map[string]deck.Scene{id: s}}
20 }
21 empty := &deck.Deck{}
22 if err := sceneRefusal(empty, with("abcdefghij27", nil)); err != nil {
23 t.Fatalf("a good scene: %v", err)
24 }
25 for name, after := range map[string]*deck.Deck{
26 "empty id": with("", nil),
27 "bad id": with("Scene0000001", nil),
28 "proto id": with("__proto__", nil),
29 "state proto": with("abcdefghij27", func(s *deck.Scene) { s.States = []deck.SceneState{{ID: "__proto__"}} }),
30 "word proto": with("abcdefghij27", func(s *deck.Scene) { s.Words = map[string]string{"__proto__": "x"} }),
31 "data proto": with("abcdefghij27", func(s *deck.Scene) { s.Data = []any{map[string]any{"a": map[string]any{"__proto__": 1.0}}} }),
32 "data size": with("abcdefghij27", func(s *deck.Scene) { s.Data = strings.Repeat("x", deck.MaxSceneData-1) }),
33 } {
34 if err := sceneRefusal(empty, after); err == nil {
35 t.Errorf("%s: no refusal", name)
36 }
37 }
38 // Exactly the limit is fine.
39 if err := sceneRefusal(empty, with("abcdefghij27", func(s *deck.Scene) { s.Data = strings.Repeat("x", deck.MaxSceneData-2) })); err != nil {
40 t.Errorf("at the limit: %v", err)
41 }
42 // Untouched since before: not this update's doing.
43 old := with("", func(s *deck.Scene) { s.Data = strings.Repeat("x", deck.MaxSceneData) })
44 if err := sceneRefusal(old, old); err != nil {
45 t.Errorf("an untouched scene: %v", err)
46 }
47}
48