-
Notifications
You must be signed in to change notification settings - Fork 8
/
record_unlocker_test.go
71 lines (64 loc) · 1.9 KB
/
record_unlocker_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package outbox
import (
"errors"
"testing"
time2 "time"
"github.com/pkritiotis/outbox/internal/time"
"github.com/stretchr/testify/assert"
)
func Test_recordUnlocker_unlockExpiredMessages(t *testing.T) {
sampleTime := time2.Now().UTC()
timeProvider := &time.MockProvider{}
timeProvider.On("Now").Return(sampleTime)
tests := map[string]struct {
store Store
time time.Provider
MaxLockTimeDurationMins time2.Duration
expErr error
}{
"Successful unlocking should not return error": {
store: func() *MockStore {
mp := MockStore{}
mp.On("ClearLocksWithDurationBeforeDate", sampleTime.Add(-2*time2.Minute)).Return(nil)
return &mp
}(),
time: timeProvider,
MaxLockTimeDurationMins: 2 * time2.Minute,
expErr: nil,
},
"Error in unlocking should return error": {
store: func() *MockStore {
mp := MockStore{}
mp.On("ClearLocksWithDurationBeforeDate", sampleTime.Add(-2*time2.Minute)).Return(errors.New("test"))
return &mp
}(),
time: timeProvider,
MaxLockTimeDurationMins: 2 * time2.Minute,
expErr: errors.New("test"),
},
}
for name, test := range tests {
tt := test
t.Run(name, func(t *testing.T) {
d := recordUnlocker{
store: tt.store,
time: tt.time,
MaxLockTimeDurationMins: tt.MaxLockTimeDurationMins,
}
err := d.UnlockExpiredMessages()
assert.Equal(t, tt.expErr, err)
})
}
}
func Test_newRecordUnlocker(t *testing.T) {
mStore := &MockStore{}
duration := time2.Duration(1) * time2.Second
timeProvider := time.NewTimeProvider()
expRecordUnlocker := recordUnlocker{
store: mStore,
time: timeProvider,
MaxLockTimeDurationMins: duration,
}
rc := newRecordUnlocker(mStore, duration)
assert.Equal(t, expRecordUnlocker, rc)
}