provider/azurerm: Randomizing the ARM acceptance tests

This commit is contained in:
stack72 2016-11-24 21:53:19 +00:00
parent bb9d9dcd3d
commit 16a725b33f
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
4 changed files with 57 additions and 31 deletions

View File

@ -3,11 +3,13 @@ package azurerm
import (
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAzureRMNetworkSecurityGroup_importBasic(t *testing.T) {
resourceName := "azurerm_network_security_group.test"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -15,7 +17,7 @@ func TestAccAzureRMNetworkSecurityGroup_importBasic(t *testing.T) {
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMNetworkSecurityGroup_basic,
Config: testAccAzureRMNetworkSecurityGroup_basic(rInt),
},
resource.TestStep{

View File

@ -3,10 +3,12 @@ package azurerm
import (
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAzureRMNetworkSecurityRule_importBasic(t *testing.T) {
rInt := acctest.RandInt()
resourceName := "azurerm_network_security_rule.test"
resource.Test(t, resource.TestCase{
@ -15,7 +17,7 @@ func TestAccAzureRMNetworkSecurityRule_importBasic(t *testing.T) {
CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureRMNetworkSecurityRule_basic,
Config: testAccAzureRMNetworkSecurityRule_basic(rInt),
},
resource.TestStep{

View File

@ -5,18 +5,20 @@ import (
"net/http"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAzureRMNetworkSecurityGroup_basic(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityGroup_basic,
Config: testAccAzureRMNetworkSecurityGroup_basic(rInt()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
),
@ -26,13 +28,14 @@ func TestAccAzureRMNetworkSecurityGroup_basic(t *testing.T) {
}
func TestAccAzureRMNetworkSecurityGroup_disappears(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityGroup_basic,
Config: testAccAzureRMNetworkSecurityGroup_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
testCheckAzureRMNetworkSecurityGroupDisappears("azurerm_network_security_group.test"),
@ -44,13 +47,14 @@ func TestAccAzureRMNetworkSecurityGroup_disappears(t *testing.T) {
}
func TestAccAzureRMNetworkSecurityGroup_withTags(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityGroup_withTags,
Config: testAccAzureRMNetworkSecurityGroup_withTags(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr(
@ -63,7 +67,7 @@ func TestAccAzureRMNetworkSecurityGroup_withTags(t *testing.T) {
},
{
Config: testAccAzureRMNetworkSecurityGroup_withTagsUpdate,
Config: testAccAzureRMNetworkSecurityGroup_withTagsUpdate(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr(
@ -77,13 +81,14 @@ func TestAccAzureRMNetworkSecurityGroup_withTags(t *testing.T) {
}
func TestAccAzureRMNetworkSecurityGroup_addingExtraRules(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityGroup_basic,
Config: testAccAzureRMNetworkSecurityGroup_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr(
@ -92,7 +97,7 @@ func TestAccAzureRMNetworkSecurityGroup_addingExtraRules(t *testing.T) {
},
{
Config: testAccAzureRMNetworkSecurityGroup_anotherRule,
Config: testAccAzureRMNetworkSecurityGroup_anotherRule(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
resource.TestCheckResourceAttr(
@ -182,9 +187,10 @@ func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error {
return nil
}
var testAccAzureRMNetworkSecurityGroup_basic = `
func testAccAzureRMNetworkSecurityGroup_basic(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
name = "acctestRG-%d"
location = "West US"
}
@ -205,11 +211,13 @@ resource "azurerm_network_security_group" "test" {
destination_address_prefix = "*"
}
}
`
`, rInt)
}
var testAccAzureRMNetworkSecurityGroup_anotherRule = `
func testAccAzureRMNetworkSecurityGroup_anotherRule(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
name = "acctestRG-%d"
location = "West US"
}
@ -242,11 +250,13 @@ resource "azurerm_network_security_group" "test" {
destination_address_prefix = "*"
}
}
`
`, rInt)
}
var testAccAzureRMNetworkSecurityGroup_withTags = `
func testAccAzureRMNetworkSecurityGroup_withTags(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
name = "acctestRG-%d"
location = "West US"
}
@ -273,11 +283,13 @@ resource "azurerm_network_security_group" "test" {
cost_center = "MSFT"
}
}
`
`, rInt)
}
var testAccAzureRMNetworkSecurityGroup_withTagsUpdate = `
func testAccAzureRMNetworkSecurityGroup_withTagsUpdate(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
name = "acctestRG-%d"
location = "West US"
}
@ -302,4 +314,5 @@ resource "azurerm_network_security_group" "test" {
environment = "staging"
}
}
`
`, rInt)
}

View File

@ -5,19 +5,20 @@ import (
"net/http"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAzureRMNetworkSecurityRule_basic(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityRule_basic,
Config: testAccAzureRMNetworkSecurityRule_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test"),
),
@ -27,6 +28,7 @@ func TestAccAzureRMNetworkSecurityRule_basic(t *testing.T) {
}
func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -34,7 +36,7 @@ func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) {
CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityRule_basic,
Config: testAccAzureRMNetworkSecurityRule_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test"),
testCheckAzureRMNetworkSecurityRuleDisappears("azurerm_network_security_rule.test"),
@ -46,6 +48,7 @@ func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) {
}
func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -53,14 +56,14 @@ func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) {
CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkSecurityRule_updateBasic,
Config: testAccAzureRMNetworkSecurityRule_updateBasic(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test1"),
),
},
{
Config: testAccAzureRMNetworkSecurityRule_updateExtraRule,
Config: testAccAzureRMNetworkSecurityRule_updateExtraRule(rInt),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test2"),
),
@ -152,7 +155,8 @@ func testCheckAzureRMNetworkSecurityRuleDestroy(s *terraform.State) error {
return nil
}
var testAccAzureRMNetworkSecurityRule_basic = `
func testAccAzureRMNetworkSecurityRule_basic(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acceptanceTestResourceGroup1"
location = "West US"
@ -177,9 +181,11 @@ resource "azurerm_network_security_rule" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
network_security_group_name = "${azurerm_network_security_group.test.name}"
}
`
`, rInt)
}
var testAccAzureRMNetworkSecurityRule_updateBasic = `
func testAccAzureRMNetworkSecurityRule_updateBasic(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test1" {
name = "acceptanceTestResourceGroup2"
location = "West US"
@ -204,9 +210,11 @@ resource "azurerm_network_security_rule" "test1" {
resource_group_name = "${azurerm_resource_group.test1.name}"
network_security_group_name = "${azurerm_network_security_group.test1.name}"
}
`
`, rInt)
}
var testAccAzureRMNetworkSecurityRule_updateExtraRule = `
func testAccAzureRMNetworkSecurityRule_updateExtraRule(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test1" {
name = "acceptanceTestResourceGroup2"
location = "West US"
@ -245,4 +253,5 @@ resource "azurerm_network_security_rule" "test2" {
resource_group_name = "${azurerm_resource_group.test1.name}"
network_security_group_name = "${azurerm_network_security_group.test1.name}"
}
`
`, rInt)
}