-
Notifications
You must be signed in to change notification settings - Fork 3
/
irsync_test.go
72 lines (62 loc) · 1.73 KB
/
irsync_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
package main
import "testing"
// TestCmdParsing test command line parsing.
func TestCmdParsing(t *testing.T) {
commandSets := []struct {
Args []string
RsyncExpects int
IrsyncExpects int
}{
{
Args: []string{
"-pvrt",
"--modify-window=30",
"--delete",
"--exclude='custom'",
"--exclude='somefile.txt'",
"rsync://[email protected]:873/data/",
"/media",
},
RsyncExpects: 7,
IrsyncExpects: 0,
},
{
Args: []string{
"-pvrt",
"--modify-window=30",
"--irsync-timeout-seconds=200",
"--irsync-interval-seconds=300",
"--delete",
"--exclude='custom'",
"--exclude='somefile.txt'",
"rsync://[email protected]:873/data/",
"/media",
},
RsyncExpects: 7,
IrsyncExpects: 2,
},
}
for _, commandSet := range commandSets {
rsyncArgs, irsyncArgs := parseCmdArgs(commandSet.Args)
// Test sorting out rsync from irsync flags
//
if len(rsyncArgs) != commandSet.RsyncExpects {
t.Errorf("rsync got %d args but expected %d.", len(rsyncArgs), commandSet.RsyncExpects)
}
if len(irsyncArgs) != commandSet.IrsyncExpects {
t.Errorf("irsync got %d args but expected %d.", len(irsyncArgs), commandSet.IrsyncExpects)
}
// Test default and specified values
if getIntegerFromArgs("--test-non-exist-key", irsyncArgs, 999) != 999 {
t.Errorf("Got wrong value or default value from args.")
}
kvt := getIntegerFromArgs("--irsync-timeout-seconds", irsyncArgs, 888)
if !(kvt == 888 || kvt == 200) {
t.Errorf("Got wrong value or default value from args, got %d.", kvt)
}
kvi := getIntegerFromArgs("--irsync-interval-seconds", irsyncArgs, 887)
if !(kvi == 887 || kvi == 300) {
t.Errorf("Got wrong value or default value from args, got %d.", kvi)
}
}
}