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

Test Shim: API Management #9999

Merged
merged 3 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,57 @@ import (

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

type ApiManagementApiDataSourceResource struct {
}

func TestAccDataSourceAzureRMApiManagementApi_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_api_management_api", "test")
r := ApiManagementApiDataSourceResource{}

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceApiManagementApi_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "display_name", "api1"),
resource.TestCheckResourceAttr(data.ResourceName, "path", "api1"),
resource.TestCheckResourceAttr(data.ResourceName, "protocols.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "protocols.0", "https"),
resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"),
),
},
data.DataSourceTest(t, []resource.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("display_name").HasValue("api1"),
check.That(data.ResourceName).Key("path").HasValue("api1"),
check.That(data.ResourceName).Key("protocols.#").HasValue("1"),
check.That(data.ResourceName).Key("protocols.0").HasValue("https"),
check.That(data.ResourceName).Key("soap_pass_through").HasValue("false"),
check.That(data.ResourceName).Key("subscription_required").HasValue("false"),
check.That(data.ResourceName).Key("is_current").HasValue("true"),
check.That(data.ResourceName).Key("is_online").HasValue("false"),
),
},
})
}

func TestAccDataSourceAzureRMApiManagementApi_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_api_management_api", "test")
r := ApiManagementApiDataSourceResource{}

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceApiManagementApi_complete(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Butter Parser"),
resource.TestCheckResourceAttr(data.ResourceName, "path", "butter-parser"),
resource.TestCheckResourceAttr(data.ResourceName, "protocols.#", "2"),
resource.TestCheckResourceAttr(data.ResourceName, "description", "What is my purpose? You parse butter."),
resource.TestCheckResourceAttr(data.ResourceName, "service_url", "https://example.com/foo/bar"),
resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_key_parameter_names.0.header", "X-Butter-Robot-API-Key"),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_key_parameter_names.0.query", "location"),
resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"),
),
},
data.DataSourceTest(t, []resource.TestStep{
{
Config: r.complete(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("display_name").HasValue("Butter Parser"),
check.That(data.ResourceName).Key("path").HasValue("butter-parser"),
check.That(data.ResourceName).Key("protocols.#").HasValue("2"),
check.That(data.ResourceName).Key("description").HasValue("What is my purpose? You parse butter."),
check.That(data.ResourceName).Key("service_url").HasValue("https://example.com/foo/bar"),
check.That(data.ResourceName).Key("soap_pass_through").HasValue("false"),
check.That(data.ResourceName).Key("subscription_key_parameter_names.0.header").HasValue("X-Butter-Robot-API-Key"),
check.That(data.ResourceName).Key("subscription_key_parameter_names.0.query").HasValue("location"),
check.That(data.ResourceName).Key("is_current").HasValue("true"),
check.That(data.ResourceName).Key("is_online").HasValue("false"),
),
},
})
}

func testAccDataSourceApiManagementApi_basic(data acceptance.TestData) string {
template := testAccAzureRMApiManagementApi_basic(data)
func (r ApiManagementApiDataSourceResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

Expand All @@ -69,11 +66,10 @@ data "azurerm_api_management_api" "test" {
resource_group_name = azurerm_api_management_api.test.resource_group_name
revision = azurerm_api_management_api.test.revision
}
`, template)
`, ApiManagementApiResource{}.basic(data))
}

func testAccDataSourceApiManagementApi_complete(data acceptance.TestData) string {
template := testAccAzureRMApiManagementApi_complete(data)
func (r ApiManagementApiDataSourceResource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

Expand All @@ -83,5 +79,5 @@ data "azurerm_api_management_api" "test" {
resource_group_name = azurerm_api_management_api.test.resource_group_name
revision = azurerm_api_management_api.test.revision
}
`, template)
`, ApiManagementApiResource{}.complete(data))
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func resourceArmApiManagementApiDiagnostic() *schema.Resource {
func resourceApiManagementApiDiagnostic() *schema.Resource {
return &schema.Resource{
Create: resourceArmApiManagementApiDiagnosticCreateUpdate,
Read: resourceArmApiManagementApiDiagnosticRead,
Update: resourceArmApiManagementApiDiagnosticCreateUpdate,
Delete: resourceArmApiManagementApiDiagnosticDelete,
Create: resourceApiManagementApiDiagnosticCreateUpdate,
Read: resourceApiManagementApiDiagnosticRead,
Update: resourceApiManagementApiDiagnosticCreateUpdate,
Delete: resourceApiManagementApiDiagnosticDelete,

Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error {
_, err := parse.ApiDiagnosticID(id)
Expand Down Expand Up @@ -95,18 +95,18 @@ func resourceArmApiManagementApiDiagnostic() *schema.Resource {
}, false),
},

"frontend_request": resourceArmApiManagementApiDiagnosticAdditionalContentSchema(),
"frontend_request": resourceApiManagementApiDiagnosticAdditionalContentSchema(),

"frontend_response": resourceArmApiManagementApiDiagnosticAdditionalContentSchema(),
"frontend_response": resourceApiManagementApiDiagnosticAdditionalContentSchema(),

"backend_request": resourceArmApiManagementApiDiagnosticAdditionalContentSchema(),
"backend_request": resourceApiManagementApiDiagnosticAdditionalContentSchema(),

"backend_response": resourceArmApiManagementApiDiagnosticAdditionalContentSchema(),
"backend_response": resourceApiManagementApiDiagnosticAdditionalContentSchema(),
},
}
}

func resourceArmApiManagementApiDiagnosticAdditionalContentSchema() *schema.Schema {
func resourceApiManagementApiDiagnosticAdditionalContentSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Expand All @@ -132,7 +132,7 @@ func resourceArmApiManagementApiDiagnosticAdditionalContentSchema() *schema.Sche
}
}

func resourceArmApiManagementApiDiagnosticCreateUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceApiManagementApiDiagnosticCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.ApiDiagnosticClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -228,10 +228,10 @@ func resourceArmApiManagementApiDiagnosticCreateUpdate(d *schema.ResourceData, m
}
d.SetId(*resp.ID)

return resourceArmApiManagementApiDiagnosticRead(d, meta)
return resourceApiManagementApiDiagnosticRead(d, meta)
}

func resourceArmApiManagementApiDiagnosticRead(d *schema.ResourceData, meta interface{}) error {
func resourceApiManagementApiDiagnosticRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.ApiDiagnosticClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -281,7 +281,7 @@ func resourceArmApiManagementApiDiagnosticRead(d *schema.ResourceData, meta inte
return nil
}

func resourceArmApiManagementApiDiagnosticDelete(d *schema.ResourceData, meta interface{}) error {
func resourceApiManagementApiDiagnosticDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.ApiDiagnosticClient
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down
Loading