forked from matrix-org/gomatrixserverlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_test.go
60 lines (57 loc) · 1.37 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
60
package gomatrixserverlib
import (
"encoding/json"
"reflect"
"testing"
)
func Test_Filter(t *testing.T) {
tests := []struct {
name string
input []byte
want RoomEventFilter
}{
{
name: "empty types filter",
input: []byte(`{ "types": [] }`),
want: RoomEventFilter{
Limit: 0,
NotSenders: nil,
NotTypes: nil,
Senders: nil,
Types: &[]string{},
LazyLoadMembers: false,
IncludeRedundantMembers: false,
NotRooms: nil,
Rooms: nil,
ContainsURL: nil,
},
},
{
name: "absent types filter",
input: []byte(`{}`),
want: RoomEventFilter{
Limit: 0,
NotSenders: nil,
NotTypes: nil,
Senders: nil,
Types: nil,
LazyLoadMembers: false,
IncludeRedundantMembers: false,
NotRooms: nil,
Rooms: nil,
ContainsURL: nil,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var f RoomEventFilter
if err := json.Unmarshal(tt.input, &f); err != nil {
t.Fatalf("unable to parse filter: %v", err)
}
if !reflect.DeepEqual(f, tt.want) {
t.Fatalf("Expected %+v\ngot %+v", tt.want, f)
}
})
}
}