| 1 | package registry |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestSeedSourceColumn(t *testing.T) { |
| 6 | reg := openTestRegistry(t) |
| 7 | const col = `{"id":"sd_aaaaaaaaaaaaaaaaaaaaaaaaaa","kind":"replica","state":"ready"}` |
| 8 | if err := reg.Upsert(Route{Host: "c.example.com", Kind: "instance", SeedSource: col}); err != nil { |
| 9 | t.Fatal(err) |
| 10 | } |
| 11 | // A re-add that knows nothing of seeds keeps the column. |
| 12 | if err := reg.Upsert(Route{Host: "c.example.com", Kind: "instance"}); err != nil { |
| 13 | t.Fatal(err) |
| 14 | } |
| 15 | if got, _ := reg.Get("c.example.com"); got.SeedSource != col { |
| 16 | t.Fatalf("after a seedless Upsert: %q", got.SeedSource) |
| 17 | } |
| 18 | placed := `{"id":"sd_aaaaaaaaaaaaaaaaaaaaaaaaaa","kind":"replica","state":"placed"}` |
| 19 | if err := reg.SetSeedSource("c.example.com", placed); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if got, _ := reg.Get("c.example.com"); got.SeedSource != placed { |
| 23 | t.Fatalf("after SetSeedSource: %q", got.SeedSource) |
| 24 | } |
| 25 | if err := reg.SetSeedSource("nope.example.com", placed); err == nil { |
| 26 | t.Fatal("SetSeedSource on no row: want an error") |
| 27 | } |
| 28 | before, _ := reg.Fingerprint() |
| 29 | _ = reg.SetSeedSource("c.example.com", col) |
| 30 | if after, _ := reg.Fingerprint(); after != before { |
| 31 | t.Fatal("the seed column moved the edge's fingerprint") |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | // The snapshot digest sees the column when it is set and digests exactly as |
| 36 | // before when it is not (the golden in TestFingerprintsUnchangedForUnheldRows |
| 37 | // covers the unseeded half against the pre-column hash). |
| 38 | func TestSeedSourceSnapshotFingerprint(t *testing.T) { |
| 39 | reg := openTestRegistry(t) |
| 40 | if err := reg.Upsert(Route{Host: "c.example.com", Kind: "instance", CreatedAt: 1700000000}); err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | unseeded, err := reg.SnapshotFingerprint() |
| 44 | if err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | if err := reg.SetSeedSource("c.example.com", `{"id":"sd_aaaaaaaaaaaaaaaaaaaaaaaaaa","kind":"replica","state":"ready"}`); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | seeded, _ := reg.SnapshotFingerprint() |
| 51 | if seeded == unseeded { |
| 52 | t.Fatal("SnapshotFingerprint did not move when seed_source was set") |
| 53 | } |
| 54 | if err := reg.SetSeedSource("c.example.com", ""); err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | if back, _ := reg.SnapshotFingerprint(); back != unseeded { |
| 58 | t.Fatal("clearing seed_source did not restore the unseeded digest") |
| 59 | } |
| 60 | } |
| 61 | |