...

Source file src/github.com/onsi/gomega/gleak/ignoring_creator_test.go

Documentation: github.com/onsi/gomega/gleak

     1  package gleak
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/onsi/gomega/gleak/goroutine"
     7  
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  func creator() Goroutine {
    13  	ch := make(chan Goroutine)
    14  	go func() {
    15  		ch <- goroutine.Current()
    16  	}()
    17  	return <-ch
    18  }
    19  
    20  var _ = Describe("IgnoringCreator matcher", func() {
    21  
    22  	It("returns an error for an invalid actual", func() {
    23  		m := IgnoringCreator("foo.bar")
    24  		Expect(m.Match(nil)).Error().To(MatchError("IgnoringCreator matcher expects a Goroutine or *Goroutine.  Got:\n    <nil>: nil"))
    25  	})
    26  
    27  	It("matches a creator function by full name", func() {
    28  		type T struct{}
    29  		pkg := reflect.TypeOf(T{}).PkgPath()
    30  		ignore := pkg + ".creator"
    31  		m := IgnoringCreator(ignore)
    32  		g := creator()
    33  		Expect(m.Match(g)).To(BeTrue(), "creator: %v\ntried to ignore: %s",
    34  			g.String(), ignore)
    35  		Expect(m.Match(goroutine.Current())).To(BeFalse())
    36  	})
    37  
    38  	It("matches a toplevel function by prefix", func() {
    39  		type T struct{}
    40  		pkg := reflect.TypeOf(T{}).PkgPath()
    41  		m := IgnoringCreator(pkg + "...")
    42  		g := creator()
    43  		Expect(m.Match(g)).To(BeTrue(), "creator %v", g.String())
    44  		Expect(m.Match(goroutine.Current())).To(BeFalse())
    45  		Expect(m.Match(Goroutine{
    46  			TopFunction: "spanish.inquisition",
    47  		})).To(BeFalse())
    48  	})
    49  
    50  	It("returns failure messages", func() {
    51  		m := IgnoringCreator("foo.bar")
    52  		Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
    53  			"Expected\n    <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto be created by \"foo.bar\""))
    54  		Expect(m.NegatedFailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
    55  			"Expected\n    <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nnot to be created by \"foo.bar\""))
    56  
    57  		m = IgnoringCreator("foo...")
    58  		Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
    59  			"Expected\n    <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto be created by a function with prefix \"foo.\""))
    60  	})
    61  
    62  })
    63  

View as plain text