-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilter_test.go
73 lines (60 loc) · 1.35 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
61
62
63
64
65
66
67
68
69
70
71
72
73
package filter
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFile(t *testing.T) {
f, err := os.CreateTemp("", "tmpfile-")
if err != nil {
t.Fatalf("Got error %v\n", err)
}
defer f.Close()
defer os.Remove(f.Name())
data := []byte(`
###
# Demo file
###
1
2
3 # Comment
# 4
`)
if _, err := f.Write(data); err != nil {
t.Fatalf("Got error %v\n", err)
}
fil, err := NewFilterFromFile(context.TODO(), f.Name(), None)
if err != nil {
t.Fatalf("Got error %v\n", err)
}
for _, chanid := range []uint64{1, 2, 3} {
assert.Equal(t, true, fil.AllowChanID(chanid), "Should be allowed")
}
for _, chanid := range []uint64{4, 1337} {
assert.Equal(t, false, fil.AllowChanID(chanid), "Should not be allowed")
}
}
func TestOptions(t *testing.T) {
f, err := os.CreateTemp("", "tmpfile-")
if err != nil {
t.Fatalf("Got error %v\n", err)
}
defer f.Close()
defer os.Remove(f.Name())
data := []byte(`
###
# Demo file
###
public
`)
if _, err := f.Write(data); err != nil {
t.Fatalf("Got error %v\n", err)
}
fil, err := NewFilterFromFile(context.TODO(), f.Name(), AllowAllPrivate)
if err != nil {
t.Fatalf("Got error %v\n", err)
}
assert.Equal(t, true, fil.AllowSpecial(true), "Private channels should be allowed")
assert.Equal(t, true, fil.AllowSpecial(false), "Publlic channels should be allowed")
}