-
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correctly ensure deterministic spec order, even if specs are generate…
…d by iterating over a map
- Loading branch information
Showing
6 changed files
with
178 additions
and
21 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
integration/_fixtures/nondeterministic_fixture/file_a_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nondeterministic_fixture_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
var cheat = func() { | ||
It("in", func() { | ||
|
||
}) | ||
|
||
It("order", func() { | ||
|
||
}) | ||
} | ||
|
||
var _ = Describe("ordered", Ordered, func() { | ||
It("always", func() { | ||
|
||
}) | ||
|
||
It("runs", func() { | ||
|
||
}) | ||
|
||
cheat() | ||
}) |
41 changes: 41 additions & 0 deletions
41
integration/_fixtures/nondeterministic_fixture/file_b_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nondeterministic_fixture_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
var specGenerator = map[string]bool{ | ||
"map-A": true, | ||
"map-B": true, | ||
"map-C": true, | ||
"map-D": true, | ||
"map-E": true, | ||
"map-F": true, | ||
"map-G": true, | ||
"map-H": true, | ||
"map-I": true, | ||
"map-J": true, | ||
} | ||
|
||
var _ = Describe("some tests, that include a test generated by iterating over a map", func() { | ||
Describe("some tests", func() { | ||
It("runs A", func() { | ||
|
||
}) | ||
It("runs B", func() { | ||
|
||
}) | ||
}) | ||
|
||
When("iterating over a map", func() { | ||
for key := range specGenerator { | ||
It("runs "+key, func() { | ||
|
||
}) | ||
} | ||
}) | ||
|
||
It("runs some other tests", func() { | ||
|
||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
integration/_fixtures/nondeterministic_fixture/nondeterministic_fixture_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package nondeterministic_fixture_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/ginkgo/v2/types" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestNondeterministicFixture(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "NondeterministicFixture Suite") | ||
} | ||
|
||
var _ = ReportAfterSuite("ensure all specs ran correctly", func(report types.Report) { | ||
specs := report.SpecReports.WithLeafNodeType(types.NodeTypeIt) | ||
orderedTexts := []string{} | ||
textCounts := map[string]int{} | ||
for _, spec := range specs { | ||
text := spec.FullText() | ||
textCounts[text] += 1 | ||
if strings.HasPrefix(text, "ordered") { | ||
orderedTexts = append(orderedTexts, spec.LeafNodeText) | ||
} | ||
} | ||
|
||
By("ensuring there are no duplicates") | ||
for text, count := range textCounts { | ||
Ω(count).Should(Equal(1), text) | ||
} | ||
|
||
By("ensuring ordered specs are strictly preserved") | ||
Ω(orderedTexts).Should(Equal([]string{"always", "runs", "in", "order"})) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters