-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification_test.go
39 lines (33 loc) · 1.27 KB
/
notification_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseNotification(t *testing.T) {
parseTest := func(in []string, expectedInstance, expectedState string, fail bool) func(t *testing.T) {
return func(t *testing.T) {
n, err := parseNotification(in)
if fail {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equalf(t, expectedInstance, n.Instance, "parsed instance did not match expectation")
assert.Equalf(t, NotificationStatus(expectedState), n.Status, "parsed state did not match expectation")
}
}
t.Run("master", parseTest([]string{"INSTANCE", "foo", "MASTER", "100"},
"foo", "MASTER", false))
t.Run("fault", parseTest([]string{"INSTANCE", "bar", "FAULT", "100"},
"bar", "FAULT", false))
t.Run("backup", parseTest([]string{"INSTANCE", "buzz", "BACKUP", "100"},
"buzz", "BACKUP", false))
t.Run("with space", parseTest([]string{"INSTANCE", "foo bar", "MASTER", "100"},
"foo bar", "MASTER", false))
t.Run("unexpected", parseTest([]string{"This", "is", "definitely", "not", "a", "notification"},
"", "", true))
t.Run("good length", parseTest([]string{"Still", "not", "a", "notification"},
"", "", true))
t.Run("unsported group", parseTest([]string{"GROUP", "foos", "MASTER", "100"},
"", "", true))
}