Skip to content

Commit

Permalink
fix: billing budget tests (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
bharathkkb authored Jun 11, 2021
1 parent d9bd377 commit 64461a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/budget/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ output "project_id" {
value = module.budget.project_id
}

output "billing_account" {
description = "The billing account where budgets are created"
value = var.billing_account
}

output "parent_project_id" {
description = "The project_id of the parent project to add as an additional project for the budget"
value = module.budget.parent_project_id
Expand Down
11 changes: 5 additions & 6 deletions test/integration/budget/controls/budget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

project_id = attribute("project_id")
billing_account = attribute("billing_account")
parent_project_id = attribute("parent_project_id")
pubsub_topic = attribute("pubsub_topic")
main_budget_name = attribute("main_budget_name")
Expand Down Expand Up @@ -45,8 +46,7 @@
control "project-factory-budget-main" do
title "Main Budget"

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

Expand All @@ -60,7 +60,7 @@

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

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

Expand All @@ -93,7 +92,7 @@

it "has expected structure" do
expect(metadata).to match(hash_including({
name: additional_budget_name,
name: "billingAccounts/#{billing_account}/budgets/#{additional_budget_name}",
displayName: "CI/CD Budget for #{project_id}",
budgetFilter: hash_including({creditTypesTreatment: budget_credit_types_treatment}),
amount: hash_including({specifiedAmount: hash_including({units: "#{budget_amount}"})}),
Expand Down
3 changes: 3 additions & 0 deletions test/integration/budget/inspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ attributes:
- name: project_id
required: true

- name: billing_account
required: true

- name: parent_project_id
required: true

Expand Down

0 comments on commit 64461a2

Please sign in to comment.