forked from richardlehane/siegfried
/
siegfried_test.go
115 lines (94 loc) · 3.47 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
package siegfried
import (
"bytes"
"testing"
"github.com/richardlehane/siegfried/internal/persist"
"github.com/richardlehane/siegfried/internal/siegreader"
"github.com/richardlehane/siegfried/pkg/config"
"github.com/richardlehane/siegfried/pkg/core"
"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.nm = testEMatcher{}
s.bm = testBMatcher{}
s.cm = nil
s.ids = append(s.ids, testIdentifier{})
c, err := s.Identify(bytes.NewBufferString("test"), "test.doc", "")
if err != nil {
t.Error(err)
}
i := c[0]
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, exclude ...int) (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 "" }
// byte matcher test stub
type testBMatcher struct{}
func (t testBMatcher) Identify(nm string, sb *siegreader.Buffer, exclude ...int) (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 "" }
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) Add(m core.Matcher, mt core.MatcherType) (core.Matcher, error) {
return nil, nil
}
func (t testIdentifier) Recorder() core.Recorder { return testRecorder{} }
func (t testIdentifier) Name() string { return "a" }
func (t testIdentifier) Details() string { return "b" }
func (t testIdentifier) Fields() []string { return nil }
func (t testIdentifier) Save(l *persist.LoadSaver) {}
func (t testIdentifier) String() string { return "" }
func (t testIdentifier) Inspect(s ...string) string { return "" }
func (t testIdentifier) GraphP(i int) string { return "" }
func (t testIdentifier) Recognise(m core.MatcherType, i int) (bool, string) { return false, "" }
// recorder test stub
type testRecorder struct{}
func (t testRecorder) Active(m core.MatcherType) {}
func (t testRecorder) Record(m core.MatcherType, r core.Result) bool { return true }
func (t testRecorder) Satisfied(m core.MatcherType) (bool, int) { return false, 0 }
func (t testRecorder) Report() []core.Identification {
return []core.Identification{testIdentification{}}
}
// identification test stub
type testIdentification struct{}
func (t testIdentification) String() string { return "fmt/3" }
func (t testIdentification) Warn() string { return "" }
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 }