Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed Jun 3, 2024
1 parent 213e629 commit 0fa9c68
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME="github.com/goto/siren"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
APP_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "bae8e8169691d56bb0314a33bb369c72256bc63f"
PROTON_COMMIT := "f3199ce75d2c74c545bae14c646b10516f062a3a"

.PHONY: all build test clean dist vet proto install

Expand Down
63 changes: 39 additions & 24 deletions core/notification/dispatch_bulk_notification_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestReduceMetaMessages(t *testing.T) {
wantErr bool
}{
{
name: "should group meta messages with default receiver id",
name: "should group meta messages with receiver id",
metaMessages: []notification.MetaMessage{
{
ReceiverID: 13,
Expand Down Expand Up @@ -223,9 +223,9 @@ func TestReduceMetaMessages(t *testing.T) {
"k2": "ab",
},
MergedLabels: map[string][]string{
"k1": []string{"receiver-13", "receiver-13"},
"k2": []string{"ab", "cd"},
"x1": []string{"x1"},
"k1": {"receiver-13", "receiver-13"},
"k2": {"ab", "cd"},
"x1": {"x1"},
},
},
{
Expand All @@ -247,7 +247,7 @@ func TestReduceMetaMessages(t *testing.T) {
},
},
{
name: "should group meta messages with template",
name: "should not group meta messages if receiver and template are different",
metaMessages: []notification.MetaMessage{
{
ReceiverID: 13,
Expand All @@ -263,7 +263,7 @@ func TestReduceMetaMessages(t *testing.T) {
Template: "template-1",
},
{
ReceiverID: 13,
ReceiverID: 14,
NotificationIDs: []string{"yy"},
SubscriptionIDs: []uint64{3, 4},
Data: map[string]any{
Expand All @@ -277,7 +277,7 @@ func TestReduceMetaMessages(t *testing.T) {
Template: "template-2",
},
{
ReceiverID: 14,
ReceiverID: 15,
NotificationIDs: []string{"zz"},
SubscriptionIDs: []uint64{3, 4},
Data: map[string]any{
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestReduceMetaMessages(t *testing.T) {
MergedLabels: map[string][]string{"k1": {"receiver-13"}, "k2": {"ab"}},
},
{
ReceiverID: 13,
ReceiverID: 14,
NotificationIDs: []string{"yy"},
SubscriptionIDs: []uint64{3, 4},
Data: map[string]any{
Expand All @@ -321,7 +321,7 @@ func TestReduceMetaMessages(t *testing.T) {
MergedLabels: map[string][]string{"k1": {"receiver-13"}, "k2": {"cd"}, "x1": {"x1"}},
},
{
ReceiverID: 14,
ReceiverID: 15,
NotificationIDs: []string{"zz"},
SubscriptionIDs: []uint64{3, 4},
Data: map[string]any{
Expand All @@ -337,7 +337,7 @@ func TestReduceMetaMessages(t *testing.T) {
},
},
{
name: "should group meta messages with group by labels",
name: "should group meta messages with group by labels, template and receiver id",
groupBy: []string{
"k1",
"k2",
Expand Down Expand Up @@ -376,7 +376,7 @@ func TestReduceMetaMessages(t *testing.T) {
"d3": "dv3",
},
Labels: map[string]string{
"k1": "receiver-14",
"k1": "receiver-13",
"k2": "ab",
},
},
Expand All @@ -388,16 +388,26 @@ func TestReduceMetaMessages(t *testing.T) {
"d3": "dv3",
},
Labels: map[string]string{
"k1": "receiver-13",
"k2": "ab",
},
},
{
ReceiverID: 14,
NotificationIDs: []string{"aa"},
SubscriptionIDs: []uint64{5, 6},
Data: map[string]any{
"d3": "dv3",
},
Labels: map[string]string{
"k2": "ab",
},
},
},
want: []notification.MetaMessage{
{
ReceiverID: 13,
NotificationIDs: []string{"xx", "aa"},
SubscriptionIDs: []uint64{1, 2, 5, 6},
NotificationIDs: []string{"xx", "zz"},
SubscriptionIDs: []uint64{1, 2, 3, 4},
Data: map[string]any{
"d1": "dv1",
},
Expand All @@ -423,16 +433,27 @@ func TestReduceMetaMessages(t *testing.T) {
},
{
ReceiverID: 13,
NotificationIDs: []string{"zz"},
SubscriptionIDs: []uint64{3, 4},
NotificationIDs: []string{"aa"},
SubscriptionIDs: []uint64{5, 6},
Data: map[string]any{
"d3": "dv3",
},
Labels: map[string]string{
"k1": "receiver-14",
"k2": "ab",
},
MergedLabels: map[string][]string{"k1": {"receiver-14"}, "k2": {"ab"}},
MergedLabels: map[string][]string{"k2": {"ab"}},
},
{
ReceiverID: 14,
NotificationIDs: []string{"aa"},
SubscriptionIDs: []uint64{5, 6},
Data: map[string]any{
"d3": "dv3",
},
Labels: map[string]string{
"k2": "ab",
},
MergedLabels: map[string][]string{"k2": {"ab"}},
},
},
},
Expand All @@ -447,15 +468,9 @@ func TestReduceMetaMessages(t *testing.T) {
sort.Slice(got, func(i, j int) bool {
return got[i].ReceiverID < got[j].ReceiverID
})
sort.Slice(got, func(i, j int) bool {
return len(got[i].SubscriptionIDs) < len(got[j].SubscriptionIDs)
})
sort.Slice(tt.want, func(i, j int) bool {
return tt.want[i].ReceiverID < tt.want[j].ReceiverID
})
sort.Slice(tt.want, func(i, j int) bool {
return len(tt.want[i].SubscriptionIDs) < len(tt.want[j].SubscriptionIDs)
})
if diff := cmp.Diff(got, tt.want); diff != "" {
t.Errorf("ReduceMetaMessages() diff = %v", diff)
}
Expand Down

0 comments on commit 0fa9c68

Please sign in to comment.