Skip to content

Commit

Permalink
Add option to define a string as noteq
Browse files Browse the repository at this point in the history
Will give you the option to say string noteq “admin” so everything that
is not admin will be notified.
  • Loading branch information
bittersweet committed Oct 11, 2015
1 parent 5695a77 commit 3923a39
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
15 changes: 14 additions & 1 deletion rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ func metBool(r *rule, parsed map[string]interface{}) bool {
func metString(r *rule, parsed map[string]interface{}) bool {
val := parsed[r.Key]
neededVal := r.Value
if val.(string) != neededVal {

str := val.(string)

if r.Setting == "noteq" {
if str == neededVal {
// We need not equal and string is equal
return false
} else {
// We need not equal and string is not equal
return true
}
}

if str != neededVal {
return false
}

Expand Down
36 changes: 32 additions & 4 deletions rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ func TestBoolTrue(t *testing.T) {
assert.Equal(t, true, result)
}

func TestStringDoesMatch(t *testing.T) {
event := setupTestNotifier(jt)

r := rule{
Key: "name",
Type: "string",
Value: "Go",
}

result := r.Met(&event)
assert.Equal(t, true, result)
}

func TestStringDoesNotMatch(t *testing.T) {
event := setupTestNotifier(jt)

Expand All @@ -71,13 +84,28 @@ func TestStringDoesNotMatch(t *testing.T) {
assert.Equal(t, false, result)
}

func TestStringDoesMatch(t *testing.T) {
func TestStringNotEqualIsEqual(t *testing.T) {
event := setupTestNotifier(jt)

r := rule{
Key: "name",
Type: "string",
Value: "Go",
Key: "name",
Type: "string",
Setting: "noteq",
Value: "Go",
}

result := r.Met(&event)
assert.Equal(t, false, result)
}

func TestStringNotEqualIsNotEqual(t *testing.T) {
event := setupTestNotifier(jt)

r := rule{
Key: "name",
Type: "string",
Setting: "noteq",
Value: "NotGo",
}

result := r.Met(&event)
Expand Down

0 comments on commit 3923a39

Please sign in to comment.