/ notifier / ilert-notifier_test.go
ilert-notifier_test.go
 1  package notifier
 2  
 3  import (
 4  	"reflect"
 5  	"testing"
 6  )
 7  
 8  func TestILertEvents(t *testing.T) {
 9  	ilert := &ILertNotifier{
10  		ApiKey:              "aPiKeY",
11  		IncidentKeyTemplate: "{{.Check}}:{{.Node}}:{{.Service}}",
12  	}
13  
14  	messages := Messages{
15  		Message{Status: "passing", Node: "node1", Service: "service1", Check: "check1", Output: "OK"},
16  		Message{Status: "warning", Node: "node1", Service: "service1", Check: "check2", Output: "WARN"},
17  		Message{Status: "critical", Node: "node2", Service: "service2", Check: "check3", Output: "CRIT"},
18  	}
19  
20  	expectedILertEvents := []iLertEvent{
21  		{
22  			ApiKey:      "aPiKeY",
23  			EventType:   "RESOLVE",
24  			Summary:     "check1:node1:service1 is now HEALTHY",
25  			Details:     "OK",
26  			IncidentKey: "check1:node1:service1",
27  		},
28  		{
29  			ApiKey:      "aPiKeY",
30  			EventType:   "RESOLVE",
31  			Summary:     "check2:node1:service1 is WARNING",
32  			Details:     "WARN",
33  			IncidentKey: "check2:node1:service1",
34  		},
35  		{
36  			ApiKey:      "aPiKeY",
37  			EventType:   "ALERT",
38  			Summary:     "check3:node2:service2 is CRITICAL",
39  			Details:     "CRIT",
40  			IncidentKey: "check3:node2:service2",
41  		},
42  	}
43  
44  	actualILertEvents := ilert.toILertEvents(messages)
45  
46  	if !reflect.DeepEqual(expectedILertEvents, actualILertEvents) {
47  		t.Errorf("iLert event mapping failed, expected: %v, got: %v", expectedILertEvents, actualILertEvents)
48  	}
49  }