...

Source file src/github.com/onsi/gomega/matchers/succeed_matcher.go

Documentation: github.com/onsi/gomega/matchers

     1  package matchers
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/onsi/gomega/format"
     8  )
     9  
    10  type formattedGomegaError interface {
    11  	FormattedGomegaError() string
    12  }
    13  
    14  type SucceedMatcher struct {
    15  }
    16  
    17  func (matcher *SucceedMatcher) Match(actual interface{}) (success bool, err error) {
    18  	// is purely nil?
    19  	if actual == nil {
    20  		return true, nil
    21  	}
    22  
    23  	// must be an 'error' type
    24  	if !isError(actual) {
    25  		return false, fmt.Errorf("Expected an error-type.  Got:\n%s", format.Object(actual, 1))
    26  	}
    27  
    28  	// must be nil (or a pointer to a nil)
    29  	return isNil(actual), nil
    30  }
    31  
    32  func (matcher *SucceedMatcher) FailureMessage(actual interface{}) (message string) {
    33  	var fgErr formattedGomegaError
    34  	if errors.As(actual.(error), &fgErr) {
    35  		return fgErr.FormattedGomegaError()
    36  	}
    37  	return fmt.Sprintf("Expected success, but got an error:\n%s", format.Object(actual, 1))
    38  }
    39  
    40  func (matcher *SucceedMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    41  	return "Expected failure, but got no error."
    42  }
    43  

View as plain text