-
Notifications
You must be signed in to change notification settings - Fork 26
/
main_test.go
70 lines (65 loc) · 1.31 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
package main
import (
"reflect"
"testing"
"time"
)
func Test_convertIDtoCreationTime(t *testing.T) {
timestamp := "2017-01-28 06:02:39.924 +0000 UTC"
timeObj, _ := time.Parse("2006-01-02 15:04:05.999 -0700 MST", timestamp)
type args struct {
id string
}
tests := []struct {
name string
args args
want time.Time
}{
{
name: "274781269861072896",
args: args{"274781269861072896"},
want: timeObj,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := convertIDtoCreationTime(tt.args.id).UTC() // Convert to UTC
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("convertIDtoCreationTime() = %v, want %v", got, tt.want)
}
})
}
}
func Test_isUsernameSpam(t *testing.T) {
patterns := []string{
`(?i)Announcement`,
`(?i)FAQ`,
}
type args struct {
username string
patterns []string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Ham - janedoe",
args: args{"janedoe", patterns},
want: false,
},
{
name: "Spam - announcements23",
args: args{"announcements23", patterns},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isUsernameSpam(tt.args.username, tt.args.patterns); got != tt.want {
t.Errorf("isUsernameSpam() = %v, want %v", got, tt.want)
}
})
}
}