...

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

Documentation: github.com/onsi/gomega/gleak

     1  package gleak
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo/v2"
     5  	. "github.com/onsi/gomega"
     6  )
     7  
     8  var _ = Describe("IgnoringTopFunction matcher", func() {
     9  
    10  	It("returns an error for an invalid actual", func() {
    11  		m := IgnoringTopFunction("foo.bar")
    12  		Expect(m.Match(nil)).Error().To(MatchError("IgnoringTopFunction matcher expects a Goroutine or *Goroutine.  Got:\n    <nil>: nil"))
    13  	})
    14  
    15  	It("matches a toplevel function by full name", func() {
    16  		m := IgnoringTopFunction("foo.bar")
    17  		Expect(m.Match(Goroutine{
    18  			TopFunction: "foo.bar",
    19  		})).To(BeTrue())
    20  		Expect(m.Match(Goroutine{
    21  			TopFunction: "main.main",
    22  		})).To(BeFalse())
    23  	})
    24  
    25  	It("matches a toplevel function by prefix", func() {
    26  		m := IgnoringTopFunction("foo...")
    27  		Expect(m.Match(Goroutine{
    28  			TopFunction: "foo.bar",
    29  		})).To(BeTrue())
    30  		Expect(m.Match(Goroutine{
    31  			TopFunction: "foo",
    32  		})).To(BeFalse())
    33  		Expect(m.Match(Goroutine{
    34  			TopFunction: "spanish.inquisition",
    35  		})).To(BeFalse())
    36  	})
    37  
    38  	It("matches a toplevel function by name and state prefix", func() {
    39  		m := IgnoringTopFunction("foo.bar [worried]")
    40  		Expect(m.Match(Goroutine{
    41  			TopFunction: "foo.bar",
    42  			State:       "worried, stalled",
    43  		})).To(BeTrue())
    44  		Expect(m.Match(Goroutine{
    45  			TopFunction: "foo.bar",
    46  			State:       "uneasy, anxious",
    47  		})).To(BeFalse())
    48  	})
    49  
    50  	It("returns failure messages", func() {
    51  		m := IgnoringTopFunction("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 have the topmost function \"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 have the topmost function \"foo.bar\""))
    56  
    57  		m = IgnoringTopFunction("foo.bar [worried]")
    58  		Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
    59  			"Expected\n    <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto have the topmost function \"foo.bar\" and the state \"worried\""))
    60  
    61  		m = IgnoringTopFunction("foo...")
    62  		Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
    63  			"Expected\n    <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto have the prefix \"foo.\" for its topmost function"))
    64  	})
    65  
    66  })
    67  

View as plain text