utils_test.go
903 字节
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
package utils
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestTimeSpan(t *testing.T) {
inputs := []struct {
t string
e bool
}{
{"10:00", false},
{"10:11", false},
{"24:00", true},
{"-1:00", true},
{"10:60", true},
{"A:B", true},
}
for i := range inputs {
err := ValidWorkTime(inputs[i].t)
if inputs[i].e {
assert.NotNil(t, err)
} else {
assert.Nil(t, err)
}
}
}
func TestComputeTimeDuration(t *testing.T) {
assertDuration := func(s string) time.Duration {
t, _ := time.ParseDuration(s)
return t
}
inputs := []struct {
t1 string
t2 string
ts time.Duration
}{
{
"9:00", "18:00", assertDuration("9h"),
},
{
"23:00", "6:00", assertDuration("7h"),
},
}
for i := range inputs {
input := inputs[i]
out, err := ComputeTimeDuration(input.t1, input.t2)
assert.Nil(t, err)
assert.Equal(t, input.ts, out)
}
}