Skip to content

Commit

Permalink
Tests without waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
kasia-kujawa committed Nov 4, 2024
1 parent 92d30ff commit a3c6716
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test:
.PHONY: testacc
testacc:
@echo "==> Running acceptance tests"
TF_ACC=1 go test ./castai/... '-run=^TestAccResourceRebalancingJob' -v -timeout 10m
TF_ACC=1 go test ./castai/... '-run=^TestAcc' -v -timeout 10m

.PHONY: validate-terraform-examples
validate-terraform-examples:
Expand Down
29 changes: 1 addition & 28 deletions castai/resource_rebalancing_job_eks_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package castai

import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -100,8 +98,7 @@ func TestAccResourceRebalancingJobWithDataSource_eks(t *testing.T) {
),
},
{
PreConfig: func() { waitForRebalancingSchedule(t, rName) },
Config: makeInitialRebalancingJobWithDataSourceConfig(rName, clusterName),
Config: makeInitialRebalancingJobWithDataSourceConfig(rName, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.castai_rebalancing_schedule.data-source-for-rebalancing-schedule", "name", rName),
),
Expand All @@ -116,30 +113,6 @@ func TestAccResourceRebalancingJobWithDataSource_eks(t *testing.T) {
})
}

func waitForRebalancingSchedule(t *testing.T, rebalancingScheduleName string) {
client := testAccProvider.Meta().(*ProviderConfig).api
ctx := context.Background()
timeout := 120 * time.Second // Total wait time
interval := 5 * time.Second // Wait time between checks
startTime := time.Now()

for {
if time.Since(startTime) > timeout {
fmt.Println("Rebalancing schedule was not found, name: ", rebalancingScheduleName)
t.Error("Rebalancing schedule was not found, name: ", rebalancingScheduleName)
return
}

_, err := getRebalancingScheduleByName(ctx, client, rebalancingScheduleName)
if err == nil {
fmt.Println("Rebalancing schedule found, name: ", rebalancingScheduleName)
t.Log("Rebalancing schedule found, name: ", rebalancingScheduleName)
return
}
time.Sleep(interval)
}
}

func makeRebalancingScheduleConfig(rName string) string {
template := `
resource "castai_rebalancing_schedule" "test-with-data-source" {
Expand Down

0 comments on commit a3c6716

Please sign in to comment.