Skip to content

Commit 762eb59

Browse files
test withinduration
1 parent d38184c commit 762eb59

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

pkg/date/date_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package date
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestWithinDuration(t *testing.T) {
9+
type args struct {
10+
expected time.Time
11+
actual time.Time
12+
delta time.Duration
13+
}
14+
tests := []struct {
15+
name string
16+
args args
17+
want bool
18+
}{
19+
{
20+
name: "is within duration",
21+
args: args{
22+
expected: time.Date(2021, 12, 21, 0, 0, 0, 0, time.UTC),
23+
actual: time.Date(2021, 12, 21, 0, 0, 1, 0, time.UTC),
24+
delta: time.Millisecond * 1500,
25+
},
26+
want: true,
27+
},
28+
{
29+
name: "not within duration",
30+
args: args{
31+
expected: time.Date(2021, 12, 21, 0, 0, 0, 0, time.UTC),
32+
actual: time.Date(2021, 12, 21, 0, 0, 1, 0, time.UTC),
33+
delta: time.Millisecond * 900,
34+
},
35+
want: false,
36+
},
37+
{
38+
name: "not inclusive start",
39+
args: args{
40+
expected: time.Date(2021, 12, 21, 0, 0, 0, 0, time.UTC),
41+
actual: time.Date(2021, 12, 21, 0, 0, 1, 0, time.UTC),
42+
delta: time.Second,
43+
},
44+
want: false,
45+
},
46+
{
47+
name: "not inclusive end",
48+
args: args{
49+
expected: time.Date(2021, 12, 21, 0, 0, 1, 0, time.UTC),
50+
actual: time.Date(2021, 12, 21, 0, 0, 0, 0, time.UTC),
51+
delta: time.Second,
52+
},
53+
want: false,
54+
},
55+
}
56+
for _, tt := range tests {
57+
t.Run(tt.name, func(t *testing.T) {
58+
if got := WithinDuration(tt.args.expected, tt.args.actual, tt.args.delta); got != tt.want {
59+
t.Errorf("WithinDuration() = %v, want %v", got, tt.want)
60+
}
61+
})
62+
}
63+
}

0 commit comments

Comments
 (0)