github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/util/testhelpers/matchers/all_requests_called_matcher.go (about)

     1  package matchers
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/cf/util/testhelpers/net"
     7  	"github.com/onsi/gomega"
     8  )
     9  
    10  func HaveAllRequestsCalled() gomega.OmegaMatcher {
    11  	return &allRequestsCalledMatcher{}
    12  }
    13  
    14  type allRequestsCalledMatcher struct {
    15  	failureMessage string
    16  }
    17  
    18  func (matcher *allRequestsCalledMatcher) Match(actual interface{}) (bool, error) {
    19  	testHandler, ok := actual.(*net.TestHandler)
    20  	if !ok {
    21  		return false, fmt.Errorf("Expected a test handler, got %T", actual)
    22  	}
    23  
    24  	if testHandler.AllRequestsCalled() {
    25  		matcher.failureMessage = "Expected all requests to not be called, but they were all called"
    26  		return true, nil
    27  	}
    28  
    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  func (matcher *allRequestsCalledMatcher) FailureMessage(actual interface{}) string {
    39  	return matcher.failureMessage
    40  }
    41  
    42  func (matcher *allRequestsCalledMatcher) NegatedFailureMessage(actual interface{}) string {
    43  	return matcher.failureMessage
    44  }