tinyrelayfile
tinyrelay/internal/templates/templates_test.go/

internal/templates/templates_test.go raw
1package templates
2
3import "testing"
4
5func TestCatalogShapeAndTemplateApplication(t *testing.T) {
6 if got := len(Names()); got != 16 {
7 t.Fatalf("template count = %d, want 16", got)
8 }
9 if got := len(Connections()); got != 12 {
10 t.Fatalf("connection count = %d, want 12", got)
11 }
12 p, err := ApplyTemplate("outbox", "owner")
13 if err != nil {
14 t.Fatal(err)
15 }
16 if p.Owner != "owner" || p.Writes != "owner" || !p.Delivery.Enabled || len(p.BlockedKinds) != 3 {
17 t.Fatalf("outbox application: %#v", p)
18 }
19 social, err := ApplyTemplate("social", "owner")
20 if err != nil {
21 t.Fatal(err)
22 }
23 if social.Owner != "owner" || social.Writes != "allowlist" || social.Reads != "open" {
24 t.Fatalf("social policy: %#v", social)
25 }
26 for _, kind := range []int{0, 1, 5, 6, 7, 1111, 30023} {
27 if !containsKind(social.AllowedKinds, kind) {
28 t.Fatalf("social does not allow kind %d: %#v", kind, social.AllowedKinds)
29 }
30 }
31 if _, err := ApplyTemplate("missing", "owner"); err == nil {
32 t.Fatal("missing template unexpectedly applied")
33 }
34 for _, name := range Names() {
35 if _, err := ApplyTemplate(name, "owner"); err != nil {
36 t.Fatalf("template %s: %v", name, err)
37 }
38 }
39}
40
41func containsKind(kinds []int, want int) bool {
42 for _, kind := range kinds {
43 if kind == want {
44 return true
45 }
46 }
47 return false
48}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs