-
Notifications
You must be signed in to change notification settings - Fork 13
/
filter_test.go
59 lines (53 loc) · 1 KB
/
filter_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
59
package oplog
import (
"testing"
"gopkg.in/mgo.v2/bson"
)
func TestFilterSingleType(t *testing.T) {
q := bson.M{}
f := Filter{Types: []string{"a"}}
f.apply(&q)
if q["data.t"] != "a" {
t.Fail()
}
}
func TestFilterMultiTypes(t *testing.T) {
q := bson.M{}
f := Filter{Types: []string{"a", "b"}}
f.apply(&q)
m, ok := q["data.t"].(bson.M)
if !ok {
t.Fatal("data.t is not a sub-bson")
}
s, ok := m["$in"].([]string)
if !ok {
t.Fatal("data.t doesn't contain a $in")
}
if s[0] != "a" || s[1] != "b" {
t.FailNow()
}
}
func TestFilterSingleParent(t *testing.T) {
q := bson.M{}
f := Filter{Parents: []string{"a"}}
f.apply(&q)
if q["data.p"] != "a" {
t.Fail()
}
}
func TestFilterMultiParents(t *testing.T) {
q := bson.M{}
f := Filter{Parents: []string{"a", "b"}}
f.apply(&q)
m, ok := q["data.p"].(bson.M)
if !ok {
t.Fatal("data.p is not a sub-bson")
}
s, ok := m["$in"].([]string)
if !ok {
t.Fatal("data.p doesn't contain a $in")
}
if s[0] != "a" || s[1] != "b" {
t.FailNow()
}
}