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

fix: [billing] fixed resource_reference for name in GetProjectBillingInfo #4619

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