pruning: fix tests + implement 'not_replicated' and 'keep_regex' keep rule

tests expected that a KeepRule returns a *keep* list whereas it
actually returns a *destroy* list.
This commit is contained in:
Christian Schwarz
2018-08-30 11:44:43 +02:00
parent a2aa8e7bd7
commit d684302864
9 changed files with 134 additions and 43 deletions

33
pruning/keep_regex.go Normal file
View File

@ -0,0 +1,33 @@
package pruning
import (
"regexp"
)
type KeepRegex struct {
expr *regexp.Regexp
}
var _ KeepRule = &KeepRegex{}
func NewKeepRegex(expr string) (*KeepRegex, error) {
re, err := regexp.Compile(expr)
if err != nil {
return nil, err
}
return &KeepRegex{re}, nil
}
func MustKeepRegex(expr string) *KeepRegex {
k, err := NewKeepRegex(expr)
if err != nil {
panic(err)
}
return k
}
func (k *KeepRegex) KeepRule(snaps []Snapshot) []Snapshot {
return filterSnapList(snaps, func(s Snapshot) bool {
return k.expr.FindStringIndex(s.Name()) == nil
})
}