-
Notifications
You must be signed in to change notification settings - Fork 56
/
carboninterval_test.go
43 lines (32 loc) · 1.21 KB
/
carboninterval_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
package carbon
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestErrorOnConstruction(t *testing.T) {
startDate, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
endDate, _ := Create(2009, time.November, 9, 23, 0, 0, 0, "UTC")
_, err := NewCarbonInterval(startDate, endDate)
assert.Error(t, err, "the end date must be greater than or equal to the start date")
}
func TestDiffInHours(t *testing.T) {
startDate, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
endDate, _ := Create(2009, time.November, 10, 24, 0, 0, 0, "UTC")
interval, _ := NewCarbonInterval(startDate, endDate)
assert.Equal(t, int64(1), interval.DiffInHours())
}
func TestErrorOnNilStartDate(t *testing.T) {
endDate, _ := Create(2009, time.November, 10, 24, 0, 0, 0, "UTC")
_, err := NewCarbonInterval(nil, endDate)
assert.Error(t, err, "start date cannot be nil")
}
func TestErrorOnNilEndDate(t *testing.T) {
startDate, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
_, err := NewCarbonInterval(startDate, nil)
assert.Error(t, err, "end date cannot be nil")
}
func TestErrorOnNilDates(t *testing.T) {
_, err := NewCarbonInterval(nil, nil)
assert.Error(t, err, "start date cannot be nil")
}