-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
45 lines (37 loc) · 1.04 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
package main
import (
"testing"
"time"
)
var (
testFilename = "2014-10-11-15-45.json"
testFilename2 = "test_data/2014-10-11-15-45.json"
testFilenameFail = "201-10-11-1-45.json"
tz, _ = time.LoadLocation("America/New_York")
expectedTime = time.Date(2014, time.October, 11, 15, 45, 0, 0, tz)
)
func TestFilenameRegex(t *testing.T) {
if !filenameRegex.MatchString(testFilename) {
t.Error("regex did not properly match")
}
if !filenameRegex.MatchString(testFilename2) {
t.Error("regex did not properly match")
}
if filenameRegex.MatchString(testFilenameFail) {
t.Error("regex should not have matched")
}
}
func TestPullDate(t *testing.T) {
tm, err := getDate(testFilename)
if err != nil || tm.String() != expectedTime.String() {
t.Errorf("Failed to properly parse date, found %s, expected %s", tm, expectedTime)
}
tm, err = getDate(testFilename2)
if err != nil {
t.Errorf("Failed to properly parse date")
}
_, err = getDate(testFilenameFail)
if err == nil {
t.Error("Improper date parsed without failure")
}
}