-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
78 lines (64 loc) · 2.13 KB
/
options_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
package main
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestProtectArgs(t *testing.T) {
assert := require.New(t)
args := []string{`fdf`, `-r`, `--protect`, `./a/**/*`, `--unprotect`, `a/**/bar`, `a`, `./b`}
var o options
dirs := o.ParseArgs(args)
assert.True(o.Recursive)
assert.Len(dirs, 2)
assert.Equal("a", dirs[0])
assert.Equal("./b", dirs[1])
cases := map[string]bool{
"./a/foo": true,
"./a/foo/bar": false,
"./b/foo": false,
"./b/foo/bar": false,
}
for in, out := range cases {
abs, err := filepath.Abs(in)
assert.NoError(err)
assert.Equal(out, o.Protect.Includes(abs), "expected Includes=%t for '%s'", out, in)
}
}
func TestOptions_ParseArgs(t *testing.T) {
assert := require.New(t)
mockFileRecord := &fileRecord{
FilePath: "Path/To/File",
FoldedName: "FoldedName",
FoldedParent: "FoldedParent",
}
tests := []struct {
spec string
verb verb
expect matchFlag
comparers []string
}{
{"content", VerbMakeLinks, matchContent | matchSize, nil},
{"size", VerbMakeLinks, matchSize, nil},
{"name", VerbMakeLinks, matchName, nil},
{"content+name", VerbMakeLinks, matchContent | matchName, nil},
{"size+name", VerbMakeLinks, matchSize | matchName, nil},
{"name+content", VerbMakeLinks, matchName | matchContent, nil},
{"name[0:3]+content", VerbMakeLinks, matchContent, []string{"FoldedName"}},
{"parent[0:3]+content", VerbMakeLinks, matchContent, []string{"FoldedParent"}},
{"content+path", VerbMakeLinks, matchContent | matchParent | matchPathSuffix, []string{filepath.Join("Path", "To")}},
{"content+name", VerbSplitLinks, matchContent | matchName | matchHardlink, nil},
{"size+name", VerbSplitLinks, matchSize | matchName | matchHardlink, nil},
{"name+content", VerbSplitLinks, matchName | matchContent | matchHardlink, nil},
}
for _, t := range tests {
var o options
err := o.parseMatchSpec(t.spec, t.verb)
assert.NoError(err)
assert.Equal(t.expect, o.MatchMode, t.spec)
assert.Len(o.Comparers, len(t.comparers))
for i, c := range o.Comparers {
assert.Equal(t.comparers[i], c.HashFunc(mockFileRecord))
}
}
}