Skip to content

Commit

Permalink
Enable receiving a rest config on TestSuite (#348)
Browse files Browse the repository at this point in the history
Adds to the options for kuttl start-up.   Now a Rest Config can be provided as part of the kuttl.config for connectivity to a cluster.
Signed-off-by: Ali Felan <alifelan@google.com>
  • Loading branch information
alifelan authored Apr 13, 2022
1 parent 8d4d1f8 commit 769fd23
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/testharness/v1beta1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1beta1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -67,6 +68,8 @@ type TestSuite struct {
Namespace string `json:"namespace"`
// Suppress is used to suppress logs
Suppress []string `json:"suppress"`

Config *rest.Config `json:"config,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
3 changes: 3 additions & 0 deletions pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ func (h *Harness) Config() (*rest.Config, error) {

var err error
switch {
case h.TestSuite.Config != nil:
h.T.Log("running tests with passed rest config.")
h.config = h.TestSuite.Config
case h.TestSuite.StartControlPlane:
h.T.Log("running tests with a mocked control plane (kube-apiserver and etcd).")
h.config, err = h.RunTestEnv()
Expand Down
24 changes: 24 additions & 0 deletions pkg/test/harness_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"

harness "github.com/kudobuilder/kuttl/pkg/apis/testharness/v1beta1"
testutils "github.com/kudobuilder/kuttl/pkg/test/utils"
)

func TestHarnessRunIntegration(t *testing.T) {
Expand All @@ -25,6 +26,29 @@ func TestHarnessRunIntegration(t *testing.T) {
harness.Run()
}

func TestHarnessRunIntegrationWithConfig(t *testing.T) {
testenv, err := testutils.StartTestEnvironment(nil, false)
if err != nil {
t.Fatalf("fatal error starting environment: %s", err)
}
harness := Harness{
TestSuite: harness.TestSuite{
TestDirs: []string{
"./test_data/",
},
// set as true to skip service account check
StartControlPlane: true,
Config: testenv.Config,
CRDDir: "./test_crds/",
},
T: t,
}
harness.Run()
if err := testenv.Environment.Stop(); err != nil {
t.Log("error tearing down mock control plane", err)
}
}

// This test requires external KinD support to run thus is an integration test
func TestRunBackgroundCommands(t *testing.T) {
h := Harness{
Expand Down

0 comments on commit 769fd23

Please sign in to comment.