Skip to content

Commit

Permalink
Adding File System Prereqs to dependent resources (#272)
Browse files Browse the repository at this point in the history
* Adding prereqs for File System dependent resources

* Updated PreReqs
  • Loading branch information
akshay-sripriya authored Jan 2, 2025
1 parent f154a2f commit d918347
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 28 deletions.
2 changes: 1 addition & 1 deletion powerscale/provider/access_zone_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
var mocker *mockey.Mocker
var createMocker *mockey.Mocker

func TestAccAccessZoneA(t *testing.T) {
func TestAccAccessZoneResourceCreate(t *testing.T) {
var accessZoneResourceName = "powerscale_accesszone.zone"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
23 changes: 22 additions & 1 deletion powerscale/provider/file_system_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,30 @@ func TestAccFileSystemDataSourceReleaseMock(t *testing.T) {
})
}

var FileSystemDataSourceConfig = `
var FileSystemResourceConfigCommon = `
resource "powerscale_filesystem" "file_system_test" {
directory_path = "/ifs"
name = "tfacc_file_system_test"
recursive = true
overwrite = true
group = {
id = "GID:0"
name = "wheel"
type = "group"
}
owner = {
id = "UID:0",
name = "root",
type = "user"
}
}
`

var FileSystemDataSourceConfig = FileSystemResourceConfigCommon + `
data "powerscale_filesystem" "system" {
# Required parameter, path of the directory filesystem you would like to create a datasource out of
depends_on = [powerscale_filesystem.file_system_test]
directory_path = "/ifs/tfacc_file_system_test"
}
`
Expand Down
27 changes: 24 additions & 3 deletions powerscale/provider/namespace_acl_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,30 @@ func TestAccNamespaceAclDataSourceParamErr(t *testing.T) {
})
}

var NamespaceACLDataSourceConfig = `
var FileSystemResourceConfigAcl = `
resource "powerscale_filesystem" "file_system_test" {
directory_path = "/ifs"
name = "tfaccAcl"
recursive = true
overwrite = true
group = {
id = "GID:0"
name = "wheel"
type = "group"
}
owner = {
id = "UID:0",
name = "root",
type = "user"
}
}
`

var NamespaceACLDataSourceConfig = FileSystemResourceConfigAcl + `
resource "powerscale_namespace_acl" "namespace_acl_test" {
namespace = "ifs/home"
depends_on = [powerscale_filesystem.file_system_test]
namespace = "ifs/tfaccAcl"
nsaccess = true
owner = { id = "UID:0"}
group = { id = "GID:0"}
Expand Down Expand Up @@ -131,7 +152,7 @@ resource "powerscale_namespace_acl" "namespace_acl_test" {
data "powerscale_namespace_acl" "test" {
filter {
namespace = "ifs/home"
namespace = "ifs/tfaccAcl"
nsaccess = true
}
depends_on = [
Expand Down
4 changes: 2 additions & 2 deletions powerscale/provider/nfs_export_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ func TestAccNFSExportErrorDelete(t *testing.T) {
var FileSystemResourceConfigCommon2 = `
resource "powerscale_filesystem" "file_system_test" {
directory_path = "/ifs"
name = "tfacc_nfs_export1"
name = "tfacc_nfs_export"
recursive = true
overwrite = false
overwrite = true
group = {
id = "GID:0"
name = "wheel"
Expand Down
74 changes: 68 additions & 6 deletions powerscale/provider/snapshot_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,61 @@ func TestAccSnapshotDataSourceMapErr(t *testing.T) {
}

var SnapshotDataSourceConfig = `
resource "powerscale_filesystem" "file_system_test2" {
directory_path = "/ifs"
name = "tfacc_file_system_test"
recursive = true
overwrite = true
group = {
id = "GID:0"
name = "wheel"
type = "group"
}
owner = {
id = "UID:0",
name = "root",
type = "user"
}
}
resource "powerscale_snapshot" "test" {
path = "/ifs/tfacc_file_system_test"
name = "tfacc_snapshot_1"
depends_on = [powerscale_filesystem.file_system_test2]
path = "/ifs/tfacc_file_system_test"
name = "tfacc_snapshot_1"
set_expires = "1 Day"
}
data "powerscale_snapshot" "test" {
depends_on = [powerscale_snapshot.test]
filter {
path = "/ifs/tfacc_file_system_test"
state = "active"
}
depends_on = [
powerscale_snapshot.test
]
}
`

var SnapshotDataSourceNameConfig = `
resource "powerscale_filesystem" "file_system_test2" {
directory_path = "/ifs"
name = "tfacc_file_system_test"
recursive = true
overwrite = true
group = {
id = "GID:0"
name = "wheel"
type = "group"
}
owner = {
id = "UID:0",
name = "root",
type = "user"
}
}
resource "powerscale_snapshot" "test" {
depends_on = [powerscale_filesystem.file_system_test2]
path = "/ifs/tfacc_file_system_test"
name = "tfacc_snapshot_1"
}
Expand All @@ -149,6 +185,32 @@ data "powerscale_snapshot" "test" {
`

var SnapshotAllDataSourceConfig = `
resource "powerscale_filesystem" "file_system_test2" {
directory_path = "/ifs"
name = "tfacc_file_system_test"
recursive = true
overwrite = true
group = {
id = "GID:0"
name = "wheel"
type = "group"
}
owner = {
id = "UID:0",
name = "root",
type = "user"
}
}
resource "powerscale_snapshot" "test" {
depends_on = [powerscale_filesystem.file_system_test2]
path = "/ifs/tfacc_file_system_test"
name = "tfacc_snapshot_1"
set_expires = "1 Day"
}
data "powerscale_snapshot" "all" {
depends_on = [powerscale_snapshot.test]
}
`
6 changes: 4 additions & 2 deletions powerscale/provider/snapshot_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,20 @@ func TestAccSnapshotResourceReadAndUpdateError(t *testing.T) {
})
}

var SnapshotResourceConfig = `
var SnapshotResourceConfig = FileSystemResourceConfigCommon + `
resource "powerscale_snapshot" "test" {
# Required path to the filesystem to which the snapshot will be taken of
path = "/ifs/tfacc_file_system_test"
depends_on = [powerscale_filesystem.file_system_test]
}
`

var SnapshotResourceConfigUpdate = `
var SnapshotResourceConfigUpdate = FileSystemResourceConfigCommon + `
resource "powerscale_snapshot" "test" {
path = "/ifs/tfacc_file_system_test"
name = "tfacc_snapshot_1"
set_expires = "1 Day"
depends_on = [powerscale_filesystem.file_system_test]
}
`

Expand Down
63 changes: 54 additions & 9 deletions powerscale/provider/snapshot_schedule_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package provider

import (
powerscale "dell/powerscale-go-client"
"fmt"
"regexp"
"terraform-provider-powerscale/powerscale/helper"
Expand All @@ -23,7 +24,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccSnapshotScheduleDataSource(t *testing.T) {
func TestAccSnapshotScheduleDataSourceA(t *testing.T) {
var snapshotTerraformName = "data.powerscale_snapshot_schedule.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -33,8 +34,8 @@ func TestAccSnapshotScheduleDataSource(t *testing.T) {
{
Config: ProviderConfig + SnapshotScheduleDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(snapshotTerraformName, "schedules.0.name", "Snapshot schedule 370395356"),
resource.TestCheckResourceAttr(snapshotTerraformName, "schedules.0.alias", "tfacc_Snapshot schedule 370395356_Alias"),
resource.TestCheckResourceAttr(snapshotTerraformName, "schedules.0.name", "tfacc_snap_schedule_test"),
resource.TestCheckResourceAttr(snapshotTerraformName, "schedules.0.alias", "test_alias"),
),
},
},
Expand Down Expand Up @@ -89,9 +90,14 @@ func TestAccSnapshotScheduleDataSourceGetErr(t *testing.T) {
},
},
})
FunctionMocker.UnPatch()

}

