mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-21 16:03:32 +01:00
pruning/keep_last_n: correctly handle the case where count
> matching snaps
fixes #446
This commit is contained in:
parent
ac4b109872
commit
f661d9429f
@ -57,6 +57,11 @@ func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
|
||||
// then lexicographically descending (e.g. b, a)
|
||||
return strings.Compare(matching[i].Name(), matching[j].Name()) == 1
|
||||
})
|
||||
destroyList = append(destroyList, matching[k.n:]...)
|
||||
|
||||
n := k.n
|
||||
if n > len(matching) {
|
||||
n = len(matching)
|
||||
}
|
||||
destroyList = append(destroyList, matching[n:]...)
|
||||
return destroyList
|
||||
}
|
||||
|
@ -83,6 +83,19 @@ func TestKeepLastN(t *testing.T) {
|
||||
"b1": true,
|
||||
},
|
||||
},
|
||||
"keep_more_than_matching": {
|
||||
inputs: []Snapshot{
|
||||
stubSnap{"a1", false, o(10)},
|
||||
stubSnap{"b1", false, o(11)},
|
||||
stubSnap{"a2", false, o(12)},
|
||||
},
|
||||
rules: []KeepRule{
|
||||
MustKeepLastN(3, "a"),
|
||||
},
|
||||
expDestroy: map[string]bool{
|
||||
"b1": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
testTable(tcs, t)
|
||||
|
Loading…
Reference in New Issue
Block a user