-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdate_test.go
45 lines (40 loc) · 1.07 KB
/
date_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 harvest
import (
"testing"
"time"
)
func TestDateMarshallJSON(t *testing.T) {
time, _ := time.Parse("2006-01-02", "2017-03-01")
d := Date{time}
jsonBytes, err := d.MarshalJSON()
if err != nil {
t.Fatal(err)
}
if string(jsonBytes) != "\"2017-03-01\"" {
t.Errorf("Expected '\"2017-03-01\"'. Got '%s'", string(jsonBytes))
}
var dNull *Date
jsonBytes, err = dNull.MarshalJSON()
if err != nil {
t.Fatal(err)
}
if string(jsonBytes) != "null" {
t.Errorf("Expected nil Date{} to marshal to JSON as 'null. Got '%s' instead.", string(jsonBytes))
}
}
func TestDateMatchesTrue(t *testing.T) {
t1, _ := time.Parse("2006-01-02", "2017-03-01")
t2 := t1.Add(time.Minute * time.Duration(30))
d := Date{t1}
if d.Matches(t2) != true {
t.Errorf("Date.Matches() should be true as long as the date parts match")
}
}
func TestDateMatchesFalse(t *testing.T) {
t1, _ := time.Parse("2006-01-02", "2017-03-01")
t2, _ := time.Parse("2006-01-02", "2017-03-02")
d := Date{t1}
if d.Matches(t2) != false {
t.Errorf("Date.Matches() should be fale when date parts are different")
}
}