From 58a4410763bff230e30f26cb7c6c5d9ad2025ed3 Mon Sep 17 00:00:00 2001 From: Mark Mulder Date: Sun, 11 Oct 2015 19:17:53 +0100 Subject: [PATCH] Use setupTestNotifier where applicable --- notifier_test.go | 7 ++++-- rules_test.go | 56 ++++++++++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/notifier_test.go b/notifier_test.go index 6bbbbaf..51df2b4 100644 --- a/notifier_test.go +++ b/notifier_test.go @@ -23,7 +23,10 @@ func (mn *LocalMessageNotifier) SendMessage(eventName string, target string, dat } func setupTestNotifier(data types.JsonText) Event { - return Event{"signup", data} + return Event{ + Identifier: "signup", + Data: data, + } } func TestNewNotifier(t *testing.T) { @@ -193,7 +196,7 @@ func TestNotifierRenderTemplateWithLogic(t *testing.T) { assert.Equal(t, expected, result) data = types.JsonText(`{"active": false, "name": "Go", "number": 12}`) - event = Event{"signup", data} + event = setupTestNotifier(data) result, _ = n.renderTemplate(&event) expected = []byte("inactive") diff --git a/rules_test.go b/rules_test.go index 8edfd6b..4e46f04 100644 --- a/rules_test.go +++ b/rules_test.go @@ -10,30 +10,30 @@ import ( var jt = types.JsonText(`{"active": true, "name": "Go", "number": 12}`) func TestRuleKeyDoesNotMatch(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "notactive", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestRuleKeyDoesMatch(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "active", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, true, result) } func TestBoolFalse(t *testing.T) { jt := types.JsonText(`{"active": false}`) - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "active", @@ -41,12 +41,12 @@ func TestBoolFalse(t *testing.T) { Value: "true", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestBoolTrue(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "active", @@ -54,12 +54,12 @@ func TestBoolTrue(t *testing.T) { Value: "true", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, true, result) } func TestStringDoesNotMatch(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "name", @@ -67,12 +67,12 @@ func TestStringDoesNotMatch(t *testing.T) { Value: "NotGo", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestStringDoesMatch(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "name", @@ -80,12 +80,12 @@ func TestStringDoesMatch(t *testing.T) { Value: "Go", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, true, result) } func TestNumberDoesNotEqual(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -94,12 +94,12 @@ func TestNumberDoesNotEqual(t *testing.T) { Value: "11", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestNumberEqual(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -108,12 +108,12 @@ func TestNumberEqual(t *testing.T) { Value: "12", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, true, result) } func TestNumberNotGt(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -122,12 +122,12 @@ func TestNumberNotGt(t *testing.T) { Value: "13", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestNumberNotGtEqual(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -136,12 +136,12 @@ func TestNumberNotGtEqual(t *testing.T) { Value: "12", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestNumberGt(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -150,12 +150,12 @@ func TestNumberGt(t *testing.T) { Value: "11", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, true, result) } func TestNumberNotLt(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -164,12 +164,12 @@ func TestNumberNotLt(t *testing.T) { Value: "11", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestNumberNotLtEqual(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -178,12 +178,12 @@ func TestNumberNotLtEqual(t *testing.T) { Value: "12", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, false, result) } func TestNumberLt(t *testing.T) { - s := Event{"Mark", jt} + event := setupTestNotifier(jt) r := rule{ Key: "number", @@ -192,6 +192,6 @@ func TestNumberLt(t *testing.T) { Value: "13", } - result := r.Met(&s) + result := r.Met(&event) assert.Equal(t, true, result) }