github.com/onsi/gomega@v1.32.0/gleak/ignoring_in_backtrace.go (about)

     1  package gleak
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/onsi/gomega/format"
     8  	"github.com/onsi/gomega/types"
     9  )
    10  
    11  // IgnoringInBacktrace succeeds if a function name is contained in the backtrace
    12  // of the actual goroutine description.
    13  func IgnoringInBacktrace(fname string) types.GomegaMatcher {
    14  	return &ignoringInBacktraceMatcher{fname: fname}
    15  }
    16  
    17  type ignoringInBacktraceMatcher struct {
    18  	fname string
    19  }
    20  
    21  // Match succeeds if actual's backtrace contains the specified function name.
    22  func (matcher *ignoringInBacktraceMatcher) Match(actual interface{}) (success bool, err error) {
    23  	g, err := G(actual, "IgnoringInBacktrace")
    24  	if err != nil {
    25  		return false, err
    26  	}
    27  	return strings.Contains(g.Backtrace, matcher.fname), nil
    28  }
    29  
    30  // FailureMessage returns a failure message if the actual's backtrace does not
    31  // contain the specified function name.
    32  func (matcher *ignoringInBacktraceMatcher) FailureMessage(actual interface{}) (message string) {
    33  	return format.Message(actual, fmt.Sprintf("to contain %q in the goroutine's backtrace", matcher.fname))
    34  }
    35  
    36  // NegatedFailureMessage returns a failure message if the actual's backtrace
    37  // does contain the specified function name.
    38  func (matcher *ignoringInBacktraceMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    39  	return format.Message(actual, fmt.Sprintf("not to contain %q in the goroutine's backtrace", matcher.fname))
    40  }