forked from richardlehane/siegfried
/
siegfried_test.go
129 lines (89 loc) · 3.05 KB
/
siegfried_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package siegfried
import (
"bytes"
"testing"
"github.com/richardlehane/siegfried/config"
"github.com/richardlehane/siegfried/pkg/core"
"github.com/richardlehane/siegfried/pkg/core/persist"
"github.com/richardlehane/siegfried/pkg/core/priority"
"github.com/richardlehane/siegfried/pkg/core/siegreader"
"github.com/richardlehane/siegfried/pkg/pronom"
)
func TestLoad(t *testing.T) {
s := New()
config.SetHome("./cmd/roy/data")
p, err := pronom.New()
if err != nil {
t.Fatal(err)
}
err = s.Add(p)
if err != nil {
t.Fatal(err)
}
}
func TestIdentify(t *testing.T) {
s := New()
s.em = testEMatcher{}
s.bm = testBMatcher{}
s.cm = nil
s.ids = append(s.ids, testIdentifier{})
c, err := s.Identify("test.doc", bytes.NewBufferString("test"))
if err != nil {
t.Error(err)
}
i := <-c
if i.String() != "fmt/3" {
t.Error("expecting fmt/3")
}
}
// extension matcher test stub
type testEMatcher struct{}
func (t testEMatcher) Identify(n string, sb siegreader.Buffer) (chan core.Result, error) {
ret := make(chan core.Result)
go func() {
ret <- testResult(0)
close(ret)
}()
return ret, nil
}
func (t testEMatcher) String() string { return "" }
func (t testEMatcher) Save(l *persist.LoadSaver) {}
func (t testEMatcher) Add(ss core.SignatureSet, l priority.List) (int, error) { return 0, nil }
// byte matcher test stub
type testBMatcher struct{}
func (t testBMatcher) Identify(nm string, sb siegreader.Buffer) (chan core.Result, error) {
ret := make(chan core.Result)
go func() {
ret <- testResult(1)
ret <- testResult(2)
close(ret)
}()
return ret, nil
}
func (t testBMatcher) String() string { return "" }
func (t testBMatcher) Save(l *persist.LoadSaver) {}
func (t testBMatcher) Add(ss core.SignatureSet, l priority.List) (int, error) { return 0, nil }
type testResult int
func (tr testResult) Index() int { return int(tr) }
func (tr testResult) Basis() string { return "" }
// identifier test stub
type testIdentifier struct{}
func (t testIdentifier) YAML() string { return "" }
func (t testIdentifier) Describe() [2]string { return [2]string{"a", "b"} }
func (t testIdentifier) Save(l *persist.LoadSaver) {}
func (t testIdentifier) Recorder() core.Recorder { return testRecorder{} }
func (t testIdentifier) Recognise(m core.MatcherType, i int) (bool, string) { return false, "" }
func (t testIdentifier) String() string { return "" }
// recorder test stub
type testRecorder struct{}
func (t testRecorder) Record(m core.MatcherType, r core.Result) bool { return true }
func (t testRecorder) Satisfied(m core.MatcherType) bool { return false }
func (t testRecorder) Report(c chan core.Identification) { c <- testIdentification{} }
// identification test stub
type testIdentification struct{}
func (t testIdentification) String() string { return "fmt/3" }
func (t testIdentification) Known() bool { return true }
func (t testIdentification) YAML() string { return "" }
func (t testIdentification) JSON() string { return "" }
func (t testIdentification) CSV() []string { return nil }
func (t testIdentification) Archive() config.Archive { return 0 }