From 2bba35ae13dbc83313445091e6738d97e9258f12 Mon Sep 17 00:00:00 2001 From: Max Twardowski Date: Fri, 8 Nov 2024 12:30:08 +0100 Subject: [PATCH] shrink two steps of commitment acceptance tests into one --- castai/resource_commitments_test.go | 119 ++-------------------------- 1 file changed, 6 insertions(+), 113 deletions(-) diff --git a/castai/resource_commitments_test.go b/castai/resource_commitments_test.go index 6c21e3ff..830d0a6c 100644 --- a/castai/resource_commitments_test.go +++ b/castai/resource_commitments_test.go @@ -108,7 +108,7 @@ func TestAccCommitments(t *testing.T) { }, importCUDsStateStep, importReservationsStateStep, - { // Add config to the first GCP CUD, add another GCP CUD, Azure reservation remains unchanged + { // Add config to the first GCP CUD and Azure RI + add another GCP CUD and Azure RI Config: getCommitmentsConfig2(gcpServiceAccountID, gkeClusterName, gcpProjectID, azureRoleName, azureClusterName, azureResourceGroupName, azureNodeResourceGroupName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.#", "2"), @@ -126,63 +126,9 @@ func TestAccCommitments(t *testing.T) { resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.prioritization", "false"), checkFloatAttr("castai_commitments.test_gcp", "gcp_cuds.0.allowed_usage", 1), resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.status", "Active"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.assignments.#", "0"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.scaling_strategy", "Default"), - // GCP - "test-2" CUD, added in the update with config - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.cud_id", "987654321"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.cud_status", "ACTIVE"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.start_timestamp", "2023-06-01T00:00:00Z"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.end_timestamp", "2024-06-01T00:00:00Z"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.name", "test-2"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.region", "us-central1"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.cpu", "5"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.memory_mb", "10240"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.plan", "TWELVE_MONTH"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.type", "GENERAL_PURPOSE_E2"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.prioritization", "true"), - checkFloatAttr("castai_commitments.test_gcp", "gcp_cuds.1.allowed_usage", 0.7), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.status", "Active"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.assignments.#", "1"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.scaling_strategy", "CPUBased"), - // Azure - unchanged - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.#", "1"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.reservation_id", "3b3de39c-bc44-4d69-be2d-69527dfe9958"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.reservation_status", "Succeeded"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.start_timestamp", "2023-01-11T00:00:00Z"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.end_timestamp", "2050-01-01T00:00:00Z"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.name", "test-res-1"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.region", "westeurope"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.plan", "THREE_YEAR"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.instance_type", "Standard_D32as_v4"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.count", "3"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.scope", "Single subscription"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.scope_subscription", "8faa0959-093b-4612-8686-a996ac19db00"), - resource.TestCheckResourceAttr("castai_commitments.test_azure", "azure_reservations.0.scope_resource_group", "All resource groups"), - ), - }, - importCUDsStateStep, - importReservationsStateStep, - { // CUDs are unchanged, add config to the first Azure reservation and add another Azure reservation - Config: getCommitmentsConfig3(gcpServiceAccountID, gkeClusterName, gcpProjectID, azureRoleName, azureClusterName, azureResourceGroupName, azureNodeResourceGroupName), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.#", "2"), - // GCP - "test" CUD, unchanged - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.cud_id", "123456789"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.cud_status", "ACTIVE"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.start_timestamp", "2023-01-01T00:00:00Z"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.end_timestamp", "2024-01-01T00:00:00Z"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.name", "test"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.region", "us-central1"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.cpu", "10"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.memory_mb", "20480"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.plan", "TWELVE_MONTH"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.type", "COMPUTE_OPTIMIZED_C2D"), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.prioritization", "false"), - checkFloatAttr("castai_commitments.test_gcp", "gcp_cuds.0.allowed_usage", 1), - resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.status", "Active"), resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.assignments.#", "1"), resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.0.scaling_strategy", "Default"), - // GCP - "test-2" CUD, unchanged + // GCP - "test-2" CUD, added in the update with config resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.cud_id", "987654321"), resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.cud_status", "ACTIVE"), resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.1.start_timestamp", "2023-06-01T00:00:00Z"), @@ -239,7 +185,7 @@ func TestAccCommitments(t *testing.T) { importCUDsStateStep, importReservationsStateStep, { // CUDs are unchanged, destroy the Azure import - Config: getCommitmentsConfig4(gcpServiceAccountID, gkeClusterName, gcpProjectID), + Config: getCommitmentsConfig3(gcpServiceAccountID, gkeClusterName, gcpProjectID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.#", "2"), // GCP - "test" CUD, unchanged @@ -278,7 +224,7 @@ func TestAccCommitments(t *testing.T) { }, importCUDsStateStep, { // Remove the first GCP CUD so that the second one remains - Config: getCommitmentsConfig5(gcpServiceAccountID, gkeClusterName, gcpProjectID), + Config: getCommitmentsConfig4(gcpServiceAccountID, gkeClusterName, gcpProjectID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("castai_commitments.test_gcp", "gcp_cuds.#", "1"), // GCP - "test-2" CUD, unchanged @@ -396,59 +342,6 @@ resource "castai_commitments" "test_gcp" { ] EOF - commitment_configs { - matcher { - name = "test" - type = "COMPUTE_OPTIMIZED_C2D" - region = "us-central1" - } - prioritization = false - allowed_usage = 1 - status = "Active" - scaling_strategy = "Default" - } - - commitment_configs { - matcher { - name = "test-2" - type = "GENERAL_PURPOSE_E2" - region = "us-central1" - } - prioritization = true - allowed_usage = 0.7 - status = "Active" - assignments { - cluster_id = castai_gke_cluster.test.id - } - scaling_strategy = "CPUBased" - } -} - -resource "castai_commitments" "test_azure" { - azure_reservations_csv = <