diff --git a/seaweed-block/core/lifecycle/golden_v100_test.go b/seaweed-block/core/lifecycle/golden_v100_test.go index 41baec599a..65a39291f4 100644 --- a/seaweed-block/core/lifecycle/golden_v100_test.go +++ b/seaweed-block/core/lifecycle/golden_v100_test.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/sha1" "encoding/hex" + "encoding/json" "fmt" "os" "path/filepath" @@ -38,14 +39,14 @@ func goldenStores(t *testing.T, dir string) { } vols, err := OpenFileStore(filepath.Join(dir, "volumes")) must("open volumes", err) - _, err = vols.CreateVolume(VolumeSpec{VolumeID: "v1", LayoutID: "11111111111111111111111111111111", SizeBytes: 1 << 30, BlockSize: 4096, ChunkBytes: 4 << 20, ReplicationFactor: 1, Protocol: "nvme", FrontendTransport: "tcp"}) + v1, err := vols.CreateVolume(VolumeSpec{VolumeID: "v1", SizeBytes: 1 << 30, BlockSize: 4096, ChunkBytes: 4 << 20, ReplicationFactor: 1, Protocol: "nvme", FrontendTransport: "tcp"}) must("create v1", err) - _, err = vols.MarkStoreReady("v1", "11111111111111111111111111111111") + _, err = vols.MarkStoreReady("v1", v1.Spec.LayoutID) must("ready v1", err) _, err = vols.AttachVolume("v1", "node-a") must("attach v1", err) - _, err = vols.CreateVolume(VolumeSpec{VolumeID: "t1", LayoutID: "22222222222222222222222222222222", SizeBytes: 1 << 30, BlockSize: 4096, ChunkBytes: 4 << 20, ReplicationFactor: 1, - SourceVolume: "v1", SourceLayoutID: "11111111111111111111111111111111", SourceSnapshot: "daily", CreateRequestID: "restore-1", + _, err = vols.CreateVolume(VolumeSpec{VolumeID: "t1", SizeBytes: 1 << 30, BlockSize: 4096, ChunkBytes: 4 << 20, ReplicationFactor: 1, + SourceVolume: "v1", SourceLayoutID: v1.Spec.LayoutID, SourceSnapshot: "daily", CreateRequestID: "restore-1", PVCName: "data", PVCNamespace: "ns", PVCUID: "uid-1", PVName: "pv-1"}) must("create t1", err) @@ -135,6 +136,27 @@ func TestLifecycleGoldenFilesAreTheV100Files(t *testing.T) { } } +// comparable is a fixture file as the write check compares it. A volume +// record's layout ids are minted at random by the store (CreateVolume +// refuses a given one), so they are blanked; every other byte of every file +// is compared as written. +func comparable(t *testing.T, name string, b []byte) []byte { + t.Helper() + if !strings.HasPrefix(name, "volumes/") { + return b + } + var r VolumeRecord + if err := json.Unmarshal(b, &r); err != nil { + t.Fatalf("%s: %v", name, err) + } + r.Spec.LayoutID, r.Spec.SourceLayoutID = "", "" + out, err := json.MarshalIndent(r, "", " ") + if err != nil { + t.Fatal(err) + } + return out +} + // Today's stores write the v1.0.0 files for the same inputs. func TestLifecycleStoresWriteTheV100Files(t *testing.T) { dir := t.TempDir() @@ -146,8 +168,8 @@ func TestLifecycleStoresWriteTheV100Files(t *testing.T) { } sort.Strings(names) for _, n := range names { - if !bytes.Equal(got[n], want[n]) { - t.Errorf("%s: %s\n got %s\n want %s", n, goldenFixMessage, got[n], want[n]) + if g, w := comparable(t, n, got[n]), comparable(t, n, want[n]); !bytes.Equal(g, w) { + t.Errorf("%s: %s\n got %s\n want %s", n, goldenFixMessage, g, w) } } for n := range got { @@ -186,7 +208,7 @@ func TestLifecycleStoresReadTheV100Files(t *testing.T) { if err != nil { t.Fatalf("open the v1.0.0 volume records: %v: %s", err, goldenFixMessage) } - if r, ok := vols.GetVolume("v1"); !ok || !r.StoreReady || r.AttachedTo != "node-a" || r.Spec.LayoutID != "11111111111111111111111111111111" || r.Spec.Protocol != "nvme" { + if r, ok := vols.GetVolume("v1"); !ok || !r.StoreReady || r.AttachedTo != "node-a" || r.Spec.LayoutID == "" || r.Spec.Protocol != "nvme" { fail("volume v1", r, "store-ready, attached to node-a") } if r, ok := vols.GetVolume("t1"); !ok || r.StoreReady || r.Spec.SourceVolume != "v1" || r.Spec.SourceSnapshot != "daily" || r.Spec.CreateRequestID != "restore-1" || r.Spec.PVName != "pv-1" {