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

Contributor Docs - simplify test config names in new resource guide #28241

Merged
merged 4 commits into from
Dec 11, 2024
Merged
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
66 changes: 39 additions & 27 deletions contributing/topics/guide-new-resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,46 +681,58 @@ In Go tests are expected to be in a file name in the format `{original_file_name
package resource_test

import (
"context"
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"context"
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type ResourceGroupExampleTestResource struct{}

func TestAccResourceGroupExample_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_resource_group_example", "test")
testResource := ResourceGroupExampleTestResource{}
data.ResourceTest(t, testResource, []acceptance.TestStep{
data.ApplyStep(testResource.basicConfig, testResource),
r := ResourceGroupExampleTestResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r)
),
},
data.ImportStep(),
})
}

func TestAccResourceGroupExample_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_resource_group_example", "test")
testResource := ResourceGroupExampleTestResource{}
data.ResourceTest(t, testResource, []acceptance.TestStep{
data.ApplyStep(testResource.basicConfig, testResource),
data.RequiresImportErrorStep(testResource.requiresImportConfig),
r := ResourceGroupExampleTestResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
ExpectError: acceptance.RequiresImportError("azurerm_resource_group_example"),
},
})
}

func TestAccResourceGroupExample_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_resource_group_example", "test")
testResource := ResourceGroupExampleTestResource{}
data.ResourceTest(t, testResource, []acceptance.TestStep{
data.ApplyStep(testResource.completeConfig, testResource),
data.ImportStep(),
data.ApplyStep(testResource.basicConfig, testResource),
data.ImportStep(),
data.ApplyStep(testResource.completeConfig, testResource),
r := ResourceGroupExampleTestResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r)
),
},
data.ImportStep(),
})
}
Expand All @@ -739,7 +751,7 @@ func (ResourceGroupExampleTestResource) Exists(ctx context.Context, client *clie
return pointer.To(resp.Model != nil), nil
}

func (ResourceGroupExampleTestResource) basicConfig(data acceptance.TestData) string {
func (ResourceGroupExampleTestResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -752,8 +764,8 @@ resource "azurerm_resource_group_example" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (r ResourceGroupExampleTestResource) requiresImportConfig(data acceptance.TestData) string {
template := r.basicConfig(data)
func (r ResourceGroupExampleTestResource) requiresImport(data acceptance.TestData) string {
template := r.basic(data)
return fmt.Sprintf(`
%s

Expand All @@ -764,7 +776,7 @@ resource "azurerm_resource_group_example" "import" {
`, template)
}

func (ResourceGroupExampleTestResource) completeConfig(data acceptance.TestData) string {
func (ResourceGroupExampleTestResource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down
Loading