Monorepo for Tangled tangled.org
6

Configure Feed

Select the types of activity you want to include in your feed.

1package eventconsumer 2 3import ( 4 "testing" 5 6 "tangled.org/core/eventconsumer/cursor" 7) 8 9func TestMigrateLegacyCursor(t *testing.T) { 10 const host = "whelk.knot.tld" 11 src := NewKnotSource(host) 12 13 t.Run("copies legacy bare-host cursor to namespaced key", func(t *testing.T) { 14 store := &cursor.MemoryStore{} 15 store.Set(host, 42) 16 17 MigrateLegacyCursor(store, src) 18 19 if got := store.Get(src.Key()); got != 42 { 20 t.Fatalf("namespaced key = %d, want 42", got) 21 } 22 if got := store.Get(host); got != 42 { 23 t.Fatalf("legacy key = %d, want it left at 42", got) 24 } 25 }) 26 27 t.Run("does not pave over an already-migrated cursor", func(t *testing.T) { 28 store := &cursor.MemoryStore{} 29 store.Set(src.Key(), 100) 30 store.Set(host, 42) 31 32 MigrateLegacyCursor(store, src) 33 34 if got := store.Get(src.Key()); got != 100 { 35 t.Fatalf("namespaced key = %d, want 100", got) 36 } 37 }) 38 39 t.Run("noop when neither key is set", func(t *testing.T) { 40 store := &cursor.MemoryStore{} 41 42 MigrateLegacyCursor(store, src) 43 44 if got := store.Get(src.Key()); got != 0 { 45 t.Fatalf("namespaced key = %d, want 0", got) 46 } 47 }) 48 49 t.Run("namespaces the same host by kind", func(t *testing.T) { 50 const shared = "mussel.knot.tld" 51 knot := NewKnotSource(shared) 52 spindle := NewSpindleSource(shared) 53 54 store := &cursor.MemoryStore{} 55 store.Set(shared, 500) 56 57 MigrateLegacyCursor(store, knot) 58 MigrateLegacyCursor(store, spindle) 59 60 if got := store.Get(knot.Key()); got != 500 { 61 t.Fatalf("knot key = %d, want 500", got) 62 } 63 if got := store.Get(spindle.Key()); got != 500 { 64 t.Fatalf("spindle key = %d, want 500", got) 65 } 66 }) 67}