github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/testhelpers/matchers/all_requests_called_matcher.go (about) 1 package matchers 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/cloudfoundry/cli/testhelpers/net" 8 "github.com/onsi/gomega" 9 ) 10 11 func HaveAllRequestsCalled() gomega.OmegaMatcher { 12 return &allRequestsCalledMatcher{} 13 } 14 15 type allRequestsCalledMatcher struct { 16 failureMessage string 17 } 18 19 func (matcher *allRequestsCalledMatcher) Match(actual interface{}) (bool, error) { 20 testHandler, ok := actual.(*net.TestHandler) 21 if !ok { 22 return false, errors.New(fmt.Sprintf("Expected a test handler, got %T", actual)) 23 } 24 25 if testHandler.AllRequestsCalled() { 26 matcher.failureMessage = "Expected all requests to not be called, but they were all called" 27 return true, nil 28 } else { 29 message := fmt.Sprint("Failed to call requests:\n") 30 for i := testHandler.CallCount; i < len(testHandler.Requests); i++ { 31 message += fmt.Sprintf("%#v\n", testHandler.Requests[i]) 32 } 33 message += "\n" 34 matcher.failureMessage = message 35 return false, nil 36 } 37 } 38 39 func (matcher *allRequestsCalledMatcher) FailureMessage(actual interface{}) string { 40 return matcher.failureMessage 41 } 42 43 func (matcher *allRequestsCalledMatcher) NegatedFailureMessage(actual interface{}) string { 44 return matcher.failureMessage 45 }