Skip to content

Commit

Permalink
Merge pull request #5202 from terraform-providers/b/healthcare-tests
Browse files Browse the repository at this point in the history
r/healthcare_service: fixing the tests
  • Loading branch information
tombuildsstuff authored Dec 18, 2019
2 parents ab6dd82 + 8c5f328 commit 286626f
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 17 deletions.
10 changes: 6 additions & 4 deletions azurerm/data_source_healthcare_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

func TestAccAzureRMDataSourceHealthcareService_basic(t *testing.T) {
func TestAccAzureRMDataSourceHealthCareService_basic(t *testing.T) {
dataSourceName := "data.azurerm_healthcare_service.test"
ri := tf.AccRandTimeInt() / 10
location := testLocation()
// currently only supported in "ukwest", "northcentralus", "westus2".
location := "westus2"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMHealthcareServiceDestroy,
CheckDestroy: testCheckAzureRMHealthCareServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMDataSourceHealthcareService_basic(ri, location),
Expand All @@ -33,7 +35,7 @@ func TestAccAzureRMDataSourceHealthcareService_basic(t *testing.T) {
}

func testAccAzureRMDataSourceHealthcareService_basic(rInt int, location string) string {
resource := testAccAzureRMHealthcareService_basic(rInt)
resource := testAccAzureRMHealthCareService_basic(rInt, location)
return fmt.Sprintf(`
%s
Expand Down
1 change: 1 addition & 0 deletions azurerm/resource_arm_healthcare_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func resourceArmHealthcareService() *schema.Resource {
"authentication_configuration": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
119 changes: 106 additions & 13 deletions azurerm/resource_arm_healthcare_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,77 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
)

func TestAccAzureRMHealthcareService_basic(t *testing.T) {
func TestAccAzureRMHealthCareService_basic(t *testing.T) {
ri := tf.AccRandTimeInt() / 10
// currently only supported in "ukwest", "northcentralus", "westus2".
location := "westus2"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMHealthCareServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMHealthCareService_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHealthCareServiceExists("azurerm_healthcare_service.test"),
),
},
{
ResourceName: "azurerm_healthcare_service.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMHealthCareService_requiresImport(t *testing.T) {
if !features.ShouldResourcesBeImported() {
t.Skip("Skipping since resources aren't required to be imported")
return
}

ri := tf.AccRandTimeInt() / 10
// currently only supported in "ukwest", "northcentralus", "westus2".
location := "westus2"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMHealthCareServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMHealthCareService_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHealthCareServiceExists("azurerm_healthcare_service.test"),
),
},
{
Config: testAccAzureRMHealthCareService_requiresImport(ri, location),
ExpectError: testRequiresImportError("azurerm_healthcare_service"),
},
},
})
}

func TestAccAzureRMHealthCareService_complete(t *testing.T) {
ri := tf.AccRandTimeInt() / 10
// currently only supported in "ukwest", "northcentralus", "westus2".
location := "westus2"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMHealthcareServiceDestroy,
CheckDestroy: testCheckAzureRMHealthCareServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMHealthcareService_basic(ri),
Config: testAccAzureRMHealthCareService_complete(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHealthcareServiceExists("azurerm_healthcare_service.test"),
testCheckAzureRMHealthCareServiceExists("azurerm_healthcare_service.test"),
),
},
{
Expand All @@ -33,7 +90,7 @@ func TestAccAzureRMHealthcareService_basic(t *testing.T) {
})
}

func testCheckAzureRMHealthcareServiceExists(resourceName string) resource.TestCheckFunc {
func testCheckAzureRMHealthCareServiceExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
Expand Down Expand Up @@ -62,7 +119,7 @@ func testCheckAzureRMHealthcareServiceExists(resourceName string) resource.TestC
}
}

func testCheckAzureRMHealthcareServiceDestroy(s *terraform.State) error {
func testCheckAzureRMHealthCareServiceDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).HealthCare.HealthcareServiceClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

Expand All @@ -87,9 +144,45 @@ func testCheckAzureRMHealthcareServiceDestroy(s *terraform.State) error {
return nil
}

func testAccAzureRMHealthcareService_basic(rInt int) string {
// currently only supported in "ukwest", "northcentralus", "westus2".
location := "westus2"
func testAccAzureRMHealthCareService_basic(rInt int, location string) string {
return fmt.Sprintf(`
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "test" {
name = "acctestRG-health-%d"
location = "%s"
}
resource "azurerm_healthcare_service" "test" {
name = "testacc%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
access_policy_object_ids = [
"${data.azurerm_client_config.current.service_principal_object_id}",
]
}
`, rInt, location, rInt)
}

func testAccAzureRMHealthCareService_requiresImport(rInt int, location string) string {
template := testAccAzureRMHealthCareService_basic(rInt, location)
return fmt.Sprintf(`
%s
resource "azurerm_healthcare_service" "import" {
name = azurerm_healthcare_service.test.name
location = azurerm_healthcare_service.test.location
resource_group_name = azurerm_healthcare_service.test.resource_group_name
access_policy_object_ids = [
"${data.azurerm_client_config.current.service_principal_object_id}",
]
}
`, template)
}

func testAccAzureRMHealthCareService_complete(rInt int, location string) string {
return fmt.Sprintf(`
data "azurerm_client_config" "current" {}
Expand All @@ -115,15 +208,15 @@ resource "azurerm_healthcare_service" "test" {
authentication_configuration {
authority = "https://login.microsoftonline.com/${data.azurerm_client_config.current.tenant_id}"
audience = "https://azurehealthcareapis.com"
smart_proxy_enabled = "true"
smart_proxy_enabled = true
}
cors_configuration {
allowed_origins = ["http://www.example.com", "http://www.example2.com"]
allowed_headers = ["x-tempo-*", "x-tempo2-*"]
allowed_headers = ["*"]
allowed_methods = ["GET", "PUT"]
max_age_in_seconds = "500"
allow_credentials = "true"
max_age_in_seconds = 500
allow_credentials = true
}
}
`, rInt, location, rInt)
Expand Down

0 comments on commit 286626f

Please sign in to comment.