Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: chore: Reduce commitments acceptance tests execution times #418

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 6 additions & 113 deletions castai/resource_commitments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = <<EOF
Name,Reservation Id,Reservation order Id,Status,Expiration date,Purchase date,Term,Scope,Scope subscription,Scope resource group,Type,Product name,Region,Quantity,Utilization % 1 Day,Utilization % 7 Day,Utilization % 30 Day,Deep link to reservation
test-res-1,3b3de39c-bc44-4d69-be2d-69527dfe9958,630226bb-5170-4b95-90b0-f222757130c1,Succeeded,2050-01-01T00:00:00Z,2023-01-11T00:00:00Z,P3Y,Single subscription,8faa0959-093b-4612-8686-a996ac19db00,All resource groups,VirtualMachines,Standard_D32as_v4,westeurope,3,100,100,100,https://portal.azure.com#resource/providers/microsoft.capacity/reservationOrders/59791a62-264b-4b9f-aa3a-5eeb761e4583/reservations/883afd52-54c8-4bc6-a0f2-ccbaf7b84bda/overview
EOF
}
`)
}

func getCommitmentsConfig3(
gcpServiceAccountID, gcpClusterName, gcpProjectID,
azureRoleName, azureClusterName, azureResourceGroupName, azureNodeResourceGroupName string,
) string {
return ConfigCompose(
testAccGKEClusterConfig(gcpServiceAccountID, gcpClusterName, gcpProjectID),
testAccAKSClusterConfig(azureRoleName, azureClusterName, azureResourceGroupName, azureNodeResourceGroupName),
`
resource "castai_commitments" "test_gcp" {
gcp_cuds_json = <<EOF
[
`+commitment1Obj+`,
`+commitment2Obj+`
]
EOF

commitment_configs {
matcher {
name = "test"
Expand Down Expand Up @@ -520,7 +413,7 @@ test-res-2,3b3de39c-bc44-4d69-be2d-69527dfe9959,630226bb-5170-4b95-90b0-f2227571
`)
}

func getCommitmentsConfig4(serviceAccountID, clusterName, projectID string) string {
func getCommitmentsConfig3(serviceAccountID, clusterName, projectID string) string {
return ConfigCompose(testAccGKEClusterConfig(serviceAccountID, clusterName, projectID), `
provider "azurerm" {
features {}
Expand Down Expand Up @@ -567,7 +460,7 @@ resource "castai_commitments" "test_gcp" {
`)
}

func getCommitmentsConfig5(serviceAccountID, clusterName, projectID string) string {
func getCommitmentsConfig4(serviceAccountID, clusterName, projectID string) string {
return ConfigCompose(testAccGKEClusterConfig(serviceAccountID, clusterName, projectID), `
provider "azurerm" {
features {}
Expand Down
Loading