Skip to content

Commit 3aa7d6d

Browse files
committed
Fixed alert_configurations test
1 parent 189b6c3 commit 3aa7d6d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mongodbatlas/data_source_mongodbatlas_alert_configurations_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"strconv"
78
"testing"
89

910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -22,7 +23,7 @@ func TestAccConfigDSAlertConfigurations_basic(t *testing.T) {
2223
ProviderFactories: testAccProviderFactories,
2324
Steps: []resource.TestStep{
2425
{
25-
Config: testAccDSMongoDBAtlasAlertConfiguration(projectID),
26+
Config: testAccDSMongoDBAtlasAlertConfigurations(projectID),
2627
Check: resource.ComposeTestCheckFunc(
2728
testAccCheckMongoDBAtlasAlertConfigurationsCount(dataSourceName),
2829
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
@@ -70,8 +71,16 @@ func testAccCheckMongoDBAtlasAlertConfigurationsCount(resourceName string) resou
7071
return fmt.Errorf("the Alert Configurations List for project (%s) could not be read", projectID)
7172
}
7273

73-
if len(rs.Primary.Attributes["results"]) != len(alertResp) {
74-
return fmt.Errorf("%s results count did not match that of current Alert Configurations", resourceName)
74+
resultsNumber := rs.Primary.Attributes["results.#"]
75+
var dataSourceResultsCount int
76+
77+
if dataSourceResultsCount, err = strconv.Atoi(resultsNumber); err != nil {
78+
return fmt.Errorf("%s results count is somehow not a number %s", resourceName, resultsNumber)
79+
}
80+
81+
apiResultsCount := len(alertResp)
82+
if dataSourceResultsCount != len(alertResp) {
83+
return fmt.Errorf("%s results count (%v) did not match that of current Alert Configurations (%d)", resourceName, dataSourceResultsCount, apiResultsCount)
7584
}
7685

7786
return nil

0 commit comments

Comments
 (0)