forked from go-graphite/carbonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
48 lines (39 loc) · 1.05 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
package main
import (
"fmt"
"testing"
"time"
)
func TestDateParamToEpoch(t *testing.T) {
timeNow = func() time.Time {
//16 Aug 1994 15:30
return time.Date(1994, time.August, 16, 15, 30, 0, 100, defaultTimeZone)
}
const shortForm = "15:04 2006-Jan-02"
var tests = []struct {
input string
output string
}{
{"midnight", "00:00 1994-Aug-16"},
{"noon", "12:00 1994-Aug-16"},
{"teatime", "16:00 1994-Aug-16"},
{"tomorrow", "00:00 1994-Aug-17"},
{"noon 08/12/94", "12:00 1994-Aug-12"},
{"midnight 20060812", "00:00 2006-Aug-12"},
{"noon tomorrow", "12:00 1994-Aug-17"},
{"17:04 19940812", "17:04 1994-Aug-12"},
{"-1day", "15:30 1994-Aug-15"},
{"19940812", "00:00 1994-Aug-12"},
}
for _, tt := range tests {
got := dateParamToEpoch(tt.input, 0)
ts, err := time.ParseInLocation(shortForm, tt.output, defaultTimeZone)
if err != nil {
panic(fmt.Sprintf("error parsing time: %q: %v", tt.output, err))
}
want := int32(ts.Unix())
if got != want {
t.Errorf("dateParamToEpoch(%q, 0)=%v, want %v", tt.input, got, want)
}
}
}