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

Enable receiving a rest config on TestSuite #348

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
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
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