-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
71 lines (68 loc) · 1.7 KB
/
message_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 dynamomq_test
import (
"testing"
"time"
"github.com/vvatanabe/dynamomq"
"github.com/vvatanabe/dynamomq/internal/clock"
"github.com/vvatanabe/dynamomq/internal/test"
)
func TestMessageGetStatus(t *testing.T) {
type args struct {
now time.Time
}
type testCase[T any] struct {
name string
m dynamomq.Message[T]
args args
want dynamomq.Status
}
tests := []testCase[any]{
{
name: "should return StatusReady when InvisibleUntilAt is empty",
m: dynamomq.Message[any]{
InvisibleUntilAt: "",
},
args: args{
now: test.DefaultTestDate,
},
want: dynamomq.StatusReady,
},
{
name: "should return StatusProcessing when current time is before InvisibleUntilAt",
m: dynamomq.Message[any]{
InvisibleUntilAt: clock.FormatRFC3339Nano(test.DefaultTestDate.Add(time.Second)),
},
args: args{
now: test.DefaultTestDate,
},
want: dynamomq.StatusProcessing,
},
{
name: "should return StatusReady when current time is after InvisibleUntilAt",
m: dynamomq.Message[any]{
InvisibleUntilAt: clock.FormatRFC3339Nano(test.DefaultTestDate.Add(time.Second * 5)),
},
args: args{
now: test.DefaultTestDate.Add(time.Second * 6),
},
want: dynamomq.StatusReady,
},
{
name: "should return StatusProcessing when current time is equal InvisibleUntilAt",
m: dynamomq.Message[any]{
InvisibleUntilAt: clock.FormatRFC3339Nano(test.DefaultTestDate),
},
args: args{
now: test.DefaultTestDate,
},
want: dynamomq.StatusProcessing,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.m.GetStatus(tt.args.now); got != tt.want {
t.Errorf("GetStatus() = %v, want %v", got, tt.want)
}
})
}
}