Skip to content

Commit

Permalink
[AV 65761] fix cluster accpetance tests (#126)
Browse files Browse the repository at this point in the history
Co-authored-by: aniket-Kumar-c <115682403+aniket-Kumar-c@users.noreply.github.com>
Co-authored-by: matty271828 <65253959+matty271828@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 11, 2023
1 parent 22cc32c commit 7254c41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
58 changes: 28 additions & 30 deletions internal/resources/acceptance_tests/cluster_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"regexp"
"sync"
"testing"
"time"

Expand All @@ -34,6 +35,10 @@ import (
// - Import state testing for the created cluster.
// - Update of the cluster by modifying various fields.
// - Verification of the updated cluster attributes.

var WaitTime time.Duration = time.Second * 10
var mutex sync.Mutex

func TestAccClusterResourceWithOnlyReqFieldAWS(t *testing.T) {
resourceName := "acc_cluster_" + acctest.GenerateRandomResourceName()
resourceReference := "couchbase-capella_cluster." + resourceName
Expand All @@ -46,10 +51,8 @@ func TestAccClusterResourceWithOnlyReqFieldAWS(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(1 * time.Second)
},
Config: testAccClusterResourceConfigWithOnlyReqField(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigWithOnlyReqField(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeAggregateTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", resourceName),
Expand Down Expand Up @@ -177,10 +180,8 @@ func TestAccClusterResourceWithOptionalFieldAWS(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(1 * time.Minute)
},
Config: testAccClusterResourceConfigWithAllField(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigWithAllField(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeAggregateTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", "Terraform Acceptance Test Cluster"),
Expand Down Expand Up @@ -243,10 +244,8 @@ func TestAccClusterResourceAzure(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(2 * time.Minute)
},
Config: testAccClusterResourceConfigAzure(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigAzure(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeAggregateTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", "Terraform Acceptance Test Cluster"),
Expand Down Expand Up @@ -392,10 +391,8 @@ func TestAccClusterResourceGCP(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(3 * time.Minute)
},
Config: testAccClusterResourceConfigGCP(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigGCP(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeAggregateTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", "Terraform Acceptance Test Cluster"),
Expand Down Expand Up @@ -478,9 +475,7 @@ func TestAccClusterResourceWithOptionalFieldAWSInvalidScenario(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(4 * time.Minute)
},
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigWithAllFieldInvalidScenario(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
ExpectError: regexp.MustCompile("gp2, is not valid"),
},
Expand All @@ -502,9 +497,7 @@ func TestAccClusterResourceForGCPWithIOPSFieldPopulatedInvalidScenario(t *testin
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
//time.Sleep(4 * time.Minute)
},
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceForGCPWithIOPSFieldPopulatedInvalidScenarioConfig(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
ExpectError: regexp.MustCompile("Could not create cluster, unexpected error: iops for gcp cluster cannot be"),
},
Expand All @@ -529,10 +522,8 @@ func TestAccClusterResourceWithConfigurationTypeFieldAdded(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(5 * time.Minute)
},
Config: testAccClusterResourceConfigWithConfigurationTypeFieldAdded(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigWithConfigurationTypeFieldAdded(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeAggregateTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", resourceName),
Expand Down Expand Up @@ -586,10 +577,8 @@ func TestAccClusterResourceNotFound(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
PreConfig: func() {
time.Sleep(6 * time.Minute)
},
Config: testAccClusterResourceConfigWithOnlyReqField(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
PreConfig: testAccProjecCreationWaitTime(),
Config: testAccClusterResourceConfigWithOnlyReqField(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", resourceName),
Expand Down Expand Up @@ -1717,3 +1706,12 @@ func testAccExistsClusterResource(resourceReference string) resource.TestCheckFu
return nil
}
}

func testAccProjecCreationWaitTime() func() {
return func() {
mutex.Lock()
WaitTime = WaitTime + time.Second*30
time.Sleep(WaitTime)
mutex.Unlock()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAccUserResource(t *testing.T) {
projectResourceName := "acc_project_" + cfg.GenerateRandomResourceName()
projectResourceReference := "couchbase-capella_project." + projectResourceName

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { cfg.TestAccPreCheck(t) },
ProtoV6ProviderFactories: cfg.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand Down

0 comments on commit 7254c41

Please sign in to comment.