Download this file
| 1 | package codex |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "os" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestPinnedCoordinatorNotices(t *testing.T) { |
| 10 | raw, err := os.ReadFile("testdata/coordinator-notices-0.165.0.json") |
| 11 | if err != nil { |
| 12 | t.Fatal(err) |
| 13 | } |
| 14 | var frames []map[string]any |
| 15 | if err = json.Unmarshal(raw, &frames); err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | if len(frames) != 5 { |
| 19 | t.Fatal("incomplete fixture") |
| 20 | } |
| 21 | for _, f := range frames { |
| 22 | if ev, err := Decode(marshal(f)); err != nil || len(ev) != 0 { |
| 23 | t.Fatalf("pinned notice became session event: %v", err) |
| 24 | } |
| 25 | for _, field := range []string{"summary", "details", "extra"} { |
| 26 | p := f["params"].(map[string]any) |
| 27 | before, exists := p[field] |
| 28 | p[field] = "unexpected" |
| 29 | if _, err := Decode(marshal(f)); err == nil { |
| 30 | t.Fatal("unexpected notice accepted", field) |
| 31 | } |
| 32 | if exists { |
| 33 | p[field] = before |
| 34 | } else { |
| 35 | delete(p, field) |
| 36 | } |
| 37 | } |
| 38 | f["id"] = 1 |
| 39 | if _, err := Decode(marshal(f)); err == nil { |
| 40 | t.Fatal("request suppressed") |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |