From fbc479beff90ead42c0edb1eca9073cec18d004a Mon Sep 17 00:00:00 2001 From: anjor Date: Sun, 20 Oct 2024 09:54:52 +0100 Subject: [PATCH] sort cars test --- cmd-car-split_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 cmd-car-split_test.go diff --git a/cmd-car-split_test.go b/cmd-car-split_test.go new file mode 100644 index 00000000..6c8154ef --- /dev/null +++ b/cmd-car-split_test.go @@ -0,0 +1,50 @@ +package main + +import ( + "path/filepath" + "testing" +) + +func TestSortCarFiles(t *testing.T) { + + fixturesDir := "fixtures" + + carFiles := []string{ + filepath.Join(fixturesDir, "epoch-0-1.car"), + filepath.Join(fixturesDir, "epoch-0-2.car"), + filepath.Join(fixturesDir, "epoch-0-3.car"), + } + + result, err := SortCarFiles(carFiles) + + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + + if len(result) != 3 { + t.Fatalf("unexpected result length: %d", len(result)) + } + + expectedResults := []struct { + name string + firstSlot int64 + size int64 + }{ + {filepath.Join(fixturesDir, "epoch-0-1.car"), 0, 96932}, + {filepath.Join(fixturesDir, "epoch-0-2.car"), 10, 100027}, + {filepath.Join(fixturesDir, "epoch-0-3.car"), 20, 99487}, + } + + for i, expected := range expectedResults { + if result[i].name != expected.name { + t.Fatalf("unexpected name: %s", result[i].name) + } + if result[i].firstSlot != expected.firstSlot { + t.Fatalf("unexpected firstSlot: %d", result[i].firstSlot) + } + if result[i].size != expected.size { + t.Fatalf("unexpected size: %d", result[i].size) + } + } + +}