From 0d48034a228c8a360814eb63a13e7cd8e4007b11 Mon Sep 17 00:00:00 2001 From: dishankkalra23 Date: Mon, 2 Sep 2024 14:49:12 +0530 Subject: [PATCH 1/3] tests: expose CheckClusterIngressHealthyDefaultTimeout --- tests/pr_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/pr_test.go b/tests/pr_test.go index ccda8015..1d2d1134 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + "github.com/gruntwork-io/terratest/modules/terraform" "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic" "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common" @@ -69,6 +70,7 @@ func TestRunAdvancedExample(t *testing.T) { t.Parallel() options := setupOptions(t, "base-ocp-adv", advancedExampleDir, ocpVersion2) + options.PostApplyHook = getClusterIngress output, err := options.RunTestConsistency() @@ -76,6 +78,16 @@ func TestRunAdvancedExample(t *testing.T) { assert.NotNil(t, output, "Expected some output") } +func getClusterIngress(options *testhelper.TestOptions) error { + + // get output of last apply + outputs, outputErr := terraform.OutputAllE(options.Testing, options.TerraformOptions) + if assert.NoErrorf(options.Testing, outputErr, "error getting last terraform apply outputs: %s", outputErr) { + options.CheckClusterIngressHealthyDefaultTimeout(outputs["cluster_name"].(string)) + } + return nil +} + func TestRunUpgradeAdvancedExample(t *testing.T) { t.Parallel() From 8348053f541209dbfc0a2774067ca6dcdb81218d Mon Sep 17 00:00:00 2001 From: dishankkalra23 Date: Fri, 13 Sep 2024 14:45:35 +0530 Subject: [PATCH 2/3] fix: update validation --- tests/pr_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index 2c7fe56a..f93e873f 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -83,9 +83,18 @@ func TestRunAdvancedExample(t *testing.T) { func getClusterIngress(options *testhelper.TestOptions) error { - // get output of last apply + // Get output of the last apply outputs, outputErr := terraform.OutputAllE(options.Testing, options.TerraformOptions) - if assert.NoErrorf(options.Testing, outputErr, "error getting last terraform apply outputs: %s", outputErr) { + if assert.Error(options.Testing, outputErr, "error getting last terraform apply outputs: %s", outputErr) { + return nil + } + + // Validate that the "cluster_name" key is present in the outputs + expectedOutputs := []string{"cluster_name"} + _, ValidationErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...) + + // Proceed with the cluster ingress health check if "cluster_name" is valid + if assert.NoErrorf(options.Testing, ValidationErr, "Some outputs not found or nil: %s", ValidationErr) { options.CheckClusterIngressHealthyDefaultTimeout(outputs["cluster_name"].(string)) } return nil From 552bae695f703a221a3cd7f6508e855575a290a9 Mon Sep 17 00:00:00 2001 From: dishankkalra23 Date: Wed, 25 Sep 2024 04:09:43 +0530 Subject: [PATCH 3/3] fix: update validation --- tests/pr_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index 48b75d31..05d0e085 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -88,7 +88,7 @@ func getClusterIngress(options *testhelper.TestOptions) error { // Get output of the last apply outputs, outputErr := terraform.OutputAllE(options.Testing, options.TerraformOptions) - if assert.Error(options.Testing, outputErr, "error getting last terraform apply outputs: %s", outputErr) { + if !assert.NoError(options.Testing, outputErr, "error getting last terraform apply outputs: %s", outputErr) { return nil }