| 1 |
package expect |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"strings" |
| 6 |
) |
| 7 |
|
| 8 |
var ( |
| 9 |
SuccessHandler = &SuccessPostHandler{} |
| 10 |
) |
| 11 |
|
| 12 |
type PostHandler interface { |
| 13 |
Message(format string, args ...interface{}) |
| 14 |
} |
| 15 |
|
| 16 |
type FailurePostHandler struct { |
| 17 |
expected interface{} |
| 18 |
actual interface{} |
| 19 |
} |
| 20 |
|
| 21 |
func NewFailureHandler(expected, actual interface{}) PostHandler { |
| 22 |
return &FailurePostHandler{expected, actual} |
| 23 |
} |
| 24 |
|
| 25 |
func (h *FailurePostHandler) Message(format string, args ...interface{}) { |
| 26 |
if args == nil { |
| 27 |
s := fmt.Sprintf(format, h.expected, h.actual) |
| 28 |
if strings.Contains(s, "%!(EXTRA") == false { |
| 29 |
runner.ErrorMessage(s) |
| 30 |
return |
| 31 |
} |
| 32 |
} |
| 33 |
runner.ErrorMessage(format, args...) |
| 34 |
} |
| 35 |
|
| 36 |
type SuccessPostHandler struct { |
| 37 |
} |
| 38 |
|
| 39 |
func (h *SuccessPostHandler) Message(format string, args ...interface{}) { |
| 40 |
|
| 41 |
} |