-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
65 lines (54 loc) · 1.51 KB
/
main_test.go
File metadata and controls
65 lines (54 loc) · 1.51 KB
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
package main
import (
"flag"
"os"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestGetBaseTime(t *testing.T) {
Convey("aquires baseTime", t, func() {
Convey("when no timestamp or time are provided", func() {
result := getBaseTime()
So(result, ShouldHaveSameTypeAs, int64(time.Now().Unix()))
})
Convey("when time is provided", func() {
timeFlag = "2016-01-01T05:00"
result := getBaseTime()
So(result, ShouldEqual, 1451624400)
})
Convey("when timestamp is provided", func() {
timestampFlag = 1492267919
timeFlag = ""
result := getBaseTime()
So(result, ShouldEqual, 1492267919)
})
Convey("panic when both timestamp and time are provided", func() {
timestampFlag = 1492267919
timeFlag = "2016-01-01T05:00"
So(func() { getBaseTime() }, ShouldPanic)
})
timeFlag = ""
})
}
func TestGetResultTime(t *testing.T) {
Convey("correctly add / substract flag --diff", t, func() {
Convey("when --diff is 0", func() {
diffFlag = 0
baseTime := getBaseTime()
result := getResultTime(baseTime)
So(result, ShouldEqual, int64(time.Unix(baseTime, 0).Add(time.Duration(diffFlag)*time.Hour).Unix()))
})
Convey("when --diff is negative", func() {
diffFlag = -5
baseTime := getBaseTime()
result := getResultTime(baseTime)
So(result, ShouldEqual, int64(time.Unix(baseTime, 0).Add(time.Duration(diffFlag)*time.Hour).Unix()))
})
})
}
func TestMain(m *testing.M) {
// call flag.Parse() here if TestMain uses flags
flag.Parse()
os.Exit(m.Run())
}