Skip to content

Commit

Permalink
Adding PreReqs for Replication Report AT (#271)
Browse files Browse the repository at this point in the history
* Added PreReqs for SyncIQ Replication Report Acceptance Tests

* Updated test data, fixed Synciq policy AT

* fixed acceptance test data
  • Loading branch information
akshay-sripriya authored Dec 24, 2024
1 parent 6c953da commit f154a2f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
13 changes: 12 additions & 1 deletion powerscale/provider/synciq_policy_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func TestAccSynciqPolicyDatasourceID(t *testing.T) {
Steps: []resource.TestStep{
// Read testing
{
Config: ProviderConfig + `
Config: ProviderConfig + PolicyConfig + `
data "powerscale_synciq_policy" "preq" {
depends_on = [powerscale_synciq_policy.policy1]
}
data "powerscale_synciq_policy" "test" {
id = data.powerscale_synciq_policy.preq.policies[0].id
Expand Down Expand Up @@ -98,3 +99,13 @@ func TestAccSynciqPolicyDatasourceID(t *testing.T) {
},
})
}

var PolicyConfig = `
resource "powerscale_synciq_policy" "policy1" {
name = "tfaccPolicy"
action = "sync"
source_root_path = "/ifs"
target_host = "10.10.10.10"
target_path = "/ifs/tfaccSink"
}
`
79 changes: 71 additions & 8 deletions powerscale/provider/synciq_replication_reports_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@ package provider

import (
"fmt"
"github.com/bytedance/mockey"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"regexp"
"terraform-provider-powerscale/powerscale/helper"
"testing"

"github.com/bytedance/mockey"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccReplicationReportsDataSourceAll(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {
Source: "hashicorp/time",
},
},
Steps: []resource.TestStep{
// read all
{
Config: ProviderConfig + RRDataSourceConfig,
Config: ProviderConfig + SetupHostIP() + RRDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(),
},
},
Expand All @@ -44,10 +50,15 @@ func TestAccReplicationReportsDataSourceFilter(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {
Source: "hashicorp/time",
},
},
Steps: []resource.TestStep{
// read all
{
Config: ProviderConfig + RRDataSourceConfigFilter,
Config: ProviderConfig + SetupHostIP() + RRDataSourceConfigFilter,
Check: resource.ComposeAggregateTestCheckFunc(),
},
},
Expand All @@ -71,28 +82,80 @@ func TestAccReplicationReportsDataSourceGettingErr(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {
Source: "hashicorp/time",
},
},
Steps: []resource.TestStep{
{
PreConfig: func() {
FunctionMocker = mockey.Mock(helper.GetReplicationReports).Return(nil, fmt.Errorf("mock error")).Build()
},
Config: ProviderConfig + RRDataSourceConfig,
Config: ProviderConfig + SetupHostIP() + RRDataSourceConfig,
ExpectError: regexp.MustCompile(`.*mock error*.`),
},
},
})
}

var RRDataSourceConfig = `
func SetupHostIP() string {

if powerScaleSSHIP == "localhost" || powerScaleSSHIP == "0.0.0.0" {
return `
locals {
host_ip = "10.10.10.10"
}
`
}
var result = fmt.Sprintf(`
locals {
host_ip = "%s"
}
`, powerScaleSSHIP)

return result

}

var JobConfig = `
resource "powerscale_synciq_policy" "policy1" {
name = "tfaccPolicy"
action = "sync"
source_root_path = "/ifs"
target_host = local.host_ip
target_path = "/ifs/tfaccSink"
}
resource "powerscale_synciq_replication_job" "job1" {
action = "run"
id = powerscale_synciq_policy.policy1.id
is_paused = false
wait_time = 5
depends_on = [
powerscale_synciq_policy.policy1
]
}
resource "time_sleep" "wait_60_seconds" {
create_duration = "90s"
depends_on = [powerscale_synciq_replication_job.job1]
}
`

var RRDataSourceConfig = JobConfig + `
data "powerscale_synciq_replication_report" "all" {
depends_on = [time_sleep.wait_60_seconds]
}
`

var RRDataSourceConfigFilter = `
var RRDataSourceConfigFilter = JobConfig + `
data "powerscale_synciq_replication_report" "filtering" {
filter {
reports_per_policy = 2
reports_per_policy = 1
}
depends_on = [time_sleep.wait_60_seconds]
}
`

Expand Down

0 comments on commit f154a2f

Please sign in to comment.