-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
111 lines (88 loc) · 2.36 KB
/
main_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
package main
import "testing"
func reset() {
deleteSource = false
files = []string{}
useFileDate = false
useTimeZone = false
}
func TestPosixOptionGroup1(t *testing.T) {
reset()
args := []string{"-dt", "test-file.txt"}
if deleteSource && useTimeZone {
t.Errorf("deleteSource and useTimeZone already set to true")
} else if deleteSource {
t.Errorf("deleteSource already set to true")
} else if useTimeZone {
t.Errorf("useTimeZone already set to true")
}
argParse(args)
if deleteSource == false && useTimeZone == false {
t.Errorf("deleteSource and useTimeZone were not set to true")
} else if deleteSource == false {
t.Errorf("deleteSource was not set to true")
} else if useTimeZone == false {
t.Errorf("useTimeZone was not set to true")
}
}
func TestPosixOptionGroup2(t *testing.T) {
reset()
args := []string{"-td", "test-file.txt"}
argParse(args)
if deleteSource == false && useTimeZone == false {
t.Errorf("deleteSource and useTimeZone were not set to true")
} else if deleteSource == false {
t.Errorf("deleteSource was not set to true")
} else if useTimeZone == false {
t.Errorf("useTimeZone was not set to true")
}
}
func TestPosixOptionGroup3(t *testing.T) {
reset()
args := []string{"-tx", "test-file.txt"}
expect := "unknown option -x"
err := argParse(args)
got := ""
if err != nil {
got = err.Error()
}
if got != expect {
t.Errorf("expected %q but got %q", expect, got)
}
}
func TestPosixOptionGroup4(t *testing.T) {
reset()
args := []string{"-tv", "test-file.txt"}
expect := "invalid use of -v in a POSIX group"
err := argParse(args)
got := ""
if err != nil {
got = err.Error()
}
if got != expect {
t.Errorf("expected %q but got %q", expect, got)
}
}
func TestOptionParsing(t *testing.T) {
reset()
args := []string{"-t", "test-file.txt", "--", "--version"}
expect := []string{"test-file.txt", "--version"}
argParse(args)
for i, got := range files {
if i < len(expect) && got != expect[i] {
t.Errorf("expected [%d] %q but got %q", i, expect[i], got)
}
}
}
func TestFilenameGeneration(t *testing.T) {
reset()
filename := "test-file.txt"
args := []string{"-ft", filename}
argParse(args)
expect := "test-file.txt_2021-04-13_133403_PDT.gz"
_, modTime := fileContentAndModTime(filename)
got := datetimeFilename(filename, modTime)
if got != expect {
t.Errorf("expected %q but got %q", expect, got)
}
}