mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Add unit test for lifecycle.FilterRules (#18284)
This commit is contained in:
parent
780882efcf
commit
8cd80fec8c
@ -1016,3 +1016,63 @@ func TestFilterAndSetPredictionHeaders(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterRules(t *testing.T) {
|
||||
lc := Lifecycle{
|
||||
Rules: []Rule{
|
||||
{
|
||||
ID: "rule-1",
|
||||
Status: "Enabled",
|
||||
Filter: Filter{
|
||||
Tag: Tag{
|
||||
Key: "key1",
|
||||
Value: "val1",
|
||||
},
|
||||
},
|
||||
Expiration: Expiration{
|
||||
Days: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
tests := []struct {
|
||||
opts ObjectOpts
|
||||
wantRule string
|
||||
}{
|
||||
{ // Delete marker should match filter without tags
|
||||
opts: ObjectOpts{
|
||||
DeleteMarker: true,
|
||||
IsLatest: true,
|
||||
Name: "obj-1",
|
||||
},
|
||||
wantRule: "rule-1",
|
||||
},
|
||||
{ // PUT version with no matching tags
|
||||
opts: ObjectOpts{
|
||||
IsLatest: true,
|
||||
Name: "obj-1",
|
||||
},
|
||||
wantRule: "",
|
||||
},
|
||||
{ // PUT version with matching tags
|
||||
opts: ObjectOpts{
|
||||
IsLatest: true,
|
||||
UserTags: "key1=val1",
|
||||
Name: "obj-1",
|
||||
},
|
||||
wantRule: "rule-1",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range tests {
|
||||
t.Run(fmt.Sprintf("test-%d", i+1), func(t *testing.T) {
|
||||
rules := lc.FilterRules(tc.opts)
|
||||
if tc.wantRule != "" && len(rules) == 0 {
|
||||
t.Fatalf("%d: Expected rule match %s but none matched", i+1, tc.wantRule)
|
||||
}
|
||||
if tc.wantRule == "" && len(rules) > 0 {
|
||||
t.Fatalf("%d: Expected no rules to match but got matches %v", i+1, rules)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user