-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack_test.go
113 lines (84 loc) · 2.13 KB
/
pack_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_files(t *testing.T) {
t.Parallel()
accept, err := files("./testdata/zipme", []string{"./testdata/zipme/.ignore", "./testdata/zipme/.ignore1"})
assert.Nil(t, err)
assert.Equal(t, 9, len(accept))
}
func Test_ignore(t *testing.T) {
t.Parallel()
avoid := ignore([]string{"./testdata/zipme/.ignore", "./testdata/zipme/.ignore1", "./testdata/unknown"})
keys := []string{"*.png", "*.pdf", "folder2"}
assert.Equal(t, 3, len(avoid))
for _, k := range keys {
_, ok := avoid[k]
assert.True(t, ok)
}
}
func Test_isHidden(t *testing.T) {
t.Parallel()
cases := []struct {
file string
expected bool
}{
{".hidden", true},
{"regular", false},
{"nothidden.", false},
{"nor.mal", false},
{"..hidden", true},
{".", true},
{"..", true},
{"", true},
}
for _, tc := range cases {
assert.Equal(t, tc.expected, isHidden(tc.file))
}
}
func Test_parsePath(t *testing.T) {
t.Parallel()
homeDir, err := os.UserHomeDir()
assert.Nil(t, err)
cases := []struct {
file, expected string
}{
{"/some/path/to/file.ext", "/some/path/to/file.ext"},
{"~/Desktop", homeDir + "/Desktop"},
{"/some/path/./to/../file.ext", "/some/path/file.ext"},
{"some/path/./with/dot.ext", "some/path/with/dot.ext"},
}
for _, tc := range cases {
assert.Equal(t, tc.expected, parsePath(tc.file))
}
}
func Test_isDir(t *testing.T) {
t.Parallel()
assert.True(t, isDir("./testdata"))
assert.False(t, isDir("./testdata/empty.txt"))
}
func Test_createRootDir(t *testing.T) {
t.Parallel()
tmp := "/tmp/pack"
path, err := createRootDir("./testdata/empty.txt", tmp)
assert.Nil(t, err)
assert.Equal(t, tmp+"/empty", path)
assert.True(t, isDir(path))
_ = os.RemoveAll("/tmp/pack")
}
func Test_dupe(t *testing.T) {
t.Parallel()
src, dest, file := "./testdata", "/tmp/pack-dupe", "/empty.txt"
err := dupe(src, dest)
assert.Nil(t, err)
assert.True(t, isDir(dest))
err = dupe(src+file, dest+file)
assert.Nil(t, err)
_, err = os.Stat(dest + file)
assert.False(t, isDir(dest+file))
assert.True(t, !os.IsNotExist(err))
_ = os.RemoveAll("/tmp/pack-dupe")
}