Skip to content

Commit 64461a2

Browse files
authored
fix: billing budget tests (#594)
1 parent d9bd377 commit 64461a2

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

test/fixtures/budget/outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ output "project_id" {
1919
value = module.budget.project_id
2020
}
2121

22+
output "billing_account" {
23+
description = "The billing account where budgets are created"
24+
value = var.billing_account
25+
}
26+
2227
output "parent_project_id" {
2328
description = "The project_id of the parent project to add as an additional project for the budget"
2429
value = module.budget.parent_project_id

test/integration/budget/controls/budget.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
project_id = attribute("project_id")
16+
billing_account = attribute("billing_account")
1617
parent_project_id = attribute("parent_project_id")
1718
pubsub_topic = attribute("pubsub_topic")
1819
main_budget_name = attribute("main_budget_name")
@@ -45,8 +46,7 @@
4546
control "project-factory-budget-main" do
4647
title "Main Budget"
4748

48-
# Budgets is only available via rest api currently
49-
describe command("curl -s -X GET -H \"Authorization: Bearer \"`gcloud auth print-access-token` https://billingbudgets.googleapis.com/v1beta1/#{main_budget_name}") do
49+
describe command("gcloud alpha billing budgets describe #{main_budget_name} --billing-account=#{billing_account} --format=json") do
5050
its("exit_status") { should be 0 }
5151
its("stderr") { should eq "" }
5252

@@ -60,7 +60,7 @@
6060

6161
it "has expected structure" do
6262
expect(metadata).to match(hash_including({
63-
name: main_budget_name,
63+
name: "billingAccounts/#{billing_account}/budgets/#{main_budget_name}",
6464
displayName: "Budget For #{project_id}",
6565
budgetFilter: hash_including({creditTypesTreatment: "INCLUDE_ALL_CREDITS"}),
6666
amount: hash_including({specifiedAmount: hash_including({units: "#{budget_amount}"})}),
@@ -78,8 +78,7 @@
7878
control "project-factory-budget-additional" do
7979
title "Additional Budget"
8080

81-
# Budgets is only available via rest api currently
82-
describe command("curl -s -X GET -H \"Authorization: Bearer \"`gcloud auth print-access-token` https://billingbudgets.googleapis.com/v1beta1/#{additional_budget_name}") do
81+
describe command("gcloud alpha billing budgets describe #{additional_budget_name} --billing-account=#{billing_account} --format=json") do
8382
its("exit_status") { should be 0 }
8483
its("stderr") { should eq "" }
8584

@@ -93,7 +92,7 @@
9392

9493
it "has expected structure" do
9594
expect(metadata).to match(hash_including({
96-
name: additional_budget_name,
95+
name: "billingAccounts/#{billing_account}/budgets/#{additional_budget_name}",
9796
displayName: "CI/CD Budget for #{project_id}",
9897
budgetFilter: hash_including({creditTypesTreatment: budget_credit_types_treatment}),
9998
amount: hash_including({specifiedAmount: hash_including({units: "#{budget_amount}"})}),

test/integration/budget/inspec.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ attributes:
33
- name: project_id
44
required: true
55

6+
- name: billing_account
7+
required: true
8+
69
- name: parent_project_id
710
required: true
811

0 commit comments

Comments
 (0)