| 1 | package moves |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/hostclaim" |
| 7 | ) |
| 8 | |
| 9 | func TestReplicaSourcePrefixAndKeep(t *testing.T) { |
| 10 | inc := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 11 | for _, tc := range []struct { |
| 12 | h hostclaim.Holder |
| 13 | want string |
| 14 | }{ |
| 15 | {hostclaim.Holder{Location: "instances/h/" + inc, Generation: "cur"}, "instances/h/" + inc + "/g-cur/"}, |
| 16 | {hostclaim.Holder{Location: "instances/h/" + inc + "/", Generation: "cur"}, "instances/h/" + inc + "/g-cur/"}, |
| 17 | {hostclaim.Holder{Location: "instances/h", Generation: hostclaim.RootGeneration}, "instances/h/"}, |
| 18 | {hostclaim.Holder{Location: "instances/h"}, "instances/h/"}, |
| 19 | } { |
| 20 | if got, _ := ReplicaSource(tc.h); got != tc.want { |
| 21 | t.Errorf("ReplicaSource(%+v) prefix = %q, want %q", tc.h, got, tc.want) |
| 22 | } |
| 23 | } |
| 24 | _, keep := ReplicaSource(hostclaim.Holder{Location: "instances/h"}) |
| 25 | for rel, want := range map[string]bool{ |
| 26 | "0000/0000000000000001-0000000000000004.ltx": true, |
| 27 | "0009/0000000000000001-00000000000000ff.ltx": true, |
| 28 | "0001/0000000000000005-0000000000000005.ltx": true, |
| 29 | "000a/0000000000000001-0000000000000004.ltx": false, // level 10 |
| 30 | "0000/0000000000000000-0000000000000004.ltx": false, // min 0 |
| 31 | "0000/0000000000000005-0000000000000004.ltx": false, // min > max |
| 32 | "0000/0000000000000001-0000000000000004.LTX": false, |
| 33 | "0000/1-4.ltx": false, // not canonical |
| 34 | "00/0000000000000001-0000000000000004.ltx": false, |
| 35 | "g-x/0000/0000000000000001-0000000000000004.ltx": false, |
| 36 | inc + "/0000/0000000000000001-0000000000000004.ltx": false, |
| 37 | "generation.json": false, |
| 38 | "lock.json": false, |
| 39 | "closed/0000/0000000000000001-0000000000000004.ltx": false, |
| 40 | "0000/0000000000000001-0000000000000004.ltx/x": false, |
| 41 | } { |
| 42 | if got := keep(rel); got != want { |
| 43 | t.Errorf("keep(%q) = %v, want %v", rel, got, want) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |