Skip to content

Commit

Permalink
add local function atleast50 and fix build_error_count to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
bwJuniper committed Oct 1, 2024
1 parent 10afc25 commit daf32dc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apstra/data_source_blueprint_iba_dashboard_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tfapstra
package tfapstra_test

import (
"context"
Expand Down
19 changes: 17 additions & 2 deletions apstra/data_source_datacenter_blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package tfapstra_test

import (
"context"
"errors"
"fmt"
"strconv"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
Expand All @@ -29,6 +31,19 @@ func TestDatasourceDatacenterBlueprint(t *testing.T) {
client := testutils.GetTestClient(t, ctx)
apiVersion := version.Must(version.NewVersion(client.ApiVersion()))

atleast50 := func(s string) error {
i, err := strconv.Atoi(s)
if err != nil {
return err
}

if i < 50 {
return errors.New("expected value >= 50, got " + s)
}

return nil
}

type testCase struct {
label string
apiVersionConstrants version.Constraints
Expand Down Expand Up @@ -81,7 +96,7 @@ func TestDatasourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("data.apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("data.apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -149,7 +164,7 @@ func TestDatasourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("data.apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "build_errors_count", "58"),
resource.TestCheckResourceAttrWith("data.apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down
23 changes: 12 additions & 11 deletions apstra/data_source_datacenter_configlet_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tfapstra
package tfapstra_test

import (
"context"
Expand All @@ -11,21 +11,22 @@ import (

const (
dataSourceDatacenterConfigletTemplateByNameHCL = `
data "apstra_datacenter_configlet" "test" {
blueprint_id = "%s"
name = "%s"
}
`
data "apstra_datacenter_configlet" "test" {
blueprint_id = "%s"
name = "%s"
}
`

dataSourceDatacenterConfigletTemplateByIdHCL = `
data "apstra_datacenter_configlet" "test" {
blueprint_id = "%s"
id = "%s"
}
`
data "apstra_datacenter_configlet" "test" {
blueprint_id = "%s"
id = "%s"
}
`
)

func TestAccDataSourceDatacenterConfiglet(t *testing.T) {
condition := "role in [\"spine\"]"
ctx := context.Background()

client := testutils.GetTestClient(t, ctx)
Expand Down
47 changes: 30 additions & 17 deletions apstra/resource_datacenter_blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
)
}

atleast50 := func(s string) error {
i, err := strconv.Atoi(s)
if err != nil {
return err
}

if i < 50 {
return errors.New("expected value >= 50, got " + s)
}

return nil
}

type testCase struct {
apiVersionConstraints version.Constraints
testCase resource.TestCase
Expand Down Expand Up @@ -173,7 +186,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeDisabled.String()),
Expand Down Expand Up @@ -356,7 +369,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -400,7 +413,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -518,7 +531,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeDisabled.String()),
Expand Down Expand Up @@ -702,7 +715,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "58"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -863,7 +876,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeDisabled.String()),
Expand Down Expand Up @@ -929,7 +942,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -973,7 +986,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1046,7 +1059,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1090,7 +1103,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1156,7 +1169,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1208,7 +1221,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "52"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeDisabled.String()),
Expand Down Expand Up @@ -1274,7 +1287,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1318,7 +1331,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1392,7 +1405,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1436,7 +1449,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down Expand Up @@ -1502,7 +1515,7 @@ func TestResourceDatacenterBlueprint(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "external_router_count", "0"),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "has_uncommitted_changes", "true"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "version", testCheckIntGE1),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_errors_count", "53"),
resource.TestCheckResourceAttrWith("apstra_datacenter_blueprint.test", "build_errors_count", atleast50),
resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "build_warnings_count", "0"),

resource.TestCheckResourceAttr("apstra_datacenter_blueprint.test", "anti_affinity_mode", apstra.AntiAffinityModeEnabledStrict.String()),
Expand Down

0 comments on commit daf32dc

Please sign in to comment.