-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsg.go
47 lines (39 loc) · 1.42 KB
/
msg.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
package testhelpers
import "fmt"
const (
// ERROR MESSAGEs - Used as first argument in Error() call
EM_NEED_ERR = "Should have gotten an error, but didn't"
EM_UN_ERR = "Unexpected Error"
// ERROR STRINGS - embed in
// Could use a VAR block, fmt and %8s, but this is just as easy
ES_EXPECTED = "\nexpected:"
ES_GOT = "\n actual:"
ES_ARGS = "\n args:"
ES_SQL = "\n sql:"
ES_ERR = "\n err:"
ES_VALUE = "\n value:"
ES_JSON = "\n json:"
ES_COUNT = "\n count:"
)
// Supply expected and actual values and a pretty formatted string will be returned that can be passed into t.Error()
func NotEqualMsg(expected, actual interface{}) string {
return fmt.Sprintln(ES_EXPECTED, expected, ES_GOT, actual)
}
// NotEqualMsgDetail will output the expected/actual message with the detailed
// outout of %#v
func NotEqualMsgDetail(expected, actual interface{}) string {
return fmt.Sprintln(ES_EXPECTED, fmt.Sprintf("%#v", expected),
ES_GOT, fmt.Sprintf("%#v", actual))
}
func ValueWasNil(expected interface{}) string {
return NotEqualMsg(expected, "(nil)")
}
// Same as NotEqualMsg, except that the type names will be printed instead
func TypeNotEqualMsg(expected, actual interface{}) string {
eType := TypeName(expected)
aType := TypeName(actual)
return fmt.Sprintln(ES_EXPECTED, eType, ES_GOT, aType)
}
func UnexpectedErrMsg(err string) string {
return fmt.Sprintln(EM_UN_ERR, ES_ERR, err)
}