From 18aff3746098fea5dd51ef65ef83b940f361fe52 Mon Sep 17 00:00:00 2001 From: Matt White <16320656+matt-FFFFFF@users.noreply.github.com> Date: Tue, 28 Nov 2023 20:17:32 +0000 Subject: [PATCH] test: update tests --- tests/subscription/subscription_test.go | 46 ++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/subscription/subscription_test.go b/tests/subscription/subscription_test.go index df4c258d..cbb77460 100644 --- a/tests/subscription/subscription_test.go +++ b/tests/subscription/subscription_test.go @@ -90,7 +90,19 @@ func TestSubscriptionAliasCreateValidWithManagementGroupAzApi(t *testing.T) { require.NoError(t, err) defer test.Cleanup() - check.InPlan(test.PlanStruct).NumberOfResourcesEquals(1).ErrorIsNil(t) + resources := []string{ + "azapi_resource.subscription[0]", + "azapi_resource_action.subscription_rename[0]", + "azapi_update_resource.subscription_tags[0]", + "azurerm_management_group_subscription_association.this[0]", + } + + check.InPlan(test.PlanStruct).NumberOfResourcesEquals(len(resources)).ErrorIsNil(t) + + for _, res := range resources { + check.InPlan(test.PlanStruct).That(res).Exists().ErrorIsNil(t) + } + check.InPlan(test.PlanStruct).That("azapi_resource.subscription[0]").Key("name").HasValue(v["subscription_alias_name"]).ErrorIsNil(t) check.InPlan(test.PlanStruct).That("azapi_resource.subscription[0]").Key("body").Query("properties.billingScope").HasValue(v["subscription_billing_scope"]).ErrorIsNil(t) check.InPlan(test.PlanStruct).That("azapi_resource.subscription[0]").Key("body").Query("properties.workload").HasValue(v["subscription_workload"]).ErrorIsNil(t) @@ -121,6 +133,38 @@ func TestSubscriptionExistingWithManagementGroup(t *testing.T) { check.InPlan(test.PlanStruct).That("azurerm_management_group_subscription_association.this[0]").Key("management_group_id").HasValue(mgResId).ErrorIsNil(t) } +// TestSubscriptionExistingWithManagementGroup tests the +// validation functions with an existing subscription id, including a destination management group, +// then creates a plan and compares the input variables to the planned values. +func TestSubscriptionExistingWithManagementGroupAndUpdateExisting(t *testing.T) { + t.Parallel() + + v := getMockInputVariables() + v["subscription_management_group_id"] = "testdeploy" + v["subscription_management_group_association_enabled"] = true + v["subscription_alias_enabled"] = false + v["subscription_id"] = "00000000-0000-0000-0000-000000000000" + v["subscription_update_existing"] = true + test, err := setuptest.Dirs(moduleDir, "").WithVars(v).InitPlanShowWithPrepFunc(t, utils.AzureRmAndRequiredProviders) + require.NoError(t, err) + defer test.Cleanup() + + resources := []string{ + "azapi_resource_action.subscription_rename[0]", + "azapi_update_resource.subscription_tags[0]", + "azurerm_management_group_subscription_association.this[0]", + } + + check.InPlan(test.PlanStruct).NumberOfResourcesEquals(len(resources)).ErrorIsNil(t) + + for _, res := range resources { + check.InPlan(test.PlanStruct).That(res).Exists().ErrorIsNil(t) + } + + mgResId := "/providers/Microsoft.Management/managementGroups/" + v["subscription_management_group_id"].(string) + check.InPlan(test.PlanStruct).That("azurerm_management_group_subscription_association.this[0]").Key("management_group_id").HasValue(mgResId).ErrorIsNil(t) +} + // TestSubscriptionAliasCreateInvalidBillingScope tests the validation function of the subscription_billing_scope variable. func TestSubscriptionAliasCreateInvalidBillingScope(t *testing.T) { t.Parallel()