func TestAccSnapshotScheduleDataSourceGetErrCopyAll(t *testing.T) {
FunctionMockerList := mockey.Mock(helper.ListSnapshotSchedules).Return([]powerscale.V1SnapshotScheduleExtended{
{}, {},
}, nil).Build()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Expand All @@ -100,14 +106,27 @@ func TestAccSnapshotScheduleDataSourceGetErrCopyAll(t *testing.T) {
PreConfig: func() {
FunctionMocker = mockey.Mock(helper.CopyFields).Return(fmt.Errorf("mock error")).Build()
},
Config: ProviderConfig + SnapshotScheduleAllDataSourceConfig,
Config: ProviderConfig + SnapshotScheduleAllDataSourceConfig2,
ExpectError: regexp.MustCompile(`.*mock error*.`),
},
},
})
FunctionMockerList.UnPatch()
}

func NewValue[v any](in v) *v {
return &in
}

func TestAccSnapshotScheduleDataSourceGetErrCopy(t *testing.T) {
FunctionMockerList := mockey.Mock(helper.ListSnapshotSchedules).Return([]powerscale.V1SnapshotScheduleExtended{
{
Name: NewValue("tfacc_snap_schedule_test"),
},
{
Name: NewValue("tfacc_snap_schedule_test1"),
},
}, nil).Build()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Expand All @@ -116,35 +135,61 @@ func TestAccSnapshotScheduleDataSourceGetErrCopy(t *testing.T) {
PreConfig: func() {
FunctionMocker = mockey.Mock(helper.CopyFields).Return(fmt.Errorf("mock error")).Build()
},
Config: ProviderConfig + SnapshotScheduleDataSourceConfig,
Config: ProviderConfig + SnapshotScheduleDataSourceConfig2,
ExpectError: regexp.MustCompile(`.*mock error*.`),
},
},
})
FunctionMockerList.UnPatch()
}

