-
Notifications
You must be signed in to change notification settings - Fork 8
/
duration_test.go
47 lines (38 loc) · 1.17 KB
/
duration_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
package pqinterval
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDurationValue(t *testing.T) {
i := new(Duration)
_ = i.Scan("3 years 182 days 01:22:33.456789")
val, err := i.Value()
assert.Nil(t, err, "Duration.Value() error")
assert.EqualValues(
t,
"3 years 182 days 1 hours 22 minutes 33 seconds 456 milliseconds 789 microseconds",
val,
"Duration.Value() result")
j := time.Duration(30) * time.Minute
k := Duration(j)
val, err = k.Value()
assert.Nil(t, err, "Duration.Value() error")
assert.EqualValues(
t,
"30 minutes",
val,
"Duration.Value() compatibility with time.Duration")
}
func TestZeroDuration(t *testing.T) {
i := new(Duration)
assert.EqualValues(t, time.Duration(0), *i, "Duration.Scan() result")
val, err := i.Value()
assert.Nil(t, err, "Duration.Value() error")
assert.EqualValues(t, "0 microseconds", val, "Duration.Value() result")
assert.NoError(t, i.Scan("00:00:00"), "Duration.Scan() error")
assert.EqualValues(t, time.Duration(0), *i, "Duration.Scan() result")
val, err = i.Value()
assert.Nil(t, err, "Duration.Value() error")
assert.EqualValues(t, "0 microseconds", val, "Duration.Value() result")
}