forked from argoproj/notifications-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_test.go
58 lines (42 loc) · 1.67 KB
/
state_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package controller
import (
"strconv"
"testing"
"github.com/argoproj/notifications-engine/pkg/triggers"
"github.com/argoproj/notifications-engine/pkg/services"
"github.com/stretchr/testify/assert"
)
func TestNotificationState_Truncate(t *testing.T) {
state := NotificationsState{}
for i := 0; i < 5; i++ {
state[strconv.Itoa(i)] = int64(i)
}
state.truncate(3)
assert.Equal(t, NotificationsState{"2": 2, "3": 3, "4": 4}, state)
}
func TestSetAlreadyNotified(t *testing.T) {
dest := services.Destination{Service: "slack", Recipient: "my-channel"}
state := NotificationsState{}
changed := state.SetAlreadyNotified("app-synced", triggers.ConditionResult{Key: "0"}, dest, true)
assert.True(t, changed)
_, ok := state["app-synced:0:slack:my-channel"]
assert.True(t, ok)
changed = state.SetAlreadyNotified("app-synced", triggers.ConditionResult{Key: "0"}, dest, true)
assert.False(t, changed)
changed = state.SetAlreadyNotified("app-synced", triggers.ConditionResult{Key: "0"}, dest, false)
assert.True(t, changed)
_, ok = state["app-synced:0:slack:my-channel"]
assert.False(t, ok)
}
func TestSetAlreadyNotified_OncePerItem(t *testing.T) {
dest := services.Destination{Service: "slack", Recipient: "my-channel"}
state := NotificationsState{}
changed := state.SetAlreadyNotified("app-synced", triggers.ConditionResult{OncePer: "abc", Key: "0"}, dest, true)
assert.True(t, changed)
_, ok := state["abc:app-synced:0:slack:my-channel"]
assert.True(t, ok)
changed = state.SetAlreadyNotified("app-synced", triggers.ConditionResult{OncePer: "abc", Key: "0"}, dest, false)
assert.False(t, changed)
_, ok = state["abc:app-synced:0:slack:my-channel"]
assert.True(t, ok)
}