Skip to content

Commit

Permalink
fix: [billing] fixed resource_reference for name in GetProjectBilling…
Browse files Browse the repository at this point in the history
…Info (#4619)

* fix: fixed resource_reference for name in GetProjectBillingInfo

PiperOrigin-RevId: 563189185

Source-Link: googleapis/googleapis@4967815

Source-Link: googleapis/googleapis-gen@9f06f3e
Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWJpbGxpbmcvLk93bEJvdC55YW1sIiwiaCI6IjlmMDZmM2UwYmMwZTE2NjYyYTI2NGUzZGRjMmVmMzliZjdhZDkzZWMifQ==

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Sep 7, 2023
1 parent 083c352 commit 9bcc6c6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ message GetProjectBillingInfoRequest {
string name = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = {
type: "cloudbilling.googleapis.com/ProjectBillingInfo"
type: "cloudresourcemanager.googleapis.com/Project"
}
];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-billing/protos/protos.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions packages/google-cloud-billing/src/v1/cloud_billing_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ export class CloudBillingClient {
billingAccountPathTemplate: new this._gaxModule.PathTemplate(
'billingAccounts/{billing_account}'
),
projectPathTemplate: new this._gaxModule.PathTemplate(
'projects/{project}'
),
projectBillingInfoPathTemplate: new this._gaxModule.PathTemplate(
'projects/{project}/billingInfo'
),
Expand Down Expand Up @@ -1598,6 +1601,29 @@ export class CloudBillingClient {
).billing_account;
}

/**
* Return a fully-qualified project resource name string.
*
* @param {string} project
* @returns {string} Resource name string.
*/
projectPath(project: string) {
return this.pathTemplates.projectPathTemplate.render({
project: project,
});
}

/**
* Parse the project from Project resource.
*
* @param {string} projectName
* A fully-qualified path representing Project resource.
* @returns {string} A string representing the project.
*/
matchProjectFromProjectName(projectName: string) {
return this.pathTemplates.projectPathTemplate.match(projectName).project;
}

/**
* Return a fully-qualified projectBillingInfo resource name string.
*
Expand Down
38 changes: 38 additions & 0 deletions packages/google-cloud-billing/test/gapic_cloud_billing_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,44 @@ describe('v1.CloudBillingClient', () => {
});
});

describe('project', () => {
const fakePath = '/rendered/path/project';
const expectedParameters = {
project: 'projectValue',
};
const client = new cloudbillingModule.v1.CloudBillingClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
client.pathTemplates.projectPathTemplate.render = sinon
.stub()
.returns(fakePath);
client.pathTemplates.projectPathTemplate.match = sinon
.stub()
.returns(expectedParameters);

it('projectPath', () => {
const result = client.projectPath('projectValue');
assert.strictEqual(result, fakePath);
assert(
(client.pathTemplates.projectPathTemplate.render as SinonStub)
.getCall(-1)
.calledWith(expectedParameters)
);
});

it('matchProjectFromProjectName', () => {
const result = client.matchProjectFromProjectName(fakePath);
assert.strictEqual(result, 'projectValue');
assert(
(client.pathTemplates.projectPathTemplate.match as SinonStub)
.getCall(-1)
.calledWith(fakePath)
);
});
});

describe('projectBillingInfo', () => {
const fakePath = '/rendered/path/projectBillingInfo';
const expectedParameters = {
Expand Down

0 comments on commit 9bcc6c6

Please sign in to comment.