Skip to content

Commit

Permalink
refactor: changed many stuff to make it compatible with lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar López committed May 15, 2020
1 parent 5a77db9 commit dcdbe25
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 64 deletions.
8 changes: 4 additions & 4 deletions nutanix/data_source_protection_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func TestAccNutanixProtectionRuleDataSource_basic(t *testing.T) {
resourceName := "nutanix_protection_rule.protection_rule_test"
resourceName := "nutanix_protection_rule.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")

nameUpdated := acctest.RandomWithPrefix("test-protection-name-dou")
descriptionUpdated := acctest.RandomWithPrefix("test-protection-desc-dou")

zone := "ab788130-0820-4d07-a1b5-b0ba4d3a4254"
zone := "ab788130-0820-4d07-a1b5-b0ba4d3ard54"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -43,7 +43,7 @@ func TestAccNutanixProtectionRuleDataSource_basic(t *testing.T) {

func testAccProtectionRuleDataSourceConfig(name, description, zone string) string {
return fmt.Sprintf(`
resource "nutanix_protection_rule" "protection_rule_test" {
resource "nutanix_protection_rule" "test" {
name = "%s"
description = "%s"
ordered_availability_zone_list{
Expand All @@ -67,7 +67,7 @@ func testAccProtectionRuleDataSourceConfig(name, description, zone string) strin
}
}
data "nutanix_protection_rule" "test" {
protection_rule_id = nutanix_protection_rule.protection_rule_test.id
protection_rule_id = nutanix_protection_rule.test.id
}
`, name, description, zone)
}
6 changes: 3 additions & 3 deletions nutanix/data_source_protection_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ func dataSourceNutanixProtectionRulesRead(d *schema.ResourceData, meta interface
return nil
}

func flattenProtectionRuleEntities(ProtectionRules []*v3.ProtectionRuleResponse) []map[string]interface{} {
entities := make([]map[string]interface{}, len(ProtectionRules))
func flattenProtectionRuleEntities(protectionRules []*v3.ProtectionRuleResponse) []map[string]interface{} {
entities := make([]map[string]interface{}, len(protectionRules))

for i, protectionRule := range ProtectionRules {
for i, protectionRule := range protectionRules {
metadata, categories := setRSEntityMetadata(protectionRule.Metadata)

entities[i] = map[string]interface{}{
Expand Down
19 changes: 10 additions & 9 deletions nutanix/data_source_recovery_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@ import (
)

func TestAccNutanixRecoveryPlanDataSource_basic(t *testing.T) {
resourceName := "nutanix_recovery_plan.recovery_plan_test"
resourceName := "nutanix_recovery_plan.test"

name := acctest.RandomWithPrefix("test-recovery-name-dou")
description := acctest.RandomWithPrefix("test-recovery-desc-dou")

nameUpdated := acctest.RandomWithPrefix("test-recovery-name-dou")
descriptionUpdated := acctest.RandomWithPrefix("test-recovery-desc-dou")
zone := "ab788130-0820-4d07-a1b5-b0ba4d3a4254"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixRecoveryPlanDestroy,
Steps: []resource.TestStep{
{
Config: testAccRecoveryPlanDataSourceConfig(name, description, zone),
Config: testAccRecoveryPlanDataSourceConfig(name, description),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", description),
),
},
{
Config: testAccRecoveryPlanDataSourceConfig(nameUpdated, descriptionUpdated, zone),
Config: testAccRecoveryPlanDataSourceConfig(nameUpdated, descriptionUpdated),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", nameUpdated),
resource.TestCheckResourceAttr(resourceName, "description", descriptionUpdated),
Expand All @@ -41,9 +40,9 @@ func TestAccNutanixRecoveryPlanDataSource_basic(t *testing.T) {
})
}

func testAccRecoveryPlanDataSourceConfig(name, description, zoneUUID string) string {
func testAccRecoveryPlanDataSourceConfig(name, description string) string {
return fmt.Sprintf(`
resource "nutanix_recovery_plan" "recovery_plan_test" {
resource "nutanix_recovery_plan" "test" {
name = "%s"
description = "%s"
stage_list {
Expand All @@ -57,12 +56,14 @@ func testAccRecoveryPlanDataSourceConfig(name, description, zoneUUID string) str
}
}
}
stage_uuid = "%[3]s"
stage_uuid = "ab788130-0820-4d07-a1b5-b0ba4d3a4254"
delay_time_secs = 0
}
parameters{}
}
data "nutanix_recovery_plan" "test" {
recovery_plan_id = nutanix_recovery_plan.recovery_plan_test.id
recovery_plan_id = nutanix_recovery_plan.test.id
}
`, name, description, zoneUUID)
`, name, description)
}
6 changes: 3 additions & 3 deletions nutanix/data_source_recovery_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ func dataSourceNutanixRecoveryPlansRead(d *schema.ResourceData, meta interface{}
return nil
}

func flattenRecoveryPlanEntities(ProtectionRules []*v3.RecoveryPlanResponse) []map[string]interface{} {
entities := make([]map[string]interface{}, len(ProtectionRules))
func flattenRecoveryPlanEntities(protectionRules []*v3.RecoveryPlanResponse) []map[string]interface{} {
entities := make([]map[string]interface{}, len(protectionRules))

for i, recoveryPlan := range ProtectionRules {
for i, recoveryPlan := range protectionRules {
metadata, categories := setRSEntityMetadata(recoveryPlan.Metadata)

entities[i] = map[string]interface{}{
Expand Down
16 changes: 7 additions & 9 deletions nutanix/resource_nutanix_protection_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func resourceNutanixProtectionRuleCreate(d *schema.ResourceData, meta interface{
desc, descok := d.GetOk("description")

if !nok && !azclok && !oazlok {
return fmt.Errorf("please provide the required attributes `name`, `availability_zone_connectivity_list`, `ordered_availability_zone_list`")
return fmt.Errorf("please provide the required attributes `name`, `availability_zone`, `ordered_availability_zone`")
}

if err := getMetadataAttributes(d, metadata, "protection_rule"); err != nil {
Expand Down Expand Up @@ -703,16 +703,14 @@ func flattenCategoriesFilter(categoryFilter *v3.CategoryFilter) []interface{} {

func flattenAvailabilityZoneConnectivityList(azcl []*v3.AvailabilityZoneConnectivityList) []map[string]interface{} {
availibilityList := make([]map[string]interface{}, 0)
if azcl != nil {
for _, v := range azcl {
availability := make(map[string]interface{})
for _, v := range azcl {
availability := make(map[string]interface{})

availability["destination_availability_zone_index"] = utils.Int64Value(v.DestinationAvailabilityZoneIndex)
availability["source_availability_zone_index"] = utils.Int64Value(v.SourceAvailabilityZoneIndex)
availability["snapshot_schedule_list"] = flattenSnapshotScheduleList(v.SnapshotScheduleList)
availability["destination_availability_zone_index"] = utils.Int64Value(v.DestinationAvailabilityZoneIndex)
availability["source_availability_zone_index"] = utils.Int64Value(v.SourceAvailabilityZoneIndex)
availability["snapshot_schedule_list"] = flattenSnapshotScheduleList(v.SnapshotScheduleList)

availibilityList = append(availibilityList, availability)
}
availibilityList = append(availibilityList, availability)
}
return availibilityList
}
Expand Down
21 changes: 9 additions & 12 deletions nutanix/resource_nutanix_protection_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,29 @@ import (
)

func TestAccNutanixProtectionRule_basic(t *testing.T) {
resourceName := "nutanix_protection_rule.protection_rule_test"
resourceName := "nutanix_protection_rule.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")

nameUpdated := acctest.RandomWithPrefix("test-protection-name-dou")
descriptionUpdated := acctest.RandomWithPrefix("test-protection-desc-dou")

zone := "ab788130-0820-4d07-a1b5-b0ba4d3a4254"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixProtectionRUleDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixProtectionRuleConfig(name, description, zone, 1),
Config: testAccNutanixProtectionRuleConfig(name, description, 1),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProtectionRuleExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", description),
),
},
{
Config: testAccNutanixProtectionRuleConfig(nameUpdated, descriptionUpdated, zone, 2),
Config: testAccNutanixProtectionRuleConfig(nameUpdated, descriptionUpdated, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProtectionRuleExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", nameUpdated),
Expand All @@ -48,19 +46,18 @@ func TestAccNutanixProtectionRule_basic(t *testing.T) {
}

func TestAccResourceNutanixProtectionRule_importBasic(t *testing.T) {
resourceName := "nutanix_protection_rule.protection_rule_test"
resourceName := "nutanix_protection_rule.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")
zone := "ab788130-0820-4d07-a1b5-b0ba4d3a4254"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixProtectionRUleDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixProtectionRuleConfig(name, description, zone, 1),
Config: testAccNutanixProtectionRuleConfig(name, description, 1),
},
{
ResourceName: resourceName,
Expand Down Expand Up @@ -117,13 +114,13 @@ func testAccCheckNutanixProtectionRUleDestroy(s *terraform.State) error {
return nil
}

func testAccNutanixProtectionRuleConfig(name, description, zone string, snapshots int64) string {
func testAccNutanixProtectionRuleConfig(name, description string, snapshots int64) string {
return fmt.Sprintf(`
resource "nutanix_protection_rule" "protection_rule_test" {
resource "nutanix_protection_rule" "test" {
name = "%s"
description = "%s"
ordered_availability_zone_list{
availability_zone_url = "%s"
availability_zone_url = "ab788130-0820-4d07-a1b5-b0ba4d3a4254"
}
availability_zone_connectivity_list{
Expand All @@ -142,5 +139,5 @@ func testAccNutanixProtectionRuleConfig(name, description, zone string, snapshot
}
}
}
`, name, description, zone, snapshots)
`, name, description, snapshots)
}
22 changes: 10 additions & 12 deletions nutanix/resource_nutanix_recovery_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,14 +789,14 @@ func expandFloatingAssignmentList(d []interface{}) []*v3.FloatingIPAssignmentLis
floating.AvailabilityZoneURL = utils.StringPtr(v2.(string))
}
if v2, ok1 := v1["vm_ip_assignment_list"].([]interface{}); ok1 {
floating.VMIPAssignmentList = expandVmIpAssignmentList(v2)
floating.VMIPAssignmentList = expandVMIPAssignmentList(v2)
floatings = append(floatings, floating)
}
}
return floatings
}

func expandVmIpAssignmentList(d []interface{}) []*v3.VMIPAssignmentList {
func expandVMIPAssignmentList(d []interface{}) []*v3.VMIPAssignmentList {
assigns := make([]*v3.VMIPAssignmentList, 0)
for _, assignment := range d {
vmial := &v3.VMIPAssignmentList{}
Expand Down Expand Up @@ -903,16 +903,14 @@ func expandSubnetList(d []interface{}) []*v3.SubnetList {

func flattenStageList(sl []*v3.StageList) []map[string]interface{} {
stageList := make([]map[string]interface{}, 0)
if sl != nil {
for _, v := range sl {
stage := make(map[string]interface{})
for _, v := range sl {
stage := make(map[string]interface{})

stage["stage_uuid"] = utils.StringValue(v.StageUUID)
stage["delay_time_secs"] = utils.Int64Value(v.DelayTimeSecs)
stage["stage_work"] = flattenStageWork(v.StageWork)
stage["stage_uuid"] = utils.StringValue(v.StageUUID)
stage["delay_time_secs"] = utils.Int64Value(v.DelayTimeSecs)
stage["stage_work"] = flattenStageWork(v.StageWork)

stageList = append(stageList, stage)
}
stageList = append(stageList, stage)
}
return stageList
}
Expand Down Expand Up @@ -969,14 +967,14 @@ func flattenFloatingAssignmentList(floatingList []*v3.FloatingIPAssignmentList)
for _, floating := range floatingList {
float := make(map[string]interface{})
float["availability_zone_url"] = utils.StringValue(floating.AvailabilityZoneURL)
float["vm_ip_assignment_list"] = flattenVmAssignmentList(floating.VMIPAssignmentList)
float["vm_ip_assignment_list"] = flattenVMAssignmentList(floating.VMIPAssignmentList)
floatings = append(floatings, float)
}
}
return floatings
}

func flattenVmAssignmentList(vmList []*v3.VMIPAssignmentList) []map[string]interface{} {
func flattenVMAssignmentList(vmList []*v3.VMIPAssignmentList) []map[string]interface{} {
assignments := make([]map[string]interface{}, 0)
if len(vmList) > 0 {
for _, assignment := range vmList {
Expand Down
21 changes: 9 additions & 12 deletions nutanix/resource_nutanix_recovery_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,29 @@ import (
)

func TestAccNutanixRecoveryPlan_basic(t *testing.T) {
resourceName := "nutanix_recovery_plan.recovery_plan_test"
resourceName := "nutanix_recovery_plan.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")

nameUpdated := acctest.RandomWithPrefix("test-protection-name-dou")
descriptionUpdated := acctest.RandomWithPrefix("test-protection-desc-dou")

zone := "ab788130-0820-4d07-a1b5-b0ba4d3a4254"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixRecoveryPlanDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixRecoveryPlanConfig(name, description, zone),
Config: testAccNutanixRecoveryPlanConfig(name, description),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixRecoveryPlanExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", description),
),
},
{
Config: testAccNutanixRecoveryPlanConfig(nameUpdated, descriptionUpdated, zone),
Config: testAccNutanixRecoveryPlanConfig(nameUpdated, descriptionUpdated),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixRecoveryPlanExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", nameUpdated),
Expand All @@ -48,19 +46,18 @@ func TestAccNutanixRecoveryPlan_basic(t *testing.T) {
}

func TestAccResourceNutanixRecoveryPlan_importBasic(t *testing.T) {
resourceName := "nutanix_recovery_plan.recovery_plan_test"
resourceName := "nutanix_recovery_plan.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")
zone := "ab788130-0820-4d07-a1b5-b0ba4d3a4254"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixRecoveryPlanDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixRecoveryPlanConfig(name, description, zone),
Config: testAccNutanixRecoveryPlanConfig(name, description),
},
{
ResourceName: resourceName,
Expand Down Expand Up @@ -117,9 +114,9 @@ func testAccCheckNutanixRecoveryPlanDestroy(s *terraform.State) error {
return nil
}

func testAccNutanixRecoveryPlanConfig(name, description, zone string) string {
func testAccNutanixRecoveryPlanConfig(name, description string) string {
return fmt.Sprintf(`
resource "nutanix_recovery_plan" "recovery_plan_test" {
resource "nutanix_recovery_plan" "test" {
name = "%s"
description = "%s"
stage_list {
Expand All @@ -133,10 +130,10 @@ func testAccNutanixRecoveryPlanConfig(name, description, zone string) string {
}
}
}
stage_uuid = "%[3]s"
stage_uuid = "ab788130-0820-4d07-a1b5-b0ba4d3a4254"
delay_time_secs = 0
}
parameters{}
}
`, name, description, zone)
`, name, description)
}

0 comments on commit dcdbe25

Please sign in to comment.