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

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

Merged
merged 2 commits into from
Feb 24, 2023
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 @@ -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