-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_test.go
More file actions
78 lines (56 loc) · 1.56 KB
/
time_test.go
File metadata and controls
78 lines (56 loc) · 1.56 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package date
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSetTestNow(t *testing.T) {
mocked := time.Date(2024, time.June, 5, 12, 0, 0, 0, time.Local)
factory := func() time.Time {
return mocked
}
SetTestNow(factory)
defer ResetTestNow()
subject := now()
assert.Equal(t, subject, mocked, "Current time factory was not replaced by the set function")
}
func TestResetTestNow(t *testing.T) {
mocked := time.Date(2024, time.June, 5, 12, 0, 0, 0, time.Local)
factory := func() time.Time {
return mocked
}
SetTestNow(factory)
ResetTestNow()
subject := now()
assert.NotEqual(t, subject, mocked, "Current time factory was replaced")
}
func TestSetTestLocation(t *testing.T) {
mocked, _ := time.LoadLocation("Asia/Tokyo")
factory := func() *time.Location {
return mocked
}
SetTestLocation(factory)
defer ResetTestLocation()
subject := location()
assert.Equal(t, subject, mocked, "Location factory was not replaced by the set function")
}
func TestResetTestLocation(t *testing.T) {
mocked, _ := time.LoadLocation("Asia/Tokyo")
factory := func() *time.Location {
return mocked
}
SetTestLocation(factory)
ResetTestLocation()
subject := location()
assert.NotEqual(t, subject, mocked, "Location factory was replaced")
}
func TestNow(t *testing.T) {
mocked := time.Date(2024, time.June, 5, 12, 0, 0, 0, time.Local)
factory := func() time.Time {
return mocked
}
SetTestNow(factory)
defer ResetTestNow()
subject := Now()
assert.Equal(t, mocked, subject, "Now() should return mocked time when SetTestNow is used")
}