File: ordered_fixture_suite_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,060 kB
  • sloc: javascript: 59; makefile: 23; sh: 14
file content (75 lines) | stat: -rw-r--r-- 1,840 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
package ordered_fixture_test

import (
	"flag"
	"testing"

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

var noOrdered *bool

func init() {
	noOrdered = flag.CommandLine.Bool("no-ordered", false, "set to turn off ordered decoration")
}

var OrderedDecoration = []interface{}{Ordered}

func TestOrderedFixture(t *testing.T) {
	RegisterFailHandler(Fail)
	if *noOrdered {
		OrderedDecoration = []interface{}{}
	}

	RunSpecs(t, "OrderedFixture Suite")
}

var _ = Describe("tests", func() {
	for i := 0; i < 10; i += 1 {
		Context("ordered", OrderedDecoration, func() {
			var terribleSharedCounter int
			var parallelNode int

			BeforeAll(func() {
				terribleSharedCounter = 1
				parallelNode = GinkgoParallelProcess()
			})

			It("increments the counter", func() {
				Ω(parallelNode).Should(Equal(GinkgoParallelProcess()))
				terribleSharedCounter++
				Ω(terribleSharedCounter).Should(Equal(2))
			})

			It("increments the shared counter", func() {
				Ω(parallelNode).Should(Equal(GinkgoParallelProcess()))
				terribleSharedCounter++
				Ω(terribleSharedCounter).Should(Equal(3))
			})

			It("increments the terrible shared counter", func() {
				Ω(parallelNode).Should(Equal(GinkgoParallelProcess()))
				terribleSharedCounter++
				Ω(terribleSharedCounter).Should(Equal(4))
			})

			It("increments the counter again", func() {
				Ω(parallelNode).Should(Equal(GinkgoParallelProcess()))
				terribleSharedCounter++
				Ω(terribleSharedCounter).Should(Equal(5))
			})

			It("increments the counter and again", func() {
				Ω(parallelNode).Should(Equal(GinkgoParallelProcess()))
				terribleSharedCounter++
				Ω(terribleSharedCounter).Should(Equal(6))
			})

			AfterAll(func() {
				Ω(parallelNode).Should(Equal(GinkgoParallelProcess()))
				Ω(terribleSharedCounter).Should(Equal(6))
			})
		})
	}
})