forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request influxdata#2448 from influxdata/fix/topic-handler
fix: topic-handler duration() -> alertDuration()
- Loading branch information
Showing
5 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package alert | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/influxdata/kapacitor/alert" | ||
) | ||
|
||
func TestMatchHandlerAlertDuration(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
event alert.Event | ||
shouldMatch bool | ||
match string | ||
}{{ | ||
event: alert.Event{ | ||
Topic: "topi", | ||
State: alert.EventState{ | ||
ID: "woot", | ||
Message: "message", | ||
Details: "details", | ||
Time: time.Now(), | ||
Duration: time.Second * 30, | ||
Level: alert.Critical, | ||
}, | ||
Data: alert.EventData{}, | ||
}, | ||
shouldMatch: true, | ||
match: "alertDuration() < 1m", | ||
}, { | ||
event: alert.Event{ | ||
Topic: "topi", | ||
State: alert.EventState{ | ||
ID: "woot", | ||
Message: "message", | ||
Details: "details", | ||
Time: time.Now(), | ||
Duration: time.Second * 130, | ||
Level: alert.Critical, | ||
}, | ||
Data: alert.EventData{}, | ||
}, | ||
shouldMatch: false, | ||
match: "alertDuration() < 1m", | ||
}} | ||
|
||
for _, testCase := range cases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
var h alert.Handler | ||
mh, err := newMatchHandler(testCase.match, h, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
matched, err := mh.match(testCase.event) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if matched != testCase.shouldMatch { | ||
if matched { | ||
t.Errorf("expected event to match %s but it didn't", testCase.match) | ||
} else { | ||
t.Errorf("expected event to not match %s but it did", testCase.match) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters