diff --git a/tests/end-to-end-tests/basic_deployment_test.go b/tests/end-to-end-tests/basic_deployment_test.go index 816b5b1..45c5e0a 100644 --- a/tests/end-to-end-tests/basic_deployment_test.go +++ b/tests/end-to-end-tests/basic_deployment_test.go @@ -10,6 +10,9 @@ import ( "github.com/stretchr/testify/assert" ) +/* + * TestBasicDeployment tests a basic deployment of the infrastructure using Terraform using the TF output variables. + */ func TestBasicDeployment(t *testing.T) { terraformFolder := "../../infrastructure" @@ -18,6 +21,8 @@ func TestBasicDeployment(t *testing.T) { vaultRedundancy := "LocallyRedundant" // Setup stage + // ... + test_structure.RunTestStage(t, "setup", func() { terraformOptions := &terraform.Options{ TerraformDir: terraformFolder, @@ -37,6 +42,8 @@ func TestBasicDeployment(t *testing.T) { }) // Validate stage + // ... + test_structure.RunTestStage(t, "validate", func() { terraformOptions := test_structure.LoadTerraformOptions(t, terraformFolder) @@ -55,6 +62,8 @@ func TestBasicDeployment(t *testing.T) { }) // Teardown stage + // ... + test_structure.RunTestStage(t, "teardown", func() { terraformOptions := test_structure.LoadTerraformOptions(t, terraformFolder) diff --git a/tests/end-to-end-tests/full_deployment_test.go b/tests/end-to-end-tests/full_deployment_test.go index 4ccd036..3a3a4a8 100644 --- a/tests/end-to-end-tests/full_deployment_test.go +++ b/tests/end-to-end-tests/full_deployment_test.go @@ -15,6 +15,9 @@ import ( "github.com/stretchr/testify/assert" ) +/* + * TestFullDeployment tests the full deployment of the infrastructure using Terraform. + */ func TestFullDeployment(t *testing.T) { terraformFolder := "../../infrastructure" @@ -23,6 +26,8 @@ func TestFullDeployment(t *testing.T) { vaultRedundancy := "LocallyRedundant" // Setup stage + // ... + test_structure.RunTestStage(t, "setup", func() { terraformOptions := &terraform.Options{ TerraformDir: terraformFolder, @@ -42,6 +47,8 @@ func TestFullDeployment(t *testing.T) { }) // Validate stage + // ... + test_structure.RunTestStage(t, "validate", func() { resourceGroupName := fmt.Sprintf("rg-nhsbackup-%s", vaultName) fullVaultName := fmt.Sprintf("bvault-%s", vaultName) @@ -66,6 +73,8 @@ func TestFullDeployment(t *testing.T) { }) // Teardown stage + // ... + test_structure.RunTestStage(t, "teardown", func() { terraformOptions := test_structure.LoadTerraformOptions(t, terraformFolder) @@ -73,6 +82,9 @@ func TestFullDeployment(t *testing.T) { }) } +/* + * Validates the resource group has been deployed correctly + */ func ValidateResourceGroup(t *testing.T, subscriptionID string, cred *azidentity.ClientSecretCredential, resourceGroupName string, vaultLocation string) { // Create a new resource groups client @@ -90,6 +102,9 @@ func ValidateResourceGroup(t *testing.T, subscriptionID string, assert.Equal(t, vaultLocation, *resp.ResourceGroup.Location, "Resource group location does not match") } +/* + * Validates the backup vault has been deployed correctly + */ func ValidateBackupVault(t *testing.T, subscriptionID string, cred *azidentity.ClientSecretCredential, resourceGroupName string, vaultName string, vaultLocation string) { // Create a new Data Protection Backup Vaults client client, err := armdataprotection.NewBackupVaultsClient(subscriptionID, cred, nil) @@ -109,6 +124,9 @@ func ValidateBackupVault(t *testing.T, subscriptionID string, cred *azidentity.C assert.Equal(t, armdataprotection.StorageSettingStoreTypesVaultStore, *resp.BackupVaultResource.Properties.StorageSettings[0].DatastoreType, "Backup vault datastore type does not match") } +/* + * Validates the backup policies have been deployed correctly + */ func ValidateBackupPolicies(t *testing.T, subscriptionID string, cred *azidentity.ClientSecretCredential, resourceGroupName string, fullVaultName string, vaultName string) { ctx := context.Background() @@ -139,6 +157,9 @@ func ValidateBackupPolicies(t *testing.T, subscriptionID string, cred *azidentit } } +/* + * Validates the blob storage backup policy + */ func ValidateBlobStoragePolicy(t *testing.T, policies []*armdataprotection.BaseBackupPolicyResource, vaultName string) { blobStoragePolicyName := fmt.Sprintf("bkpol-%s-blobstorage", vaultName) blobStoragePolicy := GetBackupPolicyForName(policies, blobStoragePolicyName) @@ -160,7 +181,9 @@ func ValidateBlobStoragePolicy(t *testing.T, policies []*armdataprotection.BaseB assert.Equal(t, "P7D", *deleteOption.Duration, "Expected the blob storage retention period to be P7D") } -// Validates the managed disk backup policy +/* + * Validates the managed disk backup policy + */ func ValidateManagedDiskPolicy(t *testing.T, policies []*armdataprotection.BaseBackupPolicyResource, vaultName string) { managedDiskPolicyName := fmt.Sprintf("bkpol-%s-manageddisk", vaultName) managedDiskPolicy := GetBackupPolicyForName(policies, managedDiskPolicyName) @@ -195,7 +218,9 @@ func ValidateManagedDiskPolicy(t *testing.T, policies []*armdataprotection.BaseB assert.Equal(t, "P7D", *deleteOption.Duration, "Expected the managed disk retention period to be P7D") } -// Gets a backup policy from the provided list for the provided name +/* + * Gets a backup policy from the provided list for the provided name + */ func GetBackupPolicyForName(policies []*armdataprotection.BaseBackupPolicyResource, name string) *armdataprotection.BaseBackupPolicyResource { for _, policy := range policies { if *policy.Name == name { @@ -206,7 +231,9 @@ func GetBackupPolicyForName(policies []*armdataprotection.BaseBackupPolicyResour return nil } -// Gets a backup policy rules from the provided list for the provided name +/* + * Gets a backup policy rules from the provided list for the provided name + */ func GetBackupPolicyRuleForName(policyRules []armdataprotection.BasePolicyRuleClassification, name string) armdataprotection.BasePolicyRuleClassification { for _, policyRule := range policyRules { if *policyRule.GetBasePolicyRule().Name == name { diff --git a/tests/integration-tests/backup_policy.tftest.hcl b/tests/integration-tests/backup_policy.tftest.hcl index 65ce980..d8a1875 100644 --- a/tests/integration-tests/backup_policy.tftest.hcl +++ b/tests/integration-tests/backup_policy.tftest.hcl @@ -19,25 +19,21 @@ run "create_blob_storage_policy" { vault_name = run.setup_tests.vault_name } - # Check that the id is as expected assert { condition = length(module.blob_storage_policy.id) > 0 error_message = "Blob storage policy id not as expected." } - # Check that the name is as expected assert { condition = module.blob_storage_policy.name == "bkpol-${var.vault_name}-blobstorage" error_message = "Blob storage policy name not as expected." } - # Check that the vault id is as expected assert { condition = module.blob_storage_policy.vault_id == azurerm_data_protection_backup_vault.backup_vault.id error_message = "Blob storage policy vault id not as expected." } - # Check that the retention period is as expected assert { condition = module.blob_storage_policy.retention_period == "P7D" error_message = "Blob storage policy retention period not as expected." @@ -55,31 +51,26 @@ run "create_managed_disk_policy" { vault_name = run.setup_tests.vault_name } - # Check that the id is as expected assert { condition = length(module.managed_disk_policy.id) > 0 error_message = "Managed disk policy id not as expected." } - # Check that the name is as expected assert { condition = module.managed_disk_policy.name == "bkpol-${var.vault_name}-manageddisk" error_message = "Managed disk policy name not as expected." } - # Check that the vault id is as expected assert { condition = module.managed_disk_policy.vault_id == azurerm_data_protection_backup_vault.backup_vault.id error_message = "Managed disk policy vault id not as expected." } - # Check that the retention period is as expected assert { condition = module.managed_disk_policy.retention_period == "P7D" error_message = "Managed disk policy retention period not as expected." } - # Check that the backup intervals is as expected assert { condition = can(module.managed_disk_policy.backup_intervals) && length(module.managed_disk_policy.backup_intervals) == 1 && module.managed_disk_policy.backup_intervals[0] == "R/2024-01-01T00:00:00+00:00/P1D" error_message = "Managed disk policy backup intervals not as expected." diff --git a/tests/integration-tests/backup_vault.tftest.hcl b/tests/integration-tests/backup_vault.tftest.hcl index 7802a4c..7c08e36 100644 --- a/tests/integration-tests/backup_vault.tftest.hcl +++ b/tests/integration-tests/backup_vault.tftest.hcl @@ -21,43 +21,36 @@ run "create_backup_vault" { vault_redundancy = "LocallyRedundant" } - # Check that the name is as expected assert { condition = azurerm_data_protection_backup_vault.backup_vault.name == "bvault-${var.vault_name}" error_message = "Backup vault name not as expected." } - # Check that the resource group is as expected assert { condition = azurerm_data_protection_backup_vault.backup_vault.resource_group_name == azurerm_resource_group.resource_group.name error_message = "Resource group not as expected." } - # Check that the location is as expected assert { condition = azurerm_data_protection_backup_vault.backup_vault.location == var.vault_location error_message = "Backup vault location not as expected." } - # Check that the datastore type is as expected assert { condition = azurerm_data_protection_backup_vault.backup_vault.datastore_type == "VaultStore" error_message = "Backup vault datastore type not as expected." } - # Check that the redundancy is as expected assert { condition = azurerm_data_protection_backup_vault.backup_vault.redundancy == var.vault_redundancy error_message = "Backup vault redundancy not as expected." } - # Check that soft delete is as expected assert { condition = azurerm_data_protection_backup_vault.backup_vault.soft_delete == "Off" error_message = "Backup vault soft delete not as expected." } - # Check that identity is as expected assert { condition = length(azurerm_data_protection_backup_vault.backup_vault.identity[0].principal_id) > 0 error_message = "Backup vault identity not as expected." diff --git a/tests/integration-tests/resource_group.tftest.hcl b/tests/integration-tests/resource_group.tftest.hcl index 2449aef..75935a6 100644 --- a/tests/integration-tests/resource_group.tftest.hcl +++ b/tests/integration-tests/resource_group.tftest.hcl @@ -20,13 +20,11 @@ run "create_resource_group" { vault_location = "uksouth" } - # Check that the name is as expected assert { condition = azurerm_resource_group.resource_group.name == "rg-nhsbackup-${var.vault_name}" error_message = "Resource group name not as expected." } - # Check that the location is as expected assert { condition = azurerm_resource_group.resource_group.location == var.vault_location error_message = "Resource group location not as expected."