|
2 | 2 | package test |
3 | 3 |
|
4 | 4 | import ( |
| 5 | + "crypto/rand" |
| 6 | + "encoding/base64" |
5 | 7 | "fmt" |
| 8 | + "log" |
6 | 9 | "testing" |
7 | 10 |
|
8 | 11 | "github.com/stretchr/testify/assert" |
9 | 12 | "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper" |
10 | 13 | ) |
11 | 14 |
|
| 15 | +func TestRunCompleteExample(t *testing.T) { |
| 16 | + t.Parallel() |
| 17 | + |
| 18 | + // Generate a 15 char long random string for the admin_pass |
| 19 | + randomBytes := make([]byte, 13) |
| 20 | + _, err := rand.Read(randomBytes) |
| 21 | + if err != nil { |
| 22 | + log.Fatal(err) |
| 23 | + } |
| 24 | + // add character prefix to avoid generated password beginning with special char and must have a number |
| 25 | + randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13] |
| 26 | + |
| 27 | + options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{ |
| 28 | + Testing: t, |
| 29 | + TerraformDir: completeExampleTerraformDir, |
| 30 | + Prefix: "rabbitmq-upg", |
| 31 | + BestRegionYAMLPath: regionSelectionPath, |
| 32 | + ResourceGroup: resourceGroup, |
| 33 | + TerraformVars: map[string]interface{}{ |
| 34 | + "rabbitmq_version": earliestVersion, // Always lock to the lowest supported RabbitMQ version |
| 35 | + "users": []map[string]interface{}{ |
| 36 | + { |
| 37 | + "name": "testuser", |
| 38 | + "password": randomPass, // pragma: allowlist secret |
| 39 | + "type": "database", |
| 40 | + }, |
| 41 | + }, |
| 42 | + "admin_pass": randomPass, |
| 43 | + }, |
| 44 | + CloudInfoService: sharedInfoSvc, |
| 45 | + }) |
| 46 | + |
| 47 | + output, err := options.RunTestConsistency() |
| 48 | + assert.Nil(t, err, "This should not have errored") |
| 49 | + assert.NotNil(t, output, "Expected some output") |
| 50 | + |
| 51 | + outputs := options.LastTestTerraformOutputs |
| 52 | + expectedOutputs := []string{"port", "hostname"} |
| 53 | + _, outputErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...) |
| 54 | + assert.NoErrorf(t, outputErr, "Some outputs not found or nil") |
| 55 | +} |
| 56 | + |
12 | 57 | func testPlanICDVersions(t *testing.T, version string) { |
13 | 58 | t.Parallel() |
14 | 59 |
|
@@ -45,7 +90,8 @@ func TestRunRestoredDBExample(t *testing.T) { |
45 | 90 | ResourceGroup: resourceGroup, |
46 | 91 | Region: fmt.Sprint(permanentResources["rabbitmqRegion"]), |
47 | 92 | TerraformVars: map[string]interface{}{ |
48 | | - "rabbitmq_db_crn": permanentResources["rabbitmqCrn"], |
| 93 | + "rabbitmq_db_crn": permanentResources["rabbitmqCrn"], |
| 94 | + "rabbitmq_version": permanentResources["rabbitmqVersion"], |
49 | 95 | }, |
50 | 96 | CloudInfoService: sharedInfoSvc, |
51 | 97 | }) |
|
0 commit comments