var SnapshotScheduleDataSourceConfig = `
var SnapshotScheduleCommonConfig = FileSystemResourceConfigCommon + `
resource "powerscale_snapshot_schedule" "test" {
# Required name of snapshot schedule
depends_on = [powerscale_filesystem.file_system_test]
name = "tfacc_snap_schedule_test"
alias = "test_alias"
path = "/ifs/tfacc_file_system_test"
retention_time = "3 Hour(s)"
}
`

var SnapshotScheduleDataSourceConfig = SnapshotScheduleCommonConfig + `
data "powerscale_snapshot_schedule" "test" {
depends_on = [powerscale_snapshot_schedule.test]
filter {
names = ["Snapshot schedule 370395356"]
names = ["tfacc_snap_schedule_test"]
}
}
output "powerscale_snapshot_schedule" {
value = data.powerscale_snapshot_schedule.test
}
`

var SnapshotScheduleAllDataSourceConfig = `
var SnapshotScheduleAllDataSourceConfig = SnapshotScheduleCommonConfig + `
data "powerscale_snapshot_schedule" "all" {
depends_on = [powerscale_snapshot_schedule.test]
}
`

var SnapshotScheduleOtherFiltersDataSourceConfig = `
var SnapshotScheduleOtherFiltersDataSourceConfig = SnapshotScheduleCommonConfig + `
data "powerscale_snapshot_schedule" "filterTest" {
depends_on = [powerscale_snapshot_schedule.test]
filter {
dir = "ASC"
limit = 1
sort = "name"
}
}
`
var SnapshotScheduleDataSourceConfig2 = `
data "powerscale_snapshot_schedule" "test" {
filter {
names = ["tfacc_snap_schedule_test"]
}
}
`
var SnapshotScheduleAllDataSourceConfig2 = `
data "powerscale_snapshot_schedule" "all" {
}
`
Loading

0 comments on commit d918347

Please sign in to comment.