Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
393317b6f8 |
@@ -207,11 +207,13 @@ func FilterSnapshotsAfter(a []SnapshotInfo, t time.Time) []SnapshotInfo {
|
|||||||
// FindMinSnapshotByGeneration finds the snapshot with the lowest index in a generation.
|
// FindMinSnapshotByGeneration finds the snapshot with the lowest index in a generation.
|
||||||
func FindMinSnapshotByGeneration(a []SnapshotInfo, generation string) *SnapshotInfo {
|
func FindMinSnapshotByGeneration(a []SnapshotInfo, generation string) *SnapshotInfo {
|
||||||
var min *SnapshotInfo
|
var min *SnapshotInfo
|
||||||
for _, snapshot := range a {
|
for i := range a {
|
||||||
|
snapshot := &a[i]
|
||||||
|
|
||||||
if snapshot.Generation != generation {
|
if snapshot.Generation != generation {
|
||||||
continue
|
continue
|
||||||
} else if min == nil || snapshot.Index < min.Index {
|
} else if min == nil || snapshot.Index < min.Index {
|
||||||
min = &snapshot
|
min = snapshot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return min
|
return min
|
||||||
|
|||||||
@@ -128,6 +128,16 @@ func TestWALSegmentPath(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFindMinSnapshotByGeneration(t *testing.T) {
|
||||||
|
infos := []litestream.SnapshotInfo{
|
||||||
|
{Generation: "29cf4bced74e92ab", Index: 0},
|
||||||
|
{Generation: "5dfeb4aa03232553", Index: 24},
|
||||||
|
}
|
||||||
|
if got, want := litestream.FindMinSnapshotByGeneration(infos, "29cf4bced74e92ab"), &infos[0]; got != want {
|
||||||
|
t.Fatalf("info=%#v, want %#v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func MustDecodeHexString(s string) []byte {
|
func MustDecodeHexString(s string) []byte {
|
||||||
b, err := hex.DecodeString(s)
|
b, err := hex.DecodeString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user