Skip to content

Commit 73e7b94

Browse files
committed
pkg/sanity: support sanity testing in another Ginkgo suite
This was not possible before: - Ginkgo only supports one set of Before/AfterSuite calls, which might be in use already in the existing suite (for example, the Kubernetes e2e framework). - When nesting the sanity test inside a Ginkgo spec there is no testing.T pointer that could be passed to the Test method. Now all global variables are replaced with a test context that gets passed into the specs explicitly. For this to work, specs must be set up with SanityDescribe instead of the previous Describe call. The Test and Config API are unchanged, but there is one slight change of behavior: previously it was possible to define two tests with different configs in the same test binary and then running each test would execute the sanity tests for that config. That no longer works because running one test changes the global Ginkgo suite and running the second test would then also run the specs from the first one. This usage could be supported by having one test function which takes multiple configs, then runs one suite that contains tests for all of them. Probably it is easier to just use a Ginkgo suite, because there multiple different configs can be handled already normally via different Describe specs: calling the new GinkgoTest API will add all sanity test cases for one configuration to the spec in which the API is called.
1 parent 5f55e22 commit 73e7b94

File tree

6 files changed

+289
-181
lines changed

6 files changed

+289
-181
lines changed

pkg/sanity/README.md

+41-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,50 @@ Golang `TestXXX` functions. For example:
1313

1414
```go
1515
func TestMyDriver(t *testing.T) {
16-
// Setup the full driver and its environment
17-
... setup driver ...
16+
// Setup the full driver and its environment
17+
... setup driver ...
18+
config := &sanity.Config{
19+
TargetPath: ...
20+
StagingPath: ...
21+
Address: endpoint,
22+
}
1823

19-
// Now call the test suite
20-
sanity.Test(t, driverEndpointAddress, "/mnt")
24+
25+
// Now call the test suite
26+
sanity.Test(t, config)
2127
}
2228
```
2329

30+
Only one such test function is supported because under the hood a
31+
Ginkgo test suite gets constructed and executed by the call.
32+
33+
Alternatively, the tests can also be embedded inside a Ginkgo test
34+
suite. In that case it is possible to define multiple tests with
35+
different configurations:
36+
37+
```go
38+
var _ = Describe("MyCSIDriver", func () {
39+
Context("Config A", func () {
40+
var config &sanity.Config
41+
42+
BeforeEach() {
43+
... setup driver and config...
44+
}
45+
46+
AfterEach() {
47+
...tear down driver...
48+
}
49+
50+
Describe("CSI sanity", func() {
51+
sanity.GinkgoTest(config)
52+
})
53+
})
54+
55+
Context("Config B", func () {
56+
...
57+
})
58+
})
59+
```
60+
2461
## Command line program
2562
Please see [csi-sanity](https://github.com/kubernetes-csi/csi-test/tree/master/cmd/csi-sanity)

0 commit comments

Comments
 (0)