Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add acceptance tests for svm resource storage_limit parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Christ <achim.christ@sva.de>
acch committed Oct 16, 2024
1 parent d294f0e commit 2fcb74a
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions internal/provider/svm/svm_resource_test.go
Original file line number Diff line number Diff line change
@@ -2,11 +2,12 @@ package svm_test

import (
"fmt"
ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider"
"os"
"regexp"
"testing"

ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider"

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

@@ -16,53 +17,56 @@ func TestAccSvmResource(t *testing.T) {
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccSvmResourceConfig("tfsvm4", "test", "default"),
Config: testAccSvmResourceConfig("tfsvm4", "test", "default", 0),
Check: resource.ComposeTestCheckFunc(
// Check to see the svm name is correct,
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "name", "tfsvm4"),
// Check to see if Ipspace is set correctly
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "ipspace", "ansibleIpspace_newname"),
// Check that a ID has been set (we don't know what the vaule is as it changes
resource.TestCheckResourceAttrSet("netapp-ontap_svm.example", "id"),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "comment", "test")),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "comment", "test"),
// Check to see if storage_limit is set correctly
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "storage_limit", "0"),
),
},
// Update a comment
{
Config: testAccSvmResourceConfig("tfsvm4", "carchi8py was here", "default"),
Config: testAccSvmResourceConfig("tfsvm4", "carchi8py was here", "default", 0),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "comment", "carchi8py was here"),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "name", "tfsvm4")),
},
// Update a comment with an empty string
{
Config: testAccSvmResourceConfig("tfsvm4", "", "default"),
Config: testAccSvmResourceConfig("tfsvm4", "", "default", 0),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "comment", ""),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "name", "tfsvm4")),
},
// Update snapshot policy default-1weekly and comment "carchi8py was here"
{
Config: testAccSvmResourceConfig("tfsvm4", "carchi8py was here", "default-1weekly"),
Config: testAccSvmResourceConfig("tfsvm4", "carchi8py was here", "default-1weekly", 0),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "comment", "carchi8py was here"),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "snapshot_policy", "default-1weekly"),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "name", "tfsvm4")),
},
// Update snapshot policy with empty string
{
Config: testAccSvmResourceConfig("tfsvm4", "carchi8py was here", ""),
Config: testAccSvmResourceConfig("tfsvm4", "carchi8py was here", "", 0),
ExpectError: regexp.MustCompile("cannot be updated with empty string"),
},
// change SVM name
{
Config: testAccSvmResourceConfig("tfsvm3", "carchi8py was here", "default"),
Config: testAccSvmResourceConfig("tfsvm3", "carchi8py was here", "default", 0),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "comment", "carchi8py was here"),
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "name", "tfsvm3")),
},
// Fail if the name already exist
{
Config: testAccSvmResourceConfig("svm5", "carchi8py was here", "default"),
Config: testAccSvmResourceConfig("svm5", "carchi8py was here", "default", 0),
ExpectError: regexp.MustCompile("13434908"),
},
// Import and read
@@ -74,10 +78,22 @@ func TestAccSvmResource(t *testing.T) {
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "name", "ansibleSVM"),
),
},
// Update storage_limit
{
Config: testAccSvmResourceConfig("tfsvm3", "carchi8py was here", "default", (1024 * 1024 * 1024)), // 1GB
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm.example", "storage_limit", "1073741824"),
),
},
// Fail if storage_limit too low
{
Config: testAccSvmResourceConfig("tfsvm3", "carchi8py was here", "default", (1024 * 1024)), // 1MB
ExpectError: regexp.MustCompile("13434880"),
},
},
})
}
func testAccSvmResourceConfig(svm, comment string, snapshotPolicy string) string {
func testAccSvmResourceConfig(svm, comment string, snapshotPolicy string, storage_limit int) string {
host := os.Getenv("TF_ACC_NETAPP_HOST")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
@@ -118,5 +134,6 @@ resource "netapp-ontap_svm" "example" {
},
]
max_volumes = "unlimited"
}`, host, admin, password, svm, comment, snapshotPolicy)
storage_limit = %d
}`, host, admin, password, svm, comment, snapshotPolicy, storage_limit)
}

0 comments on commit 2fcb74a

Please sign in to comment.