forked from bmaupin/go-epub
-
Notifications
You must be signed in to change notification settings - Fork 7
/
dirinfo_test.go
88 lines (72 loc) · 1.22 KB
/
dirinfo_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
package epub
import (
"bytes"
"io/fs"
"testing"
"time"
)
func Test_fileInfoToDirEntry(t *testing.T) {
f := file{
name: "test",
mode: fs.ModeDir,
}
d := fileInfoToDirEntry(&f)
_, err := d.Info()
if err != nil {
t.Fatal(err)
}
if !d.IsDir() {
t.Fail()
}
if d.Type()&fs.ModeDir == 0 {
t.Fail()
}
if d.Name() != "test" {
t.Fail()
}
if fileInfoToDirEntry(nil) != nil {
t.Fail()
}
}
type file struct {
name string
modTime time.Time
content bytes.Buffer
mode fs.FileMode
}
func (f *file) Info() (fs.FileInfo, error) {
return f, nil
}
func (f *file) Stat() (fs.FileInfo, error) {
return f, nil
}
func (f *file) Read(b []byte) (int, error) {
return f.content.Read(b)
}
func (f *file) Close() error {
return nil
}
func (f *file) Write(p []byte) (n int, err error) {
return f.content.Write(p)
}
func (f *file) Name() string {
return f.name
}
func (f *file) Size() int64 {
return int64(f.content.Len())
}
func (f *file) Type() fs.FileMode {
return f.mode & fs.ModeType
}
func (f *file) Mode() fs.FileMode {
return f.mode
}
func (f *file) ModTime() time.Time {
return f.modTime
}
func (f *file) IsDir() bool {
return f.mode&fs.ModeDir != 0
}
func (f *file) Sys() interface{} {
return nil
}