carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package moves
2
3import (
4 "encoding/json"
5 "testing"
6)
7
8func TestStagingKeysAreScopedPerOperation(t *testing.T) {
9 host, op := "a.go.example.com", "mv_abcdefghijklmnopqrstuvwxyz"
10 if StagingPrefix(host, op) != "moves/a.go.example.com/mv_abcdefghijklmnopqrstuvwxyz/" {
11 t.Fatal(StagingPrefix(host, op))
12 }
13 if ReplicaPrefix(host, op) != StagingPrefix(host, op)+"replica/" || FilesPrefix(host, op) != StagingPrefix(host, op)+"files/" || TimersPrefix(host, op) != StagingPrefix(host, op)+"timers/" {
14 t.Fatal("subprefixes")
15 }
16 if MoveJSONKey(host, op) != StagingPrefix(host, op)+"move.json" {
17 t.Fatal(MoveJSONKey(host, op))
18 }
19 if LaneKey(op) != "moves/_lane/mv_abcdefghijklmnopqrstuvwxyz" || ReceiptsKey(host, op) != "move-receipts/a.go.example.com/mv_abcdefghijklmnopqrstuvwxyz.json" || SnapshotsPrefix(host, op) != "move-snapshots/a.go.example.com/mv_abcdefghijklmnopqrstuvwxyz/" {
20 t.Fatal("source-bucket keys")
21 }
22 p := ReportPrefix("bab", "app", host, op)
23 if p != "moves/bab/app/a.go.example.com/mv_abcdefghijklmnopqrstuvwxyz/" || StoppedKey(p, "source") != p+"stopped-source.json" || TargetReportKey(p) != p+"target.json" || SourceReportKey(p) != p+"source.json" || LogKeyFor(p, "cutting-flipped") != p+"log/cutting-flipped.json" {
24 t.Fatal("deployment-bucket keys")
25 }
26 // The park scope grammar has no trailing slash (claim rev 6.23 §2).
27 if ScopeLocation(host, op) != "moves/a.go.example.com/mv_abcdefghijklmnopqrstuvwxyz" {
28 t.Fatal(ScopeLocation(host, op))
29 }
30}
31
32// The per-operation ledger sits beside the receipts in the source bucket
33// (Task 14, ruling F30), and is a different key from them.
34func TestLedgerKeyIsBesideTheReceiptsAndDistinctFromThem(t *testing.T) {
35 host, op := "a.go.example.com", "mv_abcdefghijklmnopqrstuvwxyz"
36 if got := LedgerKey(host, op); got != "move-receipts/a.go.example.com/mv_abcdefghijklmnopqrstuvwxyz-moves.json" {
37 t.Fatal(got)
38 }
39 if LedgerKey(host, op) == ReceiptsKey(host, op) {
40 t.Fatal("ledger and receipts share a key")
41 }
42}
43
44func TestMoveJSONCarriesTheWireFieldNames(t *testing.T) {
45 b, err := json.Marshal(MoveJSON{MoveID: "mv_x", Incarnation: "i", Host: "h", From: "f", To: "t"})
46 if err != nil {
47 t.Fatal(err)
48 }
49 if string(b) != `{"move_id":"mv_x","incarnation":"i","host":"h","from":"f","to":"t"}` {
50 t.Fatal(string(b))
51 }
52}
53