Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/healthcare_service: fixing the tests #5202

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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