-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_test.go
77 lines (65 loc) · 1.87 KB
/
actions_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
package main
import (
"os"
"strings"
"time"
"testing"
)
func TestFilterOut(t *testing.T) {
testCases := []struct {
name string
file string
ext string
minSize int64
modSince string
expected bool
}{
{"FilterNoExtension", "testdata/dir.log", "", 0, "", false},
{"FilterExtensionMatch", "testdata/dir.log", ".log", 0, "", false},
{"FilterExtensionNoMatch", "testdata/dir.log", ".sh", 0, "", true},
{"FilterExtensionSizeMatch", "testdata/dir.log", ".log", 10, "", false},
{"FilterExtensionSizeNoMatch", "testdata/dir.log", ".log", 20, "", true},
{"FilterExtensionTimeMatch", "testdata/dir.log", ".log", 0, "01 Apr 24 12:00 +0300", false},
{"FilterExtensionTimeNoMatch", "testdata/dir.log", ".log", 0, "12 Apr 24 12:00 +0300", true},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
info, err := os.Stat(tc.file)
if err != nil {
t.Fatal(err)
}
extList := strings.Fields(tc.ext)
var afterRFC822Z time.Time
if tc.modSince != "" {
afterRFC822Z, err = time.Parse(time.RFC822Z, tc.modSince)
if err != nil {
t.Fatal(err)
}
}
f := filterOut(tc.file, extList, tc.minSize, afterRFC822Z, info)
if f != tc.expected {
t.Errorf("Expected '%t', got '%t' instead\n", tc.expected, f)
}
})
}
}
func TestListContainsExt(t *testing.T) {
testCases := []struct {
name string
list []string
ext string
expected bool
}{
{"ListContain", []string{".log", ".rar", ".png", ".jpeg", "xlsb", ".txt"}, ".log", true},
{"ListNoContain", []string{".log", ".rar", ".png", ".jpeg", "xlsb", ".txt"}, ".zip", false},
{"ListEmptyNoContain", []string{}, ".zip", false},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
res := listContainsExt(tc.list, tc.ext)
if tc.expected != res {
t.Errorf("Expected %t, got %t instead.", tc.expected, res)
}
})
}
}