Skip to content

Commit 2d3b987

Browse files
akocbekakocbekIBM
andauthored
test: check if hostname and port outputs exist (#267)
Co-authored-by: akocbek@ie.ibm.com <akocbek@ie.ibm.com>
1 parent b51c3a8 commit 2d3b987

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

examples/fscloud/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ output "version" {
1515
description = "Postgresql instance version"
1616
value = module.postgresql_db.version
1717
}
18+
19+
output "hostname" {
20+
description = "Postgresql instance hostname"
21+
value = module.postgresql_db.hostname
22+
}
23+
24+
output "port" {
25+
description = "Postgresql instance port"
26+
value = module.postgresql_db.port
27+
}

tests/pr_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ package test
44
import (
55
"crypto/rand"
66
"encoding/base64"
7-
"github.com/stretchr/testify/assert"
8-
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
9-
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
107
"log"
118
"os"
129
"testing"
10+
11+
"github.com/gruntwork-io/terratest/modules/terraform"
12+
"github.com/stretchr/testify/assert"
13+
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
14+
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
1315
)
1416

1517
// Use existing resource group
@@ -57,10 +59,17 @@ func TestRunFSCloudExample(t *testing.T) {
5759
"pg_version": "14", // Always lock this test into the latest supported Postgres version
5860
},
5961
})
60-
62+
options.SkipTestTearDown = true
6163
output, err := options.RunTestConsistency()
6264
assert.Nil(t, err, "This should not have errored")
6365
assert.NotNil(t, output, "Expected some output")
66+
67+
// check if outputs exist
68+
outputs := terraform.OutputAll(options.Testing, options.TerraformOptions)
69+
expectedOutputs := []string{"port", "hostname"}
70+
_, outputErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...)
71+
assert.NoErrorf(t, outputErr, "Some outputs not found or nil")
72+
options.TestTearDown()
6473
}
6574

6675
func TestRunUpgradeCompleteExample(t *testing.T) {

0 commit comments

Comments
 (0)