-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhelper_test.go
62 lines (49 loc) · 1.4 KB
/
helper_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
package mtg
import (
"fmt"
"time"
"gopkg.in/jarcoal/httpmock.v1"
)
func NewStringResponderWithHeader(status int, body string, header map[string]string) httpmock.Responder {
resp := httpmock.NewStringResponse(status, body)
for k, v := range header {
resp.Header.Set(k, v)
}
return httpmock.ResponderFromResponse(resp)
}
func ShouldContainCard(actual interface{}, expected ...interface{}) string {
if len(expected) != 1 {
return "Invalid parameters for ShouldContainCard"
}
cards, firstOk := actual.([]*Card)
cardName, secondOk := expected[0].(string)
if !firstOk || !secondOk {
return "Invalid Arguments for ShouldContainCard"
}
for _, card := range cards {
if card.Name == cardName {
return ""
}
}
return fmt.Sprintf("Card %q was not found in %q", cardName, cards)
}
func ShouldBeOn(actual interface{}, expected ...interface{}) string {
if len(expected) != 1 {
return "Invalid parameters for ShouldBeOn"
}
var actualTime time.Time
date, firstOk := actual.(Date)
if firstOk {
actualTime = time.Time(date)
} else {
actualTime, firstOk = actual.(time.Time)
}
expectedTime, secondOk := expected[0].(time.Time)
if !firstOk || !secondOk {
return "ShouldBeOn should be used on date / time values"
}
if actualTime.Before(expectedTime) || actualTime.After(expectedTime) {
return fmt.Sprintf("Expected to happen on %v but happened on %v", expectedTime, actualTime)
}
return ""
}