File: util_test.go

package info (click to toggle)
golang-gomega 1.36.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,984 kB
  • sloc: xml: 277; javascript: 59; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gleak

import (
	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

var _ = Describe("utilities", func() {

	Context("G(oroutine) descriptions", func() {

		It("returns an error for actual <nil>", func() {
			Expect(func() { _, _ = G(nil, "foo") }).NotTo(Panic())
			Expect(G(nil, "foo")).Error().To(MatchError("foo matcher expects a Goroutine or *Goroutine.  Got:\n    <nil>: nil"))
		})

		It("returns an error when passing something that's not a goroutine by any means", func() {
			Expect(func() { _, _ = G("foobar", "foo") }).NotTo(Panic())
			Expect(G("foobar", "foo")).Error().To(MatchError("foo matcher expects a Goroutine or *Goroutine.  Got:\n    <string>: foobar"))
		})

		It("returns a goroutine", func() {
			actual := Goroutine{ID: 42}
			g, err := G(actual, "foo")
			Expect(err).NotTo(HaveOccurred())
			Expect(g.ID).To(Equal(uint64(42)))

			g, err = G(&actual, "foo")
			Expect(err).NotTo(HaveOccurred())
			Expect(g.ID).To(Equal(uint64(42)))
		})

	})

	It("returns a list of Goroutine IDs in textual format", func() {
		Expect(goids(nil)).To(BeEmpty())
		Expect(goids([]Goroutine{
			{ID: 666},
			{ID: 42},
		})).To(Equal("42, 666"))
		Expect(goids([]Goroutine{
			{ID: 42},
		})).To(Equal("42"))
	})

})