Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
adapt naming convention
adapt test structure / function
  • Loading branch information
royto committed Jan 14, 2021
1 parent 76f0987 commit 3c7935e
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 965 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func resourceArmIotHubEnrichment() *schema.Resource {
func resourceIotHubEnrichment() *schema.Resource {
return &schema.Resource{
Create: resourceArmIotHubEnrichmentCreateUpdate,
Read: resourceArmIotHubEnrichmentRead,
Expand Down
42 changes: 21 additions & 21 deletions azurerm/internal/services/iothub/iothub_enrichment_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,74 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func TestAccAzureRMIotHubEnrichment_basic(t *testing.T) {
func TestAccIotHubEnrichment_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_enrichment", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMIotHubEnrichmentDestroy,
CheckDestroy: testCheckIotHubEnrichmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHubEnrichment_basic(data),
Config: testAccIotHubEnrichment_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubEnrichmentExists(data.ResourceName),
testCheckIotHubEnrichmentExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMIotHubEnrichment_requiresImport(t *testing.T) {
func TestAccIotHubEnrichment_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_enrichment", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMIotHubEnrichmentDestroy,
CheckDestroy: testCheckIotHubEnrichmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHubEnrichment_basic(data),
Config: testAccIotHubEnrichment_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubEnrichmentExists(data.ResourceName),
testCheckIotHubEnrichmentExists(data.ResourceName),
),
},
{
Config: testAccAzureRMIotHubEnrichment_requiresImport(data),
Config: testAccIotHubEnrichment_requiresImport(data),
ExpectError: acceptance.RequiresImportError("azurerm_iothub_enrichment"),
},
},
})
}

func TestAccAzureRMIotHubEnrichment_update(t *testing.T) {
func TestAccIotHubEnrichment_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_enrichment", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMIotHubEnrichmentDestroy,
CheckDestroy: testCheckIotHubEnrichmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHubEnrichment_basic(data),
Config: testAccIotHubEnrichment_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubEnrichmentExists(data.ResourceName),
testCheckIotHubEnrichmentExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMIotHubEnrichment_update(data),
Config: testAccIotHubEnrichment_update(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubEnrichmentExists(data.ResourceName),
testCheckIotHubEnrichmentExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMIotHubEnrichmentDestroy(s *terraform.State) error {
func testCheckIotHubEnrichmentDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext

Expand Down Expand Up @@ -119,7 +119,7 @@ func testCheckAzureRMIotHubEnrichmentDestroy(s *terraform.State) error {
return nil
}

func testCheckAzureRMIotHubEnrichmentExists(resourceName string) resource.TestCheckFunc {
func testCheckIotHubEnrichmentExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -164,8 +164,8 @@ func testCheckAzureRMIotHubEnrichmentExists(resourceName string) resource.TestCh
}
}

func testAccAzureRMIotHubEnrichment_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMIotHubEnrichment_basic(data)
func testAccIotHubEnrichment_requiresImport(data acceptance.TestData) string {
template := testAccIotHubEnrichment_basic(data)
return fmt.Sprintf(`
%s
Expand All @@ -180,7 +180,7 @@ resource "azurerm_iothub_enrichment" "import" {
`, template)
}

func testAccAzureRMIotHubEnrichment_basic(data acceptance.TestData) string {
func testAccIotHubEnrichment_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -244,7 +244,7 @@ resource "azurerm_iothub_enrichment" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMIotHubEnrichment_update(data acceptance.TestData) string {
func testAccIotHubEnrichment_update(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down
126 changes: 126 additions & 0 deletions azurerm/internal/services/iothub/iothub_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ func TestAccIotHub_customRoutes(t *testing.T) {
})
}

func TestAccIotHub_enrichments(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub", "test")
r := IotHubResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.enrichments(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("endpoint.#").HasValue("2"),
check.That(data.ResourceName).Key("endpoint.0.type").HasValue("AzureIotHub.StorageContainer"),
check.That(data.ResourceName).Key("endpoint.1.type").HasValue("AzureIotHub.EventHub"),
check.That(data.ResourceName).Key("route.#").HasValue("1"),
check.That(data.ResourceName).Key("enrichment.#").HasValue("2"),
),
},
data.ImportStep(),
})
}

func TestAccIotHub_removeEndpointsAndRoutes(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub", "test")
r := IotHubResource{}
Expand Down Expand Up @@ -450,6 +469,113 @@ resource "azurerm_iothub" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger)
}

func (IotHubResource) enrichments(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "acctestsa%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_container" "test" {
name = "test"
storage_account_name = azurerm_storage_account.test.name
container_access_type = "private"
}
resource "azurerm_eventhub_namespace" "test" {
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
name = "acctest-%d"
sku = "Basic"
}
resource "azurerm_eventhub" "test" {
name = "acctest"
resource_group_name = azurerm_resource_group.test.name
namespace_name = azurerm_eventhub_namespace.test.name
partition_count = 2
message_retention = 1
}
resource "azurerm_eventhub_authorization_rule" "test" {
resource_group_name = azurerm_resource_group.test.name
namespace_name = azurerm_eventhub_namespace.test.name
eventhub_name = azurerm_eventhub.test.name
name = "acctest"
send = true
}
resource "azurerm_iothub" "test" {
name = "acctestIoTHub-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku {
name = "S1"
capacity = "1"
}
event_hub_retention_in_days = 7
event_hub_partition_count = 77
endpoint {
type = "AzureIotHub.StorageContainer"
connection_string = azurerm_storage_account.test.primary_blob_connection_string
name = "export"
batch_frequency_in_seconds = 60
max_chunk_size_in_bytes = 10485760
container_name = azurerm_storage_container.test.name
encoding = "Avro"
file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"
resource_group_name = azurerm_resource_group.test.name
}
endpoint {
type = "AzureIotHub.EventHub"
connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string
name = "export2"
resource_group_name = azurerm_resource_group.test.name
}
route {
name = "export"
source = "DeviceMessages"
condition = "true"
endpoint_names = ["export"]
enabled = true
}
enrichment {
key = "enrichment"
value = "$twin.tags.Tenant"
endpoint_names = ["export2"]
}
enrichment {
key = "enrichment2"
value = "Multiple endpoint"
endpoint_names = ["export", "export2"]
}
tags = {
purpose = "testing"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger)
}

func (IotHubResource) removeEndpointsAndRoutes(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/services/iothub/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource {
"azurerm_iothub_consumer_group": resourceIotHubConsumerGroup(),
"azurerm_iothub": resourceIotHub(),
"azurerm_iothub_fallback_route": resourceIotHubFallbackRoute(),
"azurerm_iothub_enrichment": resourceIotHubEnrichment(),
"azurerm_iothub_route": resourceIotHubRoute(),
"azurerm_iothub_endpoint_eventhub": resourceIotHubEndpointEventHub(),
"azurerm_iothub_endpoint_servicebus_queue": resourceIotHubEndpointServiceBusQueue(),
Expand Down
Loading

0 comments on commit 3c7935e

Please sign in to comment.