-
Notifications
You must be signed in to change notification settings - Fork 191
/
fs_test.go
50 lines (43 loc) · 1.19 KB
/
fs_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
package fakeobj_test
import (
"testing"
"time"
"github.com/gookit/goutil/testutil/assert"
"github.com/gookit/goutil/testutil/fakeobj"
)
func TestNewDirEntry(t *testing.T) {
de := fakeobj.NewDirEntry("/some/path/to/dir", true)
assert.True(t, de.IsDir())
assert.Gt(t, int(de.Type()), 0)
assert.Equal(t, "dir", de.Name())
fi, err := de.Info()
assert.NoError(t, err)
assert.True(t, fi.IsDir())
assert.Gt(t, int(fi.Mode()), 0)
assert.Equal(t, "dir", fi.Name())
}
func TestNewFileInfo(t *testing.T) {
fi := fakeobj.NewFile("/some/path/to/file")
fi.WithBody("hello")
fi.WithMtime(time.Now().Add(-time.Hour))
assert.False(t, fi.IsDir())
assert.Gt(t, int(fi.Mode()), 0)
assert.Gt(t, fi.Size(), 0)
assert.Equal(t, "file", fi.Name())
assert.True(t, fi.ModTime().Before(time.Now()))
assert.NoError(t, fi.Close())
bs := make([]byte, 5)
n, err := fi.Read(bs)
assert.NoError(t, err)
assert.Gt(t, n, 0)
assert.Equal(t, "hello", string(bs))
fi.Reset()
st, err := fi.Stat()
assert.NoError(t, err)
assert.NotEmpty(t, st)
fi = fakeobj.NewFileInfo("/some/path/to/dir", true)
assert.True(t, fi.IsDir())
assert.Gt(t, int(fi.Mode()), 0)
assert.Equal(t, "dir", fi.Name())
assert.Nil(t, fi.Sys())
}