Skip to content

Commit

Permalink
move eventhub testdata into tests package
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte authored and Jack Batzner committed Dec 31, 2019
1 parent 8b258f4 commit ac32aec
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 437 deletions.
12 changes: 6 additions & 6 deletions azurerm/internal/services/eventhub/resource_arm_eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func resourceArmEventHub() *schema.Resource {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validateEventHubPartitionCount,
ValidateFunc: ValidateEventHubPartitionCount,
},

"message_retention": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validateEventHubMessageRetentionCount,
ValidateFunc: ValidateEventHubMessageRetentionCount,
},

"capture_description": {
Expand Down Expand Up @@ -123,7 +123,7 @@ func resourceArmEventHub() *schema.Resource {
"archive_name_format": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEventHubArchiveNameFormat,
ValidateFunc: ValidateEventHubArchiveNameFormat,
},
"blob_container_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -276,7 +276,7 @@ func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}

func validateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) {
func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) {
value := v.(int)

if !(32 >= value && value >= 1) {
Expand All @@ -286,7 +286,7 @@ func validateEventHubPartitionCount(v interface{}, _ string) (warnings []string,
return warnings, errors
}

func validateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) {
func ValidateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) {
value := v.(int)

if !(7 >= value && value >= 1) {
Expand All @@ -296,7 +296,7 @@ func validateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []
return warnings, errors
}

func validateEventHubArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) {
func ValidateEventHubArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)

requiredComponents := []string{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
package eventhub
package tests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
)

func TestAccDataSourceAzureRMEventHubNamespace_basic(t *testing.T) {
dataSourceName := "data.azurerm_eventhub_namespace.test"
rInt := tf.AccRandTimeInt()
location := acceptance.Location()
data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceEventHubNamespace_basic(rInt, location),
Config: testAccDataSourceEventHubNamespace_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "sku", "Basic"),
resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"),
),
},
},
})
}

func TestAccDataSourceAzureRMEventHubNamespace_complete(t *testing.T) {
dataSourceName := "data.azurerm_eventhub_namespace.test"
rInt := tf.AccRandTimeInt()
location := acceptance.Location()
data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceEventHubNamespace_complete(rInt, location),
Config: testAccDataSourceEventHubNamespace_complete(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "sku", "Standard"),
resource.TestCheckResourceAttr(dataSourceName, "capacity", "2"),
resource.TestCheckResourceAttr(dataSourceName, "auto_inflate_enabled", "true"),
resource.TestCheckResourceAttr(dataSourceName, "maximum_throughput_units", "20"),
resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"),
resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"),
resource.TestCheckResourceAttr(data.ResourceName, "auto_inflate_enabled", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "maximum_throughput_units", "20"),
),
},
},
})
}

func testAccDataSourceEventHubNamespace_basic(rInt int, location string) string {
func testAccDataSourceEventHubNamespace_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
Expand All @@ -68,10 +63,10 @@ data "azurerm_eventhub_namespace" "test" {
name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}"
}
`, rInt, location, rInt)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccDataSourceEventHubNamespace_complete(rInt int, location string) string {
func testAccDataSourceEventHubNamespace_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
Expand All @@ -92,5 +87,5 @@ data "azurerm_eventhub_namespace" "test" {
name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}"
}
`, rInt, location, rInt)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventhub
package tests

import (
"fmt"
Expand All @@ -7,7 +7,6 @@ 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/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
Expand All @@ -31,34 +30,30 @@ func TestAccAzureRMEventHubAuthorizationRule_manage(t *testing.T) {
}

func testAccAzureRMEventHubAuthorizationRule(t *testing.T, listen, send, manage bool) {
resourceName := "azurerm_eventhub_authorization_rule.test"
data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHubAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), listen, send, manage),
Config: testAccAzureRMEventHubAuthorizationRule_base(data, listen, send, manage),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubAuthorizationRuleExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "name"),
resource.TestCheckResourceAttrSet(resourceName, "namespace_name"),
resource.TestCheckResourceAttrSet(resourceName, "eventhub_name"),
resource.TestCheckResourceAttrSet(resourceName, "primary_key"),
resource.TestCheckResourceAttrSet(resourceName, "secondary_key"),
resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"),
resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"),
resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)),
resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)),
resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)),
testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"),
resource.TestCheckResourceAttr(data.ResourceName, "listen", strconv.FormatBool(listen)),
resource.TestCheckResourceAttr(data.ResourceName, "send", strconv.FormatBool(send)),
resource.TestCheckResourceAttr(data.ResourceName, "manage", strconv.FormatBool(manage)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
data.ImportStep(),
},
})
}
Expand All @@ -69,67 +64,60 @@ func TestAccAzureRMEventHubAuthorizationRule_requiresImport(t *testing.T) {
return
}

resourceName := "azurerm_eventhub_authorization_rule.test"
rInt := tf.AccRandTimeInt()

location := acceptance.Location()
data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHubAuthorizationRule_base(rInt, location, true, true, true),
Config: testAccAzureRMEventHubAuthorizationRule_base(data, true, true, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubAuthorizationRuleExists(resourceName),
testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName),
),
},
{
Config: testAccAzureRMEventHubAuthorizationRule_requiresImport(rInt, location, true, true, true),
Config: testAccAzureRMEventHubAuthorizationRule_requiresImport(data, true, true, true),
ExpectError: acceptance.RequiresImportError("azurerm_eventhub_authorization_rule"),
},
},
})
}

func TestAccAzureRMEventHubAuthorizationRule_rightsUpdate(t *testing.T) {
resourceName := "azurerm_eventhub_authorization_rule.test"
data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHubAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), true, false, false),
Config: testAccAzureRMEventHubAuthorizationRule_base(data, true, false, false),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubAuthorizationRuleExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "listen", "true"),
resource.TestCheckResourceAttr(resourceName, "send", "false"),
resource.TestCheckResourceAttr(resourceName, "manage", "false"),
testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "send", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"),
),
},
{
Config: testAccAzureRMEventHubAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), true, true, true),
Config: testAccAzureRMEventHubAuthorizationRule_base(data, true, true, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubAuthorizationRuleExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "name"),
resource.TestCheckResourceAttrSet(resourceName, "namespace_name"),
resource.TestCheckResourceAttrSet(resourceName, "primary_key"),
resource.TestCheckResourceAttrSet(resourceName, "secondary_key"),
resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"),
resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"),
resource.TestCheckResourceAttr(resourceName, "listen", "true"),
resource.TestCheckResourceAttr(resourceName, "send", "true"),
resource.TestCheckResourceAttr(resourceName, "manage", "true"),
testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"),
resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "send", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
data.ImportStep(),
},
})
}
Expand Down Expand Up @@ -190,7 +178,7 @@ func testCheckAzureRMEventHubAuthorizationRuleExists(resourceName string) resour
}
}

func testAccAzureRMEventHubAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string {
func testAccAzureRMEventHubAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
Expand Down Expand Up @@ -224,11 +212,11 @@ resource "azurerm_eventhub_authorization_rule" "test" {
send = %[4]t
manage = %[5]t
}
`, rInt, location, listen, send, manage)
`, data.RandomInteger, data.Locations.Primary, listen, send, manage)
}

func testAccAzureRMEventHubAuthorizationRule_requiresImport(rInt int, location string, listen, send, manage bool) string {
template := testAccAzureRMEventHubAuthorizationRule_base(rInt, location, listen, send, manage)
func testAccAzureRMEventHubAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string {
template := testAccAzureRMEventHubAuthorizationRule_base(data, listen, send, manage)
return fmt.Sprintf(`
%s
Expand Down
Loading

0 comments on commit ac32aec

Please sign in to comment.