Skip to content

Commit

Permalink
Move more billing tests that require permissions beyond Billing User …
Browse files Browse the repository at this point in the history
…to master billing account (GoogleCloudPlatform#7344)

* Move more billing tests that require permissions beyond Billing User to master billing account

* Add comments to clarify billing account usage
  • Loading branch information
roaks3 authored and kubalaguna committed Feb 27, 2023
1 parent 07fd7d3 commit e56d387
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestAccDataSourceGoogleBillingAccount_byFullName(t *testing.T) {
billingId := getTestBillingAccountFromEnv(t)
billingId := getTestMasterBillingAccountFromEnv(t)
name := "billingAccounts/" + billingId

vcrTest(t, resource.TestCase{
Expand All @@ -29,7 +29,7 @@ func TestAccDataSourceGoogleBillingAccount_byFullName(t *testing.T) {
}

func TestAccDataSourceGoogleBillingAccount_byShortName(t *testing.T) {
billingId := getTestBillingAccountFromEnv(t)
billingId := getTestMasterBillingAccountFromEnv(t)
name := "billingAccounts/" + billingId

vcrTest(t, resource.TestCase{
Expand All @@ -49,7 +49,7 @@ func TestAccDataSourceGoogleBillingAccount_byShortName(t *testing.T) {
}

func TestAccDataSourceGoogleBillingAccount_byFullNameClosed(t *testing.T) {
billingId := getTestBillingAccountFromEnv(t)
billingId := getTestMasterBillingAccountFromEnv(t)
name := "billingAccounts/" + billingId

vcrTest(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func TestAccProject_create(t *testing.T) {
func TestAccProject_billing(t *testing.T) {
t.Parallel()
org := getTestOrgFromEnv(t)
// This is a second billing account that can be charged, which is used only in this test to
// verify that a project can update its billing account.
skipIfEnvNotSet(t, "GOOGLE_BILLING_ACCOUNT_2")
billingId2 := os.Getenv("GOOGLE_BILLING_ACCOUNT_2")
billingId := getTestBillingAccountFromEnv(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestAccLoggingBucketConfigBillingAccount_basic(t *testing.T) {

context := map[string]interface{}{
"random_suffix": randString(t, 10),
"billing_account_name": "billingAccounts/" + getTestBillingAccountFromEnv(t),
"billing_account_name": "billingAccounts/" + getTestMasterBillingAccountFromEnv(t),
"org_id": getTestOrgFromEnv(t),
}

Expand Down
8 changes: 8 additions & 0 deletions mmv1/third_party/terraform/utils/provider_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ var orgTargetEnvVars = []string{
"GOOGLE_ORG_2",
}

// This is the billing account that will be charged for the infrastructure used during testing. For
// that reason, it is also the billing account used for creating new projects.
var billingAccountEnvVars = []string{
"GOOGLE_BILLING_ACCOUNT",
}
Expand All @@ -118,6 +120,8 @@ type VcrSource struct {

var sources map[string]VcrSource

// This is the billing account that will be modified to test billing-related functionality. It is
// expected to have more permissions granted to the test user and support subaccounts.
var masterBillingAccountEnvVars = []string{
"GOOGLE_MASTER_BILLING_ACCOUNT",
}
Expand Down Expand Up @@ -838,11 +842,15 @@ func getTestOrgTargetFromEnv(t *testing.T) string {
return MultiEnvSearch(orgTargetEnvVars)
}

// This is the billing account that will be charged for the infrastructure used during testing. For
// that reason, it is also the billing account used for creating new projects.
func getTestBillingAccountFromEnv(t *testing.T) string {
skipIfEnvNotSet(t, billingAccountEnvVars...)
return MultiEnvSearch(billingAccountEnvVars)
}

// This is the billing account that will be modified to test billing-related functionality. It is
// expected to have more permissions granted to the test user and support subaccounts.
func getTestMasterBillingAccountFromEnv(t *testing.T) string {
skipIfEnvNotSet(t, masterBillingAccountEnvVars...)
return MultiEnvSearch(masterBillingAccountEnvVars)
Expand Down

0 comments on commit e56d387

Please sign in to comment.