tests: Add tests for filterRuleMatch (#2722)

Part-1 fix for #2418
master
Harshavardhana 8 years ago committed by GitHub
parent 79888bfff7
commit 797d749322
  1. 107
      cmd/notifiers_test.go

@ -18,6 +18,113 @@ package cmd
import "testing"
// Tests for event filter rules.
func TestFilterMatch(t *testing.T) {
testCases := []struct {
objectName string
rules []filterRule
expectedRuleMatch bool
}{
// Prefix matches for a parent.
{
objectName: "test/test1/object.txt",
rules: []filterRule{
{
Name: "prefix",
Value: "test",
},
},
expectedRuleMatch: true,
},
// Prefix matches for the object.
{
objectName: "test/test1/object.txt",
rules: []filterRule{
{
Name: "prefix",
Value: "test/test1/object",
},
},
expectedRuleMatch: true,
},
// Prefix doesn't match.
{
objectName: "test/test1/object.txt",
rules: []filterRule{
{
Name: "prefix",
Value: "test/test1/object/",
},
},
expectedRuleMatch: false,
},
// Suffix matches.
{
objectName: "test/test1/object.txt",
rules: []filterRule{
{
Name: "suffix",
Value: ".txt",
},
},
expectedRuleMatch: true,
},
// Suffix doesn't match but prefix matches.
{
objectName: "test/test1/object.txt",
rules: []filterRule{
{
Name: "suffix",
Value: ".jpg",
},
{
Name: "prefix",
Value: "test/test1",
},
},
expectedRuleMatch: false,
},
// Prefix doesn't match but suffix matches.
{
objectName: "test/test2/object.jpg",
rules: []filterRule{
{
Name: "suffix",
Value: ".jpg",
},
{
Name: "prefix",
Value: "test/test1",
},
},
expectedRuleMatch: false,
},
// Suffix and prefix doesn't match.
{
objectName: "test/test2/object.jpg",
rules: []filterRule{
{
Name: "suffix",
Value: ".txt",
},
{
Name: "prefix",
Value: "test/test1",
},
},
expectedRuleMatch: false,
},
}
// .. Validate all cases.
for i, testCase := range testCases {
ruleMatch := filterRuleMatch(testCase.objectName, testCase.rules)
if ruleMatch != testCase.expectedRuleMatch {
t.Errorf("Test %d: Expected %t, got %t", i+1, testCase.expectedRuleMatch, ruleMatch)
}
}
}
// Tests all event match.
func TestEventMatch(t *testing.T) {
testCases := []struct {

Loading…
Cancel
Save