Skip to content

Commit

Permalink
hashicorp#2047 add acc test for ACR geo replication
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorioland committed Oct 11, 2018
1 parent 40e8e7b commit 60b8704
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions azurerm/resource_arm_container_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azurerm
import (
"fmt"
"net/http"
"strings"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
Expand Down Expand Up @@ -221,6 +222,27 @@ func TestAccAzureRMContainerRegistry_update(t *testing.T) {
})
}

func TestAccAzureRMContainerRegistry_geoReplication(t *testing.T) {
ri := acctest.RandInt()
georeplicationLocations := []string{"\"eastus\"", "\"westus\""}
config := testAccAzureRMContainerRegistry_geoReplication(ri, testLocation(), "Premium", strings.Join(georeplicationLocations[:], ","))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMContainerRegistryDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMContainerRegistryExists("azurerm_container_registry.test"),
testCheckAzureRMContainerRegistryGeoreplicationExists("azurerm_container_registry.test", georeplicationLocations),
),
},
},
})
}

func testCheckAzureRMContainerRegistryDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).containerRegistryClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
Expand Down Expand Up @@ -276,6 +298,38 @@ func testCheckAzureRMContainerRegistryExists(name string) resource.TestCheckFunc
}
}

func testCheckAzureRMContainerRegistryGeoreplicationExists(name string, locations []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

name := rs.Primary.Attributes["name"]
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
if !hasResourceGroup {
return fmt.Errorf("Bad: no resource group found in state for Container Registry: %s", name)
}

conn := testAccProvider.Meta().(*ArmClient).containerRegistryReplicationsClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

resp, err := conn.List(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Bad: Get on containerRegistryClient: %+v", err)
}

georeplicationValues := resp.Values()

if georeplicationValues == nil {
return fmt.Errorf("Bad: Container Registry %q (resource group: %q) has not been configured for geo-replication", name, resourceGroup)
}

return nil
}
}

func testAccAzureRMContainerRegistry_basicManaged(rInt int, location string, sku string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down Expand Up @@ -376,3 +430,21 @@ resource "azurerm_container_registry" "test" {
}
`, rInt, location, rStr, rInt)
}

func testAccAzureRMContainerRegistry_geoReplication(rInt int, location string, sku string, georeplicationLocations string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "testAccRg-%d"
location = "%s"
}
resource "azurerm_container_registry" "test" {
name = "testacccr%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
sku = "%s"
georeplication_enabled = true
georeplication_locations = [%s]
}
`, rInt, location, rInt, sku, georeplicationLocations)
}

0 comments on commit 60b8704

Please sign in to comment.