-
Notifications
You must be signed in to change notification settings - Fork 4
/
filter_test.go
48 lines (40 loc) · 947 Bytes
/
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
package greenleaf
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFilter(t *testing.T) {
got := Filter(
Eq("field", "value"),
Ne("field1", "value1"),
Gt("field2", "value2"),
Gte("field3", "value3"),
Lt("field4", "value4"),
Lte("field5", "value5"),
Exists("field6", true),
In("field7", []int{1, 2, 3}),
Nin("field8", []string{"foo", "bar"}),
)
want := FilterDocument{
"field": M{"$eq": "value"},
"field1": M{"$ne": "value1"},
"field2": M{"$gt": "value2"},
"field3": M{"$gte": "value3"},
"field4": M{"$lt": "value4"},
"field5": M{"$lte": "value5"},
"field6": M{"$exists": true},
"field7": M{"$in": []int{1, 2, 3}},
"field8": M{"$nin": []string{"foo", "bar"}},
}
assert.Equal(t, want, got)
}
func TestFilterSameFields(t *testing.T) {
got := Filter(
Eq("field", "value"),
Eq("field", 10),
)
want := FilterDocument{
"field": M{"$eq": 10},
}
assert.Equal(t, want, got)
}