forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_requests_called_matcher.go
43 lines (36 loc) · 1.09 KB
/
all_requests_called_matcher.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
package net
import (
"errors"
"fmt"
"github.com/onsi/gomega"
)
func HaveAllRequestsCalled() gomega.OmegaMatcher {
return &allRequestsCalledMatcher{}
}
type allRequestsCalledMatcher struct {
failureMessage string
}
func (matcher *allRequestsCalledMatcher) Match(actual interface{}) (bool, error) {
testHandler, ok := actual.(*TestHandler)
if !ok {
return false, errors.New(fmt.Sprintf("Expected a test handler, got %T", actual))
}
if testHandler.AllRequestsCalled() {
matcher.failureMessage = "Expected all requests to not be called, but they were all called"
return true, nil
} else {
message := fmt.Sprint("Failed to call requests:\n")
for i := testHandler.CallCount; i < len(testHandler.Requests); i++ {
message += fmt.Sprintf("%#v\n", testHandler.Requests[i])
}
message += "\n"
matcher.failureMessage = message
return false, nil
}
}
func (matcher *allRequestsCalledMatcher) FailureMessage(actual interface{}) string {
return matcher.failureMessage
}
func (matcher *allRequestsCalledMatcher) NegatedFailureMessage(actual interface{}) string {
return matcher.failureMessage
}