Debian Codegraph @

gleak/ignoring_top_function_test.go

raw
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 m = IgnoringTopFunction("foo.bar(*implementation[...]).baz")
25 Expect(m.Match(Goroutine{
26 TopFunction: "foo.bar(*implementation[...]).baz",
27 })).To(BeTrue())
28 Expect(m.Match(Goroutine{
29 TopFunction: "main.main",
30 })).To(BeFalse())
31 })
32
33 It("matches a toplevel function by prefix", func() {
34 m := IgnoringTopFunction("foo...")
35 Expect(m.Match(Goroutine{
36 TopFunction: "foo.bar",
37 })).To(BeTrue())
38 Expect(m.Match(Goroutine{
39 TopFunction: "foo",
40 })).To(BeFalse())
41 Expect(m.Match(Goroutine{
42 TopFunction: "spanish.inquisition",
43 })).To(BeFalse())
44
45 m = IgnoringTopFunction("foo.bar(*implementation[...])...")
46 Expect(m.Match(Goroutine{
47 TopFunction: "foo.bar(*implementation[...]).baz",
48 })).To(BeTrue())
49 Expect(m.Match(Goroutine{
50 TopFunction: "foo",
51 })).To(BeFalse())
52 Expect(m.Match(Goroutine{
53 TopFunction: "spanish.inquisition",
54 })).To(BeFalse())
55 })
56
57 It("matches a toplevel function by name and state prefix", func() {
58 m := IgnoringTopFunction("foo.bar [worried]")
59 Expect(m.Match(Goroutine{
60 TopFunction: "foo.bar",
61 State: "worried, stalled",
62 })).To(BeTrue())
63 Expect(m.Match(Goroutine{
64 TopFunction: "foo.bar",
65 State: "uneasy, anxious",
66 })).To(BeFalse())
67
68 m = IgnoringTopFunction("foo.bar(*implementation[...]) [worried]")
69 Expect(m.Match(Goroutine{
70 TopFunction: "foo.bar(*implementation[...])",
71 State: "worried, stalled",
72 })).To(BeTrue())
73 Expect(m.Match(Goroutine{
74 TopFunction: "foo.bar(*implementation[...])",
75 State: "uneasy, anxious",
76 })).To(BeFalse())
77 })
78
79 It("returns failure messages", func() {
80 m := IgnoringTopFunction("foo.bar")
81 Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
82 "Expected\n <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto have the topmost function \"foo.bar\""))
83 Expect(m.NegatedFailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
84 "Expected\n <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nnot to have the topmost function \"foo.bar\""))
85
86 m = IgnoringTopFunction("foo.bar [worried]")
87 Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
88 "Expected\n <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto have the topmost function \"foo.bar\" and the state \"worried\""))
89
90 m = IgnoringTopFunction("foo...")
91 Expect(m.FailureMessage(Goroutine{ID: 42, TopFunction: "foo"})).To(Equal(
92 "Expected\n <goroutine.Goroutine>: {ID: 42, State: \"\", TopFunction: \"foo\", CreatorFunction: \"\", BornAt: \"\"}\nto have the prefix \"foo.\" for its topmost function"))
93 })
94
95 })