Monorepo for Tangled
tangled.org
1package db
2
3import (
4 "context"
5 "testing"
6)
7
8func TestKnotAclNativeDefaultsFalse(t *testing.T) {
9 d := newTestDB(t)
10
11 native, err := IsKnotAclNative(context.Background(), d, "clam.nel.pet")
12 if err != nil {
13 t.Fatalf("IsKnotAclNative: %v", err)
14 }
15 if native {
16 t.Fatal("an unseen knot must default to not native")
17 }
18}
19
20func TestKnotAclNativeMarkLatches(t *testing.T) {
21 d := newTestDB(t)
22
23 if err := MarkKnotAclNative(context.Background(), d, "whelk.nel.pet"); err != nil {
24 t.Fatalf("MarkKnotAclNative: %v", err)
25 }
26
27 native, err := IsKnotAclNative(context.Background(), d, "whelk.nel.pet")
28 if err != nil {
29 t.Fatalf("IsKnotAclNative: %v", err)
30 }
31 if !native {
32 t.Fatal("a marked knot must read back native")
33 }
34}
35
36func TestKnotAclNativeMarkIsIdempotent(t *testing.T) {
37 d := newTestDB(t)
38
39 if err := MarkKnotAclNative(context.Background(), d, "limpet.nel.pet"); err != nil {
40 t.Fatalf("first mark: %v", err)
41 }
42 if err := MarkKnotAclNative(context.Background(), d, "limpet.nel.pet"); err != nil {
43 t.Fatalf("second mark must be a no-op, got: %v", err)
44 }
45
46 if n := countRows(t, d, `select count(*) from knot_acl_native where domain = ?`, "limpet.nel.pet"); n != 1 {
47 t.Fatalf("rows = %d, want exactly 1 after a repeated mark", n)
48 }
49}