Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanity: fix nil pointer error for IDGen when using Ginkgo suite #220

Merged
merged 1 commit into from
Sep 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ type Config struct {
// Timeout for the executed commands for path removal.
RemovePathCmdTimeout int

// IDGen is an optional interface for callers to provide a generator for
// valid Volume and Node IDs. Defaults to DefaultIDGenerator which generates
// generic string IDs
// IDGen is an optional interface for callers to provide a
// generator for valid Volume and Node IDs. If unset,
// it will be set to a DefaultIDGenerator instance when
// passing the config to Test or GinkgoTest.
IDGen IDGenerator
}

Expand All @@ -143,6 +144,21 @@ type SanityContext struct {
StagingPath string
}

// newContext sets up sanity testing with a config supplied by the
// user of the sanity package. Ownership of that config is shared
// between the sanity package and the caller.
func newContext(reqConfig *Config) *SanityContext {
// To avoid runtime if checks when using IDGen, a default
// is set here.
if reqConfig.IDGen == nil {
reqConfig.IDGen = &DefaultIDGenerator{}
}

return &SanityContext{
Config: reqConfig,
}
}

// Test will test the CSI driver at the specified address by
// setting up a Ginkgo suite and running it.
func Test(t *testing.T, reqConfig *Config) {
Expand All @@ -158,14 +174,7 @@ func Test(t *testing.T, reqConfig *Config) {
}
}

if reqConfig.IDGen == nil {
reqConfig.IDGen = &DefaultIDGenerator{}
}

sc := &SanityContext{
Config: reqConfig,
}

sc := newContext(reqConfig)
registerTestsInGinkgo(sc)
RegisterFailHandler(Fail)

Expand All @@ -180,11 +189,11 @@ func Test(t *testing.T, reqConfig *Config) {
}
}

// GinkoTest is another entry point for sanity testing: instead of directly
// running tests like Test does, it merely registers the tests. This can
// be used to embed sanity testing in a custom Ginkgo test suite.
func GinkgoTest(reqConfig *Config) {
sc := &SanityContext{
Config: reqConfig,
}

sc := newContext(reqConfig)
registerTestsInGinkgo(sc)
}

Expand Down