Skip to content

Commit ddf8b3f

Browse files
committed
sanity: support embedding tests multiple time in Ginkgo
When using a sequence of DescribeSanity, RegisterTestsInGinkgo, DescribeSanity, RegisterTestsInGinkgo (i.e. embedding sanity tests in a Ginkgo suite more than once) the first test got registered multiple times, first by the initial RegisterTestsInGinkgo and again in the second RegisterTestsInGinkgo. Not only is this wrong, the locally bound variables also weren't initialized properly by the BeforeEach functions, which could lead to nil pointer accesses.
1 parent 8f687ee commit ddf8b3f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/sanity/sanity.go

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ func Test(t GinkgoTestingT, config TestConfig) {
231231
// GinkgoTest for use when the tests run. Therefore its content can
232232
// still be modified in a BeforeEach. The sanity package itself treats
233233
// it as read-only.
234+
//
235+
// Only tests defined with DescribeSanity after the last invocation with
236+
// GinkgoTest (if there has be one) will be added, i.e. each test only
237+
// gets added at most once.
234238
func GinkgoTest(config *TestConfig) *TestContext {
235239
sc := newTestContext(config)
236240
registerTestsInGinkgo(sc)

pkg/sanity/tests.go

+4
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ func registerTestsInGinkgo(sc *TestContext) {
5353
})
5454
})
5555
}
56+
// Don't register tests more than once! More tests might
57+
// be added later in a different context, followed by
58+
// another registerTestsInGinkgo call.
59+
tests = nil
5660
}

0 commit comments

Comments
 (0)