-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtt-timer_test.go
156 lines (152 loc) · 2.58 KB
/
mqtt-timer_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"reflect"
"testing"
"time"
)
func Test_offsetDuration(t *testing.T) {
type args struct {
timer Timer
}
tests := []struct {
name string
args args
want time.Duration
}{
{
name: "empty",
args: args{},
want: time.Duration(0),
},
{
name: "no time",
args: args{
timer: Timer{Before: "test"},
},
want: time.Duration(0),
},
{
name: "not sec, min",
args: args{
timer: Timer{Before: "test tst"},
},
want: time.Duration(0),
},
{
name: "not int",
args: args{
timer: Timer{Before: "test sec"},
},
want: time.Duration(0),
},
{
name: "1 sec",
args: args{
timer: Timer{Before: "1 sec"},
},
want: time.Duration(0),
},
{
name: "1 second",
args: args{
timer: Timer{After: "1 second"},
},
want: time.Duration(1000000000),
},
{
name: "10 minutes",
args: args{
timer: Timer{After: "10 minutes"},
},
want: time.Duration(600000000000),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := offsetDuration(&tt.args.timer); got != tt.want {
t.Errorf("offsetDuration() = %v, want %v", got, tt.want)
}
})
}
}
func Test_timeBefore(t *testing.T) {
type args struct {
timer Timer
}
tests := []struct {
name string
args args
want time.Time
}{
{
name: "empty",
args: args{},
want: time.Time{},
},
{
name: "no time",
args: args{
timer: Timer{Before: "test"},
},
want: time.Time{},
},
{
name: "not sec, min",
args: args{
timer: Timer{Before: "test tst"},
},
want: time.Time{},
},
{
name: "not int",
args: args{
timer: Timer{Before: "test sec"},
},
want: time.Time{},
},
{
name: "1 min",
args: args{
timer: Timer{Time: "00:20", Before: "10 min"},
},
want: time.Date(0000, 01, 01, 00, 10, 00, 0, time.UTC),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := timeBefore(&tt.args.timer, tt.args.timer.Time); !reflect.DeepEqual(got, tt.want) {
t.Errorf("timeWithOffset() = %v, want %v", got, tt.want)
}
})
}
}
func Test_offsetDescr(t *testing.T) {
type args struct {
timer Timer
}
tests := []struct {
name string
args args
want string
}{
{
name: "empty",
args: args{},
want: "at",
},
{
name: "no time",
args: args{
timer: Timer{Before: "1 sec"},
},
want: "1 sec before",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := offsetDescr(&tt.args.timer); got != tt.want {
t.Errorf("offsetDescr() = %v, want %v", got, tt.want)
}
})
}
}