-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags_test.go
More file actions
67 lines (61 loc) · 2.85 KB
/
Copy pathflags_test.go
File metadata and controls
67 lines (61 loc) · 2.85 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
package main
import "testing"
func TestMatchType(t *testing.T) {
file := entryStatus{kind: "dotfile"}
repo := entryStatus{kind: "repo"}
tests := []struct {
name string
entry entryStatus
types multiFlag
want bool
}{
{"no filter matches dotfile", file, nil, true},
{"no filter matches repo", repo, nil, true},
{"repo matches repo", repo, multiFlag{"repo"}, true},
{"repo no match dotfile", file, multiFlag{"repo"}, false},
{"dotfile matches dotfile", file, multiFlag{"dotfile"}, true},
{"dotfile no match repo", repo, multiFlag{"dotfile"}, false},
{"!repo matches dotfile", file, multiFlag{"!repo"}, true},
{"!repo no match repo", repo, multiFlag{"!repo"}, false},
{"multi OR: repo or dotfile", file, multiFlag{"repo", "dotfile"}, true},
{"unknown type no match", file, multiFlag{"unknown"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := matchType(tt.entry, tt.types); got != tt.want {
t.Errorf("matchType() = %v, want %v", got, tt.want)
}
})
}
}
func TestMatchState(t *testing.T) {
tests := []struct {
name string
state entryState
states multiFlag
want bool
}{
{"no filter matches any", stateOK, nil, true},
{"ok matches ok", stateOK, multiFlag{"ok"}, true},
{"ok* matches ok", stateChanged, multiFlag{"ok"}, true},
{"ok no match empty", stateEmpty, multiFlag{"ok"}, false},
{"empty matches empty", stateEmpty, multiFlag{"empty"}, true},
{"blocked matches blocked", stateBlocked, multiFlag{"blocked"}, true},
{"src-missing matches src-missing", stateSrcMissing, multiFlag{"src-missing"}, true},
{"!ok excludes ok", stateOK, multiFlag{"!ok"}, false},
{"!ok excludes ok*", stateChanged, multiFlag{"!ok"}, false},
{"!ok includes empty", stateEmpty, multiFlag{"!ok"}, true},
{"!ok includes blocked", stateBlocked, multiFlag{"!ok"}, true},
{"multi OR: empty or blocked", stateEmpty, multiFlag{"empty", "blocked"}, true},
{"multi OR: no match ok", stateOK, multiFlag{"empty", "blocked"}, false},
{"negation excludes explicitly", stateBlocked, multiFlag{"!blocked"}, false},
{"negation includes others", stateEmpty, multiFlag{"!blocked"}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := matchState(tt.state, tt.states); got != tt.want {
t.Errorf("matchState(%s, %v) = %v, want %v", tt.state, tt.states, got, tt.want)
}
})
}
}