Skip to content

Refactor test files to use dynamic resource group names #483

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

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -4,8 +4,10 @@
package licensing_test

import (
"math/rand/v2"
"net/http"
"regexp"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -34,7 +36,7 @@ func TestAccBillingPoliciesEnvironmentsDataSource_Validate_Read(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "power-platform-billing-` + mocks.TestName() + strconv.Itoa(rand.IntN(9999)) + `"

body = jsonencode({
properties = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package licensing_test

import (
"math/rand/v2"
"net/http"
"regexp"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -34,7 +36,7 @@ func TestAccBillingPoliciesDataSource_Validate_Read(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "power-platform-billing-` + mocks.TestName() + strconv.Itoa(rand.IntN(9999)) + `"

body = jsonencode({
properties = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package licensing_test

import (
"fmt"
"math/rand/v2"
"net/http"
"regexp"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -35,7 +37,7 @@ func TestAccBillingPolicyResourceEnvironment_Validate_Create(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "power-platform-billing-` + mocks.TestName() + strconv.Itoa(rand.IntN(9999)) + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -122,6 +124,7 @@ func TestUnitBillingPolicyResourceEnvironment_Validate_Create(t *testing.T) {
}

func TestAccBillingPolicyResourceEnvironment_Validate_Update(t *testing.T) {
rgName := "power-platform-billing-" + mocks.TestName() + strconv.Itoa(rand.IntN(9999))
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: mocks.TestAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand All @@ -139,7 +142,7 @@ func TestAccBillingPolicyResourceEnvironment_Validate_Update(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -191,7 +194,7 @@ func TestAccBillingPolicyResourceEnvironment_Validate_Update(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -243,7 +246,7 @@ func TestAccBillingPolicyResourceEnvironment_Validate_Update(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down
24 changes: 15 additions & 9 deletions internal/services/licensing/resource_billing_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package licensing_test

import (
"fmt"
"math/rand/v2"
"net/http"
"regexp"
"strconv"
"strings"
"testing"

Expand All @@ -18,6 +20,8 @@ import (
)

func TestAccBillingPolicyResource_Validate_Create(t *testing.T) {
rgName := "power-platform-billing-" + mocks.TestName() + strconv.Itoa(rand.IntN(9999))

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: mocks.TestAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand All @@ -35,7 +39,7 @@ func TestAccBillingPolicyResource_Validate_Create(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand All @@ -57,7 +61,7 @@ func TestAccBillingPolicyResource_Validate_Create(t *testing.T) {
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "name", strings.ReplaceAll(mocks.TestName(), "_", "")),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "location", "unitedstates"),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "status", "Enabled"),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "billing_instrument.resource_group", "power-platform-billing-"+mocks.TestName()),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "billing_instrument.resource_group", rgName),
resource.TestMatchResourceAttr("powerplatform_billing_policy.pay_as_you_go", "billing_instrument.subscription_id", regexp.MustCompile(helpers.GuidRegex)),
),
},
Expand Down Expand Up @@ -120,6 +124,7 @@ func TestUnitTestBillingPolicyResource_Validate_Create(t *testing.T) {
}

func TestAccBillingPolicy_Validate_Update(t *testing.T) {
rgName := "power-platform-billing-" + mocks.TestName() + strconv.Itoa(rand.IntN(9999))
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: mocks.TestAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand All @@ -137,7 +142,7 @@ func TestAccBillingPolicy_Validate_Update(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -166,7 +171,7 @@ func TestAccBillingPolicy_Validate_Update(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -197,7 +202,7 @@ func TestAccBillingPolicy_Validate_Update(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -311,6 +316,7 @@ func TestUnitTestBillingPolicy_Validate_Update(t *testing.T) {
}

func TestAccBillingPolicy_Validate_Update_ForceRecreate(t *testing.T) {
rgName := "power-platform-billing-" + mocks.TestName() + strconv.Itoa(rand.IntN(9999))
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: mocks.TestAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand All @@ -327,7 +333,7 @@ func TestAccBillingPolicy_Validate_Update_ForceRecreate(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -355,7 +361,7 @@ func TestAccBillingPolicy_Validate_Update_ForceRecreate(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `"
name = "` + rgName + `"

body = jsonencode({
properties = {}
Expand Down Expand Up @@ -383,7 +389,7 @@ func TestAccBillingPolicy_Validate_Update_ForceRecreate(t *testing.T) {
resource "azapi_resource" "rg_example" {
type = "Microsoft.Resources/resourceGroups@2021-04-01"
location = "East US"
name = "power-platform-billing-` + mocks.TestName() + `1"
name = "` + rgName + `1"

body = jsonencode({
properties = {}
Expand All @@ -402,7 +408,7 @@ func TestAccBillingPolicy_Validate_Update_ForceRecreate(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("powerplatform_billing_policy.pay_as_you_go", "id", regexp.MustCompile(helpers.GuidRegex)),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "location", "switzerland"),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "billing_instrument.resource_group", "power-platform-billing-"+mocks.TestName()+"1"),
resource.TestCheckResourceAttr("powerplatform_billing_policy.pay_as_you_go", "billing_instrument.resource_group", rgName+"1"),
),
},
},
Expand Down
Loading