Skip to content

Commit

Permalink
Cleanup test to skip setup cluster steps if needed (#5945)
Browse files Browse the repository at this point in the history
* add global variables for setupcluster, add parameter in commonbeforeEach for skipping namespace creation

Signed-off-by: anandrkskd <[email protected]>

* update commonbeforeeach in each tests to skip or execute project creation

Signed-off-by: anandrkskd <[email protected]>
  • Loading branch information
anandrkskd authored Jul 15, 2022
1 parent 62f7c61 commit 0b6a166
Show file tree
Hide file tree
Showing 24 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion tests/e2escenarios/e2e-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var _ = Describe("E2E Test", func() {
var commonVar helper.CommonVar
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
})
var _ = AfterEach(func() {
helper.CommonAfterEach(commonVar)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2escenarios/e2e_devfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = Describe("odo devfile supported tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
componentName = helper.RandString(6)
helper.Chdir(commonVar.Context)
projectDirPath = commonVar.Context + projectDir
Expand Down
16 changes: 11 additions & 5 deletions tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ type CommonVar struct {
testDuration float64
}

const SetupClusterTrue = true
const SetupClusterFalse = false

// CommonBeforeEach is common function runs before every test Spec (It)
// returns CommonVar values that are used within the test script
func CommonBeforeEach() CommonVar {
func CommonBeforeEach(setupCluster bool) CommonVar {
SetDefaultEventuallyTimeout(10 * time.Minute)
SetDefaultConsistentlyDuration(30 * time.Second)

Expand All @@ -193,7 +196,9 @@ func CommonBeforeEach() CommonVar {
commonVar.OriginalKubeconfig = os.Getenv("KUBECONFIG")
commonVar.CliRunner = GetCliRunner()
LocalKubeconfigSet(commonVar.ConfigDir)
commonVar.Project = commonVar.CliRunner.CreateAndSetRandNamespaceProject()
if setupCluster {
commonVar.Project = commonVar.CliRunner.CreateAndSetRandNamespaceProject()
}
commonVar.OriginalWorkingDirectory = Getwd()
os.Setenv("GLOBALODOCONFIG", filepath.Join(commonVar.ConfigDir, "preference.yaml"))
// Set ConsentTelemetry to false so that it does not prompt to set a preference value
Expand Down Expand Up @@ -246,9 +251,10 @@ func CommonAfterEach(commonVar CommonVar) {
}
}

// delete the random project/namespace created in CommonBeforeEach
commonVar.CliRunner.DeleteNamespaceProject(commonVar.Project, false)

if commonVar.Project != "" {
// delete the random project/namespace created in CommonBeforeEach
commonVar.CliRunner.DeleteNamespaceProject(commonVar.Project, false)
}
// restores the original kubeconfig and working directory
Chdir(commonVar.OriginalWorkingDirectory)
err = os.Setenv("KUBECONFIG", commonVar.OriginalKubeconfig)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_add_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("odo add binding command tests", func() {
var err error

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
// Ensure that the operators are installed
commonVar.CliRunner.EnsureOperatorIsInstalled("service-binding-operator")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _ = Describe("odo analyze command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterFalse)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("odo delete command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
cmpName = helper.RandString(6)
helper.Chdir(commonVar.Context)
getDeployArgs = []string{"get", "deployment", "-n", commonVar.Project}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_describe_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("odo describe component command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
cmpName = helper.RandString(6)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_describe_list_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("odo describe/list binding command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_dev_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("odo dev debug command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
cmpName = helper.RandString(6)
helper.Chdir(commonVar.Context)
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("odo dev command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
cmpName = helper.RandString(6)
helper.Chdir(commonVar.Context)
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_devfile_build_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ = Describe("odo devfile build-images command tests", func() {
var commonVar helper.CommonVar

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("odo devfile deploy command tests", func() {
var commonVar helper.CommonVar

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var _ = Describe("odo devfile init command tests", func() {
var commonVar helper.CommonVar

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterFalse)
helper.Chdir(commonVar.Context)
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_devfile_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("odo list with devfile", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_devfile_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("odo devfile registry command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterFalse)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("odo logs command tests", func() {
}

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
componentName = helper.RandString(6)
helper.Chdir(commonVar.Context)
Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() {
var commonVar helper.CommonVar

BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
})

AfterEach(func() {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_pref_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("odo preference and config command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterFalse)
})

// Clean up after the test
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_remove_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = Describe("odo remove binding command tests", func() {
var commonVar helper.CommonVar

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
// Note: We do not add any operators here because `odo remove binding` is simply about removing the ServiceBinding from devfile.
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("odo generic", func() {
// This is run before every Spec (It)
var _ = BeforeEach(func() {
oc = helper.NewOcRunner("oc")
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
})

// Clean up after the test
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/interactive_add_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = Describe("odo add binding interactive command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)

// We make EXPLICITLY sure that we are outputting with NO COLOR
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/interactive_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ = Describe("odo deploy interactive command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/interactive_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ = Describe("odo dev interactive command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterTrue)
helper.Chdir(commonVar.Context)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/interactive_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("odo init interactive command tests", func() {

// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
commonVar = helper.CommonBeforeEach(helper.SetupClusterFalse)
helper.Chdir(commonVar.Context)

// We make EXPLICITLY sure that we are outputting with NO COLOR
Expand Down

0 comments on commit 0b6a166

Please sign in to comment.