Skip to content

Commit

Permalink
Add test for rebalancing job with data source for rebalancing schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
kasia-kujawa committed Oct 31, 2024
1 parent c3f8865 commit b036b43
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
73 changes: 72 additions & 1 deletion castai/resource_rebalancing_job_eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package castai

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"testing"
)

func TestAccResourceRebalancingJob_eks(t *testing.T) {
Expand Down Expand Up @@ -47,6 +48,45 @@ func TestAccResourceRebalancingJob_eks(t *testing.T) {
})
}

func TestAccResourceRebalancingJobWithDataSource_eks(t *testing.T) {
rName := fmt.Sprintf("%v-rebalancing-job-with-data-source-%v", ResourcePrefix, acctest.RandString(8))
clusterName := "core-tf-acc"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },

ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: makeInitialRebalancingJobWithDataSourceConfig(rName, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("castai_rebalancing_job.test-with-data-source", "enabled", "true"),
),
},
{
ResourceName: "castai_rebalancing_job.test-with-data-source",
ImportStateIdFunc: func(s *terraform.State) (string, error) {
clusterID := s.RootModule().Resources["castai_eks_cluster.test"].Primary.ID
return fmt.Sprintf("%v/%v", clusterID, rName), nil
},
ImportState: true,
ImportStateVerify: true,
},
{
Config: makeUpdatedRebalancingJobConfig(rName, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("castai_rebalancing_job.test-with-data-source", "enabled", "false"),
),
},
},
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "~> 4.0",
},
},
})
}

func makeRebalancingJobConfig(rName, config string) string {
template := `
resource "castai_rebalancing_schedule" "test" {
Expand Down Expand Up @@ -81,3 +121,34 @@ func makeInitialRebalancingJobConfig(rName, clusterName string) string {
func makeUpdatedRebalancingJobConfig(rName, clusterName string) string {
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), makeRebalancingJobConfig(rName, "enabled=false"))
}

func makeRebalancingJobWithDataSourceConfig(rName, config string) string {
template := `
resource "castai_rebalancing_schedule" "test" {
name = %[1]q
schedule {
cron = "5 4 * * *"
}
trigger_conditions {
savings_percentage = 15.25
}
launch_configuration {
execution_conditions {
enabled = false
achieved_savings_percentage = 0
}
}
}
resource "castai_rebalancing_job" "test-with-data-source" {
cluster_id = castai_eks_cluster.test.id
rebalancing_schedule_id = castai_rebalancing_schedule.test.id
%[2]s
}
`
return fmt.Sprintf(template, rName, config)
}

func makeInitialRebalancingJobWithDataSourceConfig(rName, clusterName string) string {
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), makeRebalancingJobWithDataSourceConfig(rName, ""))
}
3 changes: 3 additions & 0 deletions castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b036b43

Please sign in to comment.