Fix FindMinSnapshotByGeneration() loop ref bug

This commit fixes an issue where the reference is taken
on the loop variable rather than the slice element when
computing the minimum snapshot within a generation so
it can cause the wrong snapshot to be chosen.
This commit is contained in:
Ben Johnson
2021-12-08 18:28:03 -07:00
parent 61c80cbfc2
commit d09f4ef618
3 changed files with 17 additions and 3 deletions

View File

@@ -40,6 +40,16 @@ func TestChecksum(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 {
b, err := hex.DecodeString(s)
if err != nil {