package moves import ( "testing" "github.com/carlosframework/platform/internal/hostclaim" ) func TestReplicaSourcePrefixAndKeep(t *testing.T) { inc := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" for _, tc := range []struct { h hostclaim.Holder want string }{ {hostclaim.Holder{Location: "instances/h/" + inc, Generation: "cur"}, "instances/h/" + inc + "/g-cur/"}, {hostclaim.Holder{Location: "instances/h/" + inc + "/", Generation: "cur"}, "instances/h/" + inc + "/g-cur/"}, {hostclaim.Holder{Location: "instances/h", Generation: hostclaim.RootGeneration}, "instances/h/"}, {hostclaim.Holder{Location: "instances/h"}, "instances/h/"}, } { if got, _ := ReplicaSource(tc.h); got != tc.want { t.Errorf("ReplicaSource(%+v) prefix = %q, want %q", tc.h, got, tc.want) } } _, keep := ReplicaSource(hostclaim.Holder{Location: "instances/h"}) for rel, want := range map[string]bool{ "0000/0000000000000001-0000000000000004.ltx": true, "0009/0000000000000001-00000000000000ff.ltx": true, "0001/0000000000000005-0000000000000005.ltx": true, "000a/0000000000000001-0000000000000004.ltx": false, // level 10 "0000/0000000000000000-0000000000000004.ltx": false, // min 0 "0000/0000000000000005-0000000000000004.ltx": false, // min > max "0000/0000000000000001-0000000000000004.LTX": false, "0000/1-4.ltx": false, // not canonical "00/0000000000000001-0000000000000004.ltx": false, "g-x/0000/0000000000000001-0000000000000004.ltx": false, inc + "/0000/0000000000000001-0000000000000004.ltx": false, "generation.json": false, "lock.json": false, "closed/0000/0000000000000001-0000000000000004.ltx": false, "0000/0000000000000001-0000000000000004.ltx/x": false, } { if got := keep(rel); got != want { t.Errorf("keep(%q) = %v, want %v", rel, got, want) } } }