pruning: add 'Negate' option to KeepRegex and expose it in config

This commit is contained in:
Christian Schwarz
2018-11-16 11:32:24 +01:00
parent 2db3977408
commit 5e1ea21f85
7 changed files with 82 additions and 15 deletions

View File

@ -24,6 +24,25 @@ type testCase struct {
expDestroyAlternatives []map[string]bool
}
type snapshotList []Snapshot
func (l snapshotList) ContainsName(n string) bool {
for _, s := range l {
if s.Name() == n {
return true
}
}
return false
}
func (l snapshotList) NameList() []string {
res := make([]string, len(l))
for i, s := range l {
res[i] = s.Name()
}
return res
}
func testTable(tcs map[string]testCase, t *testing.T) {
mapEqual := func(a, b map[string]bool) bool {
if len(a) != len(b) {
@ -79,7 +98,7 @@ func TestPruneSnapshots(t *testing.T) {
"simple": {
inputs: inputs["s1"],
rules: []KeepRule{
MustKeepRegex("foo_"),
MustKeepRegex("foo_", false),
},
expDestroy: map[string]bool{
"bar_123": true,
@ -88,16 +107,16 @@ func TestPruneSnapshots(t *testing.T) {
"multipleRules": {
inputs: inputs["s1"],
rules: []KeepRule{
MustKeepRegex("foo_"),
MustKeepRegex("bar_"),
MustKeepRegex("foo_", false),
MustKeepRegex("bar_", false),
},
expDestroy: map[string]bool{},
},
"onlyThoseRemovedByAllAreRemoved": {
inputs: inputs["s1"],
rules: []KeepRule{
MustKeepRegex("notInS1"), // would remove all
MustKeepRegex("bar_"), // would remove all but bar_, i.e. foo_.*
MustKeepRegex("notInS1", false), // would remove all
MustKeepRegex("bar_", false), // would remove all but bar_, i.e. foo_.*
},
expDestroy: map[string]bool{
"foo_123": true,
@ -117,7 +136,7 @@ func TestPruneSnapshots(t *testing.T) {
"noSnaps": {
inputs: []Snapshot{},
rules: []KeepRule{
MustKeepRegex("foo_"),
MustKeepRegex("foo_", false),
},
expDestroy: map[string]bool{},
},