forked from tonistiigi/fsutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat_test.go
56 lines (47 loc) · 1.41 KB
/
stat_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
package fsutil
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tonistiigi/fsutil/types"
)
func TestStat(t *testing.T) {
requiresRoot(t)
d, err := tmpDir(changeStream([]string{
"ADD foo file data1",
"ADD zzz dir",
"ADD zzz/aa file data3",
"ADD zzz/bb dir",
"ADD zzz/bb/cc dir",
"ADD zzz/bb/cc/dd symlink ../../",
"ADD sock socket",
}))
assert.NoError(t, err)
defer os.RemoveAll(d)
st, err := Stat(filepath.Join(d, "foo"))
assert.NoError(t, err)
assert.NotZero(t, st.ModTime)
st.ModTime = 0
assert.Equal(t, &types.Stat{Path: "foo", Mode: 0644, Size_: 5}, st)
st, err = Stat(filepath.Join(d, "zzz"))
assert.NoError(t, err)
assert.NotZero(t, st.ModTime)
st.ModTime = 0
assert.Equal(t, &types.Stat{Path: "zzz", Mode: uint32(os.ModeDir | 0700)}, st)
st, err = Stat(filepath.Join(d, "zzz/aa"))
assert.NoError(t, err)
assert.NotZero(t, st.ModTime)
st.ModTime = 0
assert.Equal(t, &types.Stat{Path: "aa", Mode: 0644, Size_: 5}, st)
st, err = Stat(filepath.Join(d, "zzz/bb/cc/dd"))
assert.NoError(t, err)
assert.NotZero(t, st.ModTime)
st.ModTime = 0
assert.Equal(t, &types.Stat{Path: "dd", Mode: uint32(os.ModeSymlink | 0777), Size_: 6, Linkname: "../../"}, st)
st, err = Stat(filepath.Join(d, "sock"))
assert.NoError(t, err)
assert.NotZero(t, st.ModTime)
st.ModTime = 0
assert.Equal(t, &types.Stat{Path: "sock", Mode: 0755 /* ModeSocket not set */}, st)
}