-
Notifications
You must be signed in to change notification settings - Fork 1
/
nopfs_test.go
82 lines (67 loc) · 1.5 KB
/
nopfs_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
74
75
76
77
78
79
80
81
82
package nopfs
import (
"io"
"testing"
"github.com/ipfs-shipyard/nopfs/tester"
"github.com/ipfs/boxo/path"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
)
type testBlocker struct {
Blocker
}
type testHeader struct {
DenylistHeader
}
func (th testHeader) Name() string {
return th.DenylistHeader.Name
}
func (th testHeader) Hints() map[string]string {
return th.DenylistHeader.Hints
}
func (tb *testBlocker) ReadHeader(r io.Reader) (tester.Header, error) {
dl := Denylist{}
err := dl.Header.Decode(r)
if err != nil {
return testHeader{}, err
}
return testHeader{
DenylistHeader: dl.Header,
}, nil
}
func (tb *testBlocker) ReadDenylist(r io.ReadSeekCloser) error {
tb.Blocker.Denylists = make(map[string]*Denylist)
dl, err := NewDenylistReader(r)
if err != nil {
return err
}
dl.Filename = "test"
tb.Blocker.Denylists["test"] = dl
return nil
}
func (tb *testBlocker) IsPathBlocked(p path.Path) bool {
res := tb.Blocker.IsPathBlocked(p)
return res.Status == StatusBlocked
}
func (tb *testBlocker) IsCidBlocked(c cid.Cid) bool {
res := tb.Blocker.IsCidBlocked(c)
return res.Status == StatusBlocked
}
func TestSuite(t *testing.T) {
logging.SetLogLevel("nopfs", "ERROR")
tb := testBlocker{
Blocker: Blocker{},
}
suite := &tester.Suite{
TestHeader: true,
TestCID: true,
TestCIDPath: true,
TestIPNSPath: true,
TestDoubleHashLegacy: true,
TestDoubleHash: true,
}
err := suite.Run(&tb)
if err != nil {
t.Fatal(err)
}
}