-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathepub_test.go
45 lines (37 loc) · 1.02 KB
/
epub_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
package epub
import (
"encoding/json"
"path/filepath"
"testing"
"github.com/pirmd/verify"
)
const (
testdataPath = "./testdata"
)
func TestGetPackageFromFile(t *testing.T) {
testCases, err := filepath.Glob(filepath.Join(testdataPath, "*.epub"))
if err != nil {
t.Fatalf("cannot read test data in %s:%v", testdataPath, err)
}
out := []*PackageDocument{}
for _, tc := range testCases {
opf, err := GetPackageFromFile(tc)
if err != nil {
t.Errorf("Fail to get package for %s: %v", tc, err)
}
out = append(out, opf)
}
got, err := json.MarshalIndent(out, "", " ")
if err != nil {
t.Fatalf("Fail to marshal test output to json: %v", err)
}
if failure := verify.MatchGolden(t.Name(), string(got)); failure != nil {
t.Fatalf("Package Document is not as expected:\n%v", failure)
}
}
func TestGetPackageFromFileCorruptInput(t *testing.T) {
tc := filepath.Join(testdataPath, "corrupt", "*.epub")
if _, err := GetPackageFromFile(tc); err == nil {
t.Errorf("Expected error when getting package for %s", tc)
}
}