Skip to content

Commit

Permalink
Use setupTestNotifier where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
bittersweet committed Oct 11, 2015
1 parent 69ca99e commit 58a4410
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
7 changes: 5 additions & 2 deletions notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
56 changes: 28 additions & 28 deletions rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,82 @@ 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",
Type: "boolean",
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",
Type: "boolean",
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",
Type: "string",
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",
Type: "string",
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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -192,6 +192,6 @@ func TestNumberLt(t *testing.T) {
Value: "13",
}

result := r.Met(&s)
result := r.Met(&event)
assert.Equal(t, true, result)
}

0 comments on commit 58a4410

Please sign in to comment.