Skip to content

Commit 4c2bce0

Browse files
committed
sanity: support embedding tests multiple time in Ginkgo, II
This reverts commit ddf8b3f. It was meant to enable the call sequence DescribeSanity, RegisterTestsInGinkgo, DescribeSanity, RegisterTestsInGinkgo, but that call sequence is invalid: DescribeSanity must be called during the init phase, then RegisterTestsInGinkgo may be called multiple times with different configs. That usage got broken by the commit above because the second RegisterTestsInGinkgo then didn't add any of the tests defined by the sanity package. Users who want to add their own sanity tests can do it like this: Describe( ... func() { config := &sanity.TestConfig{...} Describe(..., func() { sc := NewTestContext(config) BeforeEach(func() { sc.Setup() }) AfterEach(func() { sc.Teardown() }) Describe(..., func() { ... }) }) sanity.GinkgoTest(config) }) NewTestContext must be made public for this to work. Otherwise TestContext has be initialized manually, which isn't as nice.
1 parent ddf8b3f commit 4c2bce0

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

pkg/sanity/sanity.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ func NewTestConfig() TestConfig {
200200
}
201201
}
202202

203-
// newContext sets up sanity testing with a config supplied by the
203+
// NewContext sets up sanity testing with a config supplied by the
204204
// user of the sanity package. Ownership of that config is shared
205205
// between the sanity package and the caller.
206-
func newTestContext(config *TestConfig) *TestContext {
206+
func NewTestContext(config *TestConfig) *TestContext {
207207
return &TestContext{
208208
Config: config,
209209
}
@@ -231,10 +231,6 @@ 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.
238234
func GinkgoTest(config *TestConfig) *TestContext {
239235
sc := newTestContext(config)
240236
registerTestsInGinkgo(sc)

pkg/sanity/tests.go

-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,4 @@ 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
6056
}

0 commit comments

Comments
 (0)