Skip to content

Commit

Permalink
pkg/sanity: support sanity testing in another Ginkgo suite
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pohly committed Jul 5, 2018
1 parent 5f55e22 commit f325be5
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 181 deletions.
45 changes: 41 additions & 4 deletions pkg/sanity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,50 @@ Golang `TestXXX` functions. For example:

```go
func TestMyDriver(t *testing.T) {
// Setup the full driver and its environment
... setup driver ...
// Setup the full driver and its environment
... setup driver ...
config := &sanity.Config{
TargetPath: ...
StagingPath: ...
Address: endpoint,
}

// Now call the test suite
sanity.Test(t, driverEndpointAddress, "/mnt")

// Now call the test suite
sanity.Test(t, config)
}
```

Only one such test function is supported because under the hood a
Ginkgo test suite gets constructed and executed by the call.

Alternatively, the tests can also be embedded inside a Ginkgo test
suite. In that case it is possible to define multiple tests with
different configurations:

```go
var _ = Describe("MyCSIDriver", func () {
Context("Config A", func () {
var config &sanity.Config

BeforeEach() {
... setup driver and config...
}

AfterEach() {
...tear down driver...
}

Describe("CSI sanity", func() {
sanity.GinkgoTest(config)
})
})

Context("Config B", func () {
...
})
})
```

## Command line program
Please see [csi-sanity](https://github.com/kubernetes-csi/csi-test/tree/master/cmd/csi-sanity)
Loading

0 comments on commit f325be5

Please sign in to comment.