| 1 |
// Copyright (c) 2020 Tulir Asokan |
| 2 |
// |
| 3 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
package pushrules_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"testing" |
| 11 |
|
| 12 |
"github.com/stretchr/testify/assert" |
| 13 |
) |
| 14 |
|
| 15 |
func TestPushCondition_Match_KindMemberCount_OneToOne_ImplicitPrefix(t *testing.T) { |
| 16 |
condition := newCountPushCondition("2") |
| 17 |
room := newFakeRoom(2) |
| 18 |
assert.True(t, condition.Match(room, countConditionTestEvent)) |
| 19 |
} |
| 20 |
|
| 21 |
func TestPushCondition_Match_KindMemberCount_OneToOne_ExplicitPrefix(t *testing.T) { |
| 22 |
condition := newCountPushCondition("==2") |
| 23 |
room := newFakeRoom(2) |
| 24 |
assert.True(t, condition.Match(room, countConditionTestEvent)) |
| 25 |
} |
| 26 |
|
| 27 |
func TestPushCondition_Match_KindMemberCount_BigRoom(t *testing.T) { |
| 28 |
condition := newCountPushCondition(">200") |
| 29 |
room := newFakeRoom(201) |
| 30 |
assert.True(t, condition.Match(room, countConditionTestEvent)) |
| 31 |
} |
| 32 |
|
| 33 |
func TestPushCondition_Match_KindMemberCount_BigRoom_Fail(t *testing.T) { |
| 34 |
condition := newCountPushCondition(">=200") |
| 35 |
room := newFakeRoom(199) |
| 36 |
assert.False(t, condition.Match(room, countConditionTestEvent)) |
| 37 |
} |
| 38 |
|
| 39 |
func TestPushCondition_Match_KindMemberCount_SmallRoom(t *testing.T) { |
| 40 |
condition := newCountPushCondition("<10") |
| 41 |
room := newFakeRoom(9) |
| 42 |
assert.True(t, condition.Match(room, countConditionTestEvent)) |
| 43 |
} |
| 44 |
|
| 45 |
func TestPushCondition_Match_KindMemberCount_SmallRoom_Fail(t *testing.T) { |
| 46 |
condition := newCountPushCondition("<=10") |
| 47 |
room := newFakeRoom(11) |
| 48 |
assert.False(t, condition.Match(room, countConditionTestEvent)) |
| 49 |
} |
| 50 |
|
| 51 |
func TestPushCondition_Match_KindMemberCount_InvalidPrefix(t *testing.T) { |
| 52 |
condition := newCountPushCondition("??10") |
| 53 |
room := newFakeRoom(11) |
| 54 |
assert.False(t, condition.Match(room, countConditionTestEvent)) |
| 55 |
} |
| 56 |
|
| 57 |
func TestPushCondition_Match_KindMemberCount_InvalidCondition(t *testing.T) { |
| 58 |
condition := newCountPushCondition("foobar") |
| 59 |
room := newFakeRoom(1) |
| 60 |
assert.False(t, condition.Match(room, countConditionTestEvent)) |
| 61 |
} |