-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwalk_test.go
78 lines (67 loc) · 2.01 KB
/
walk_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
package epub
import (
"bytes"
"fmt"
"io"
"io/fs"
"path/filepath"
"testing"
"github.com/pirmd/verify"
)
func TestWalkFiles(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)
}
got := new(bytes.Buffer)
for _, tc := range testCases {
fmt.Fprintf(got, "Files from %s\n", tc)
if err := WalkFiles(tc, func(r io.Reader, fi fs.FileInfo) error {
fmt.Fprintf(got, "- %s\n", fi.Name())
return nil
}); err != nil {
t.Errorf("Fail to get walk %s files: %v", tc, err)
}
}
if failure := verify.MatchGolden(t.Name(), got.String()); failure != nil {
t.Fatalf("Metadata is not as expected:\n%v", failure)
}
}
func TestWalkPublicationResources(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)
}
got := new(bytes.Buffer)
for _, tc := range testCases {
fmt.Fprintf(got, "Files from %s\n", tc)
if err := WalkPublicationResources(tc, func(r io.Reader, fi fs.FileInfo) error {
fmt.Fprintf(got, "- %s\n", fi.Name())
return nil
}); err != nil {
t.Errorf("Fail to get walk %s files: %v", tc, err)
}
}
if failure := verify.MatchGolden(t.Name(), got.String()); failure != nil {
t.Fatalf("Metadata is not as expected:\n%v", failure)
}
}
func TestWalkReadingContent(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)
}
got := new(bytes.Buffer)
for _, tc := range testCases {
fmt.Fprintf(got, "Files from %s\n", tc)
if err := WalkReadingContent(tc, func(r io.Reader, fi fs.FileInfo) error {
fmt.Fprintf(got, "- %s\n", fi.Name())
return nil
}); err != nil {
t.Errorf("Fail to get walk %s files: %v", tc, err)
}
}
if failure := verify.MatchGolden(t.Name(), got.String()); failure != nil {
t.Fatalf("Metadata is not as expected:\n%v", failure)
}
}