Skip to content

Commit

Permalink
Support specifying many manifest directories to install in test harne…
Browse files Browse the repository at this point in the history
…ss. (#572)

* Support specifying many manifest directories to install in test harness.

* Drop --manifests-dirs in favor of making --manifests-dir a string slice.
  • Loading branch information
jbarrick-mesosphere committed Jul 22, 2019
1 parent 2d7474f commit ff154a8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
2 changes: 2 additions & 0 deletions keps/0008-operator-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ type TestSuite struct {
CRDDir string
// Path to manifests to install before running tests.
ManifestsDir string
// Paths to manifests to install before running tests.
ManifestsDirs []string `json:"manifestsDirs"`
// Directories containing test cases to run.
TestDirs []string
// Whether or not to start a local etcd and kubernetes API server for the tests (cannot be set with StartKIND
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/kudo/v1alpha1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type TestSuite struct {
CRDDir string `json:"crdDir"`
// Path to manifests to install before running tests.
ManifestsDir string `json:"manifestsDir"`
// Paths to manifests to install before running tests.
ManifestsDirs []string `json:"manifestsDirs"`
// Directories containing test cases to run.
TestDirs []string `json:"testDirs"`
// Whether or not to start a local etcd and kubernetes API server for the tests.
Expand All @@ -42,6 +44,21 @@ type TestSuite struct {
ArtifactsDir string `json:"artifactsDir"`
}

// GetManifestsDirs returns the proper list of manifest directories to install prior to the tests.
func (t TestSuite) GetManifestsDirs() []string {
manifestsDirs := []string{}

if t.ManifestsDirs != nil {
manifestsDirs = t.ManifestsDirs
}

if t.ManifestsDir != "" {
manifestsDirs = append(manifestsDirs, t.ManifestsDir)
}

return manifestsDirs
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// TestStep settings to apply to a test step.
Expand Down
32 changes: 32 additions & 0 deletions pkg/apis/kudo/v1alpha1/test_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetManifestsDirs(t *testing.T) {
ts := TestSuite{}
assert.Equal(t, []string{}, ts.GetManifestsDirs())

ts = TestSuite{
ManifestsDir: "./hello",
}
assert.Equal(t, []string{"./hello"}, ts.GetManifestsDirs())

ts = TestSuite{
ManifestsDirs: []string{
"./hello",
},
}
assert.Equal(t, []string{"./hello"}, ts.GetManifestsDirs())

ts = TestSuite{
ManifestsDirs: []string{
"./hello",
},
ManifestsDir: "./world",
}
assert.Equal(t, []string{"./hello", "./world"}, ts.GetManifestsDirs())
}
6 changes: 3 additions & 3 deletions pkg/kudoctl/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
func newTestCmd() *cobra.Command {
configPath := ""
crdDir := ""
manifestsDir := ""
manifestsDir := []string{}
testToRun := ""
startControlPlane := false
startKIND := false
Expand Down Expand Up @@ -103,7 +103,7 @@ For more detailed documentation, visit: https://kudo.dev/docs/testing`,
}

if isSet(flags, "manifests-dir") {
options.ManifestsDir = manifestsDir
options.ManifestsDirs = manifestsDir
}

if isSet(flags, "start-control-plane") {
Expand Down Expand Up @@ -175,7 +175,7 @@ For more detailed documentation, visit: https://kudo.dev/docs/testing`,

testCmd.Flags().StringVar(&configPath, "config", "", "Path to file to load test settings from (must not be set with any other arguments).")
testCmd.Flags().StringVar(&crdDir, "crd-dir", "", "Directory to load CustomResourceDefinitions from prior to running the tests.")
testCmd.Flags().StringVar(&manifestsDir, "manifests-dir", "", "A directory containing manifests to apply before running the tests.")
testCmd.Flags().StringSliceVar(&manifestsDir, "manifests-dir", []string{}, "A directory containing manifests to apply before running the tests.")
testCmd.Flags().StringVar(&testToRun, "test", "", "If set, the specific test case to run.")
testCmd.Flags().BoolVar(&startControlPlane, "start-control-plane", false, "Start a local Kubernetes control plane for the tests (requires etcd and kube-apiserver binaries, cannot be used with --start-kind).")
testCmd.Flags().BoolVar(&startKIND, "start-kind", false, "Start a KIND cluster for the tests (cannot be used with --start-control-plane).")
Expand Down
6 changes: 4 additions & 2 deletions pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ func (h *Harness) Run() {
}

// Install required manifests.
if _, err := testutils.InstallManifests(context.TODO(), cl, dClient, h.TestSuite.ManifestsDir); err != nil {
h.T.Fatal(err)
for _, manifestsDir := range h.TestSuite.GetManifestsDirs() {
if _, err := testutils.InstallManifests(context.TODO(), cl, dClient, manifestsDir); err != nil {
h.T.Fatal(err)
}
}

if h.TestSuite.StartKUDO {
Expand Down

0 comments on commit ff154a8

Please sign in to comment.