github.com/s7techlab/cckit@v0.10.5/testing/gomega/matchers/erroris.go (about)

     1  package matchers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/onsi/gomega/format"
     8  )
     9  
    10  type ErrorIslMatcher struct {
    11  	Expected interface{}
    12  }
    13  
    14  func (matcher *ErrorIslMatcher) Match(actual interface{}) (success bool, err error) {
    15  	if actual == nil && matcher.Expected == nil {
    16  		return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead.  This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
    17  	}
    18  
    19  	// 1.12
    20  	return strings.Contains(
    21  		fmt.Sprintf(`%s`, actual),
    22  		fmt.Sprintf(`%s`, matcher.Expected)), nil
    23  }
    24  
    25  func (matcher *ErrorIslMatcher) FailureMessage(actual interface{}) (message string) {
    26  	return format.Message(actual, "to match error", matcher.Expected)
    27  }
    28  
    29  func (matcher *ErrorIslMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    30  	return format.Message(actual, "not to match error", matcher.Expected)
    31  }