Skip to content

Commit 8e8cadb

Browse files
jor2Jordan-Williams2
andauthored
test: use schematics for admin pass (#202)
Co-authored-by: Jordan-Williams2 <[email protected]>
1 parent 1a85668 commit 8e8cadb

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/pr_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
165165
{Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"},
166166
{Name: "service_credential_secrets", Value: serviceCredentialSecrets, DataType: "list(object)"},
167167
{Name: "service_credential_names", Value: string(serviceCredentialNamesJSON), DataType: "map(string)"},
168+
{Name: "admin_pass", Value: GetRandomAdminPassword(t), DataType: "string"},
168169
}
169170
err = options.RunSchematicTest()
170171
assert.Nil(t, err, "This should not have errored")
@@ -181,20 +182,12 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
181182
ResourceGroup: resourceGroup,
182183
})
183184

184-
// Generate a 15 char long random string for the admin_pass
185-
randomBytes := make([]byte, 13)
186-
_, randErr := rand.Read(randomBytes)
187-
require.Nil(t, randErr) // do not proceed if we can't gen a random password
188-
189-
randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]
190-
191185
options.TerraformVars = map[string]interface{}{
192186
"access_tags": permanentResources["accessTags"],
193187
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
194188
"kms_endpoint_type": "public",
195189
"provider_visibility": "public",
196190
"resource_group_name": options.Prefix,
197-
"admin_pass": randomPass,
198191
}
199192

200193
output, err := options.RunTestUpgrade()
@@ -229,7 +222,6 @@ func TestRunUpgradeCompleteExample(t *testing.T) {
229222
"type": "database",
230223
},
231224
},
232-
"admin_pass": randomPass,
233225
},
234226
ImplicitDestroy: []string{
235227
"module.mysql_db.time_sleep.wait_for_authorization_policy",
@@ -243,3 +235,12 @@ func TestRunUpgradeCompleteExample(t *testing.T) {
243235
assert.NotNil(t, output, "Expected some output")
244236
}
245237
}
238+
239+
func GetRandomAdminPassword(t *testing.T) string {
240+
// Generate a 15 char long random string for the admin_pass
241+
randomBytes := make([]byte, 13)
242+
_, randErr := rand.Read(randomBytes)
243+
require.Nil(t, randErr) // do not proceed if we can't gen a random password
244+
randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]
245+
return randomPass
246+
}

0 commit comments

Comments
 (0)