Skip to content

Commit fd7caaa

Browse files
test: add new function getClusterIngress to check the cluster ingress status in pr test (#507)
* tests: expose CheckClusterIngressHealthyDefaultTimeout * fix: update validation * fix: update validation --------- Co-authored-by: Aayush-Abhyarthi <[email protected]>
1 parent eb1eec6 commit fd7caaa

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/pr_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/gruntwork-io/terratest/modules/terraform"
910
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic"
1011

1112
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
@@ -74,14 +75,34 @@ func setupOptions(t *testing.T, prefix string, terraformDir string, ocpVersion s
7475
func TestRunAdvancedExample(t *testing.T) {
7576
t.Parallel()
7677

77-
options := setupOptions(t, "base-ocp-adv", advancedExampleDir, ocpVersion3)
78+
options := setupOptions(t, "base-ocp-adv", advancedExampleDir, ocpVersion2)
79+
options.PostApplyHook = getClusterIngress
7880

7981
output, err := options.RunTestConsistency()
8082

8183
assert.Nil(t, err, "This should not have errored")
8284
assert.NotNil(t, output, "Expected some output")
8385
}
8486

87+
func getClusterIngress(options *testhelper.TestOptions) error {
88+
89+
// Get output of the last apply
90+
outputs, outputErr := terraform.OutputAllE(options.Testing, options.TerraformOptions)
91+
if !assert.NoError(options.Testing, outputErr, "error getting last terraform apply outputs: %s", outputErr) {
92+
return nil
93+
}
94+
95+
// Validate that the "cluster_name" key is present in the outputs
96+
expectedOutputs := []string{"cluster_name"}
97+
_, ValidationErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...)
98+
99+
// Proceed with the cluster ingress health check if "cluster_name" is valid
100+
if assert.NoErrorf(options.Testing, ValidationErr, "Some outputs not found or nil: %s", ValidationErr) {
101+
options.CheckClusterIngressHealthyDefaultTimeout(outputs["cluster_name"].(string))
102+
}
103+
return nil
104+
}
105+
85106
func TestRunUpgradeAdvancedExample(t *testing.T) {
86107
t.Parallel()
87108

0 commit comments

Comments
 (0)