-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtesthelpers_test.go
More file actions
38 lines (29 loc) · 872 Bytes
/
testhelpers_test.go
File metadata and controls
38 lines (29 loc) · 872 Bytes
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
package recurrence
import (
"fmt"
"time"
)
func ShouldHappenOn(actual interface{}, expected ...interface{}) string {
if len(expected) != 1 {
return "Invalid parameters for ShouldHappenOn"
}
actualTime, firstOk := actual.(time.Time)
expectedTime, secondOk := expected[0].(time.Time)
if !firstOk || !secondOk {
return "ShouldHappenOn should be used on time values"
}
if actualTime.Before(expectedTime) || actualTime.After(expectedTime) {
return fmt.Sprintf("Expected to happen on %v but happened on %v", expectedTime, actualTime)
}
return ""
}
func ShouldNotHappen(actual interface{}, expected ...interface{}) string {
actualTime, ok := actual.(time.Time)
if !ok {
return fmt.Sprintf("Expected %v to be a time value", actual)
}
if !actualTime.IsZero() {
return fmt.Sprintf("Time value should be zero but is %v", actualTime)
}
return ""
}