Skip to content

Commit

Permalink
test: add isolation rule test case
Browse files Browse the repository at this point in the history
  • Loading branch information
marinsalinas committed Aug 13, 2019
1 parent 14cea6c commit 5ce4139
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
5 changes: 5 additions & 0 deletions nutanix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nutanix

import (
"math/rand"
"os"
"testing"
"time"

Expand Down Expand Up @@ -39,3 +40,7 @@ func randIntBetween(min, max int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(max-min) + min
}

func isGCPEnvironment() bool {
return os.Getenv("NUTANIX_GCP") == "true"
}
2 changes: 1 addition & 1 deletion nutanix/resource_nutanix_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestAccNutanixImage_WithLargeImageURL(t *testing.T) {

func TestAccNutanixImage_uploadLocal(t *testing.T) {
//Skipping Because in GCP still failing
if os.Getenv("NUTANIX_GCP") == "true" {
if isGCPEnvironment() {
t.Skip()
}

Expand Down
59 changes: 56 additions & 3 deletions nutanix/resource_nutanix_network_security_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

func TestAccNutanixNetworkSecurityRule_basic(t *testing.T) {
// Skipped because this test didn't pass in GCP environment
// if isGCPEnvironment() {
// t.Skip()
// }
if isGCPEnvironment() {
t.Skip()
}

rInt := acctest.RandInt()
resourceName := "nutanix_network_security_rule.TEST-TIER"
Expand Down Expand Up @@ -45,6 +45,34 @@ func TestAccNutanixNetworkSecurityRule_basic(t *testing.T) {
},
})
}
func TestAccNutanixNetworkSecurityRule_isolation(t *testing.T) {
// Skipped because this test didn't pass in GCP environment
if isGCPEnvironment() {
t.Skip()
}

rInt := acctest.RandInt()
resourceName := "nutanix_network_security_rule.isolation"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixNetworkSecurityRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixNetworkSecurityRuleIsolationConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixNetworkSecurityRuleExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckNutanixNetworkSecurityRuleExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -83,6 +111,31 @@ func testAccCheckNutanixNetworkSecurityRuleDestroy(s *terraform.State) error {
return nil
}

func testAccNutanixNetworkSecurityRuleIsolationConfig(r int) string {
return fmt.Sprintf(`
resource "nutanix_network_security_rule" "isolation" {
name = "test-acc-isolation-rule-%d"
description = "Isolation Test Acc"
isolation_rule_action = "APPLY"
isolation_rule_first_entity_filter_kind_list = ["vm"]
isolation_rule_first_entity_filter_type = "CATEGORIES_MATCH_ALL"
isolation_rule_first_entity_filter_params {
name = "Environment"
values = ["Dev"]
}
isolation_rule_second_entity_filter_kind_list = ["vm"]
isolation_rule_second_entity_filter_type = "CATEGORIES_MATCH_ALL"
isolation_rule_second_entity_filter_params {
name = "Environment"
values = ["Production"]
}
}
`, r)
}

func testAccNutanixNetworkSecurityRuleConfig(r int) string {
return fmt.Sprintf(`
resource "nutanix_category_key" "test-category-key"{
Expand Down

0 comments on commit 5ce4139

Please sign in to comment.