File: report_entries_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (99 lines) | stat: -rw-r--r-- 3,152 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package internal_integration_test

import (
	"fmt"
	"time"

	. "github.com/onsi/ginkgo/v2"
	"github.com/onsi/ginkgo/v2/types"
	. "github.com/onsi/gomega"
)

var _ = Describe("ReportEntries", func() {
	Context("happy path", func() {
		BeforeEach(func() {
			success, _ := RunFixture("Report Entries", func() {
				BeforeSuite(func() {
					AddReportEntry("bridge", "engaged")
				})

				It("adds-entries", func() {
					AddReportEntry("medical", "healthy")
					AddReportEntry("engineering", "on fire")
				})

				It("adds-no-entries", func() {})
			})
			Ω(success).Should(BeTrue())
		})

		It("attaches entries to the report", func() {
			Ω(reporter.Did.Find("adds-entries").ReportEntries[0].Name).Should(Equal("medical"))
			Ω(reporter.Did.Find("adds-entries").ReportEntries[0].Value.String()).Should(Equal("healthy"))
			Ω(reporter.Did.Find("adds-entries").ReportEntries[1].Name).Should(Equal("engineering"))
			Ω(reporter.Did.Find("adds-entries").ReportEntries[1].Value.String()).Should(Equal("on fire"))
			Ω(reporter.Did.Find("adds-no-entries").ReportEntries).Should(BeEmpty())
			Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).ReportEntries[0].Name).Should(Equal("bridge"))
			Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).ReportEntries[0].Value.String()).Should(Equal("engaged"))
		})

		It("also emits report", func() {
			Ω(reporter.ReportEntries).Should(HaveLen(3))
			Ω(reporter.ReportEntries[0].Name).Should(Equal("bridge"))
			Ω(reporter.ReportEntries[1].Name).Should(Equal("medical"))
			Ω(reporter.ReportEntries[2].Name).Should(Equal("engineering"))
		})
	})

	Context("avoiding races", func() {
		BeforeEach(func() {
			success, _ := RunFixture("Report Entries - but no races", func() {
				BeforeEach(func() {
					stop := make(chan interface{})
					done := make(chan interface{})
					ticker := time.NewTicker(10 * time.Millisecond)
					i := 0
					go func() {
						for {
							select {
							case <-ticker.C:
								AddReportEntry(fmt.Sprintf("report-%d", i))
								i++
							case <-stop:
								ticker.Stop()
								close(done)
								return
							}
						}
					}()
					DeferCleanup(func() {
						close(stop)
						<-done
					})
				})

				It("reporter", func() {
					for i := 0; i < 5; i++ {
						time.Sleep(20 * time.Millisecond)
						AddReportEntry(fmt.Sprintf("waiting... %d", i))
						Ω(len(CurrentSpecReport().ReportEntries)).Should(BeNumerically("<", (i+1)*10))
					}
				})

				ReportAfterEach(func(report SpecReport) {
					//no races here, either
					Ω(len(report.ReportEntries)).Should(BeNumerically(">", 5))
				})

			})
			Ω(success).Should(BeTrue())
		})

		It("attaches entries without racing", func() {
			Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "report-0")))
			Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "report-2")))
			Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "waiting... 1")))
			Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "waiting... 3")))
		})
	})
})