forked from earthly/fsutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat_test.go
More file actions
71 lines (59 loc) · 1.7 KB
/
stat_test.go
File metadata and controls
71 lines (59 loc) · 1.7 KB
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
package fsutil
import (
"os"
"path/filepath"
"runtime"
"strings"
"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)
}
func TestStat_SkipAppleXattrs(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("skipping test that requires darwin")
}
st, err := Stat("Dockerfile")
assert.NoError(t, err)
for key := range st.Xattrs {
assert.False(t, strings.HasPrefix(key, "com.apple."))
}
}