Skip to content

Commit

Permalink
Add test cases to repro bug #1619
Browse files Browse the repository at this point in the history
  • Loading branch information
Junyi Yi committed Jan 22, 2019
1 parent 191be77 commit fb0220d
Showing 1 changed file with 79 additions and 20 deletions.
99 changes: 79 additions & 20 deletions azurerm/resource_arm_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,57 @@ func TestAccAzureRMSubnet_disappears(t *testing.T) {
})
}

func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) {
resourceName := "azurerm_subnet.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMSubnet_serviceEndpoints(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSubnetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSubnetExists("azurerm_subnet.test"),
resource.TestCheckResourceAttr(resourceName, "service_endpoints.#", "2"),
),
},
},
})
}

func TestAccAzureRMSubnet_serviceEndpointsVNetUpdate(t *testing.T) {
resourceName := "azurerm_subnet.test"
ri := tf.AccRandTimeInt()
location := testLocation()
config := testAccAzureRMSubnet_serviceEndpoints(ri, location)
updatedConfig := testAccAzureRMSubnet_serviceEndpointsVNetUpdate(ri, location)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSubnetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSubnetExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "service_endpoints.#", "2"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSubnetExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "service_endpoints.#", "2"),
),
},
},
})
}

func testCheckAzureRMSubnetExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -362,26 +413,6 @@ func testCheckAzureRMSubnetDestroy(s *terraform.State) error {
return nil
}

func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) {

ri := tf.AccRandTimeInt()
config := testAccAzureRMSubnet_serviceEndpoints(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSubnetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSubnetExists("azurerm_subnet.test"),
),
},
},
})
}

func testAccAzureRMSubnet_basic(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down Expand Up @@ -779,3 +810,31 @@ resource "azurerm_subnet" "test" {
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMSubnet_serviceEndpointsVNetUpdate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvirtnet%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
tags {
Environment = "Staging"
}
}
resource "azurerm_subnet" "test" {
name = "acctestsubnet%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"]
}
`, rInt, location, rInt, rInt)
}

0 comments on commit fb0220d

Please sign in to comment.