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: update masks for topic should be snake case #1778

Merged
merged 3 commits into from
Jul 26, 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
3 changes: 2 additions & 1 deletion src/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
SubscriptionOptions,
} from './subscription';
import {promisifySome} from './util';
import snakeCase = require('lodash.snakecase');

export type TopicMetadata = google.pubsub.v1.ITopic;

Expand Down Expand Up @@ -951,7 +952,7 @@ export class Topic {
callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;

const topic = Object.assign({name: this.name}, options);
const updateMask = {paths: Object.keys(options)};
const updateMask = {paths: Object.keys(options).map(snakeCase)};
const reqOpts = {topic, updateMask};

this.request<TopicMetadata>(
Expand Down
16 changes: 16 additions & 0 deletions system-test/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ describe('pubsub', () => {
);
});

it('should set metadata for a topic', async () => {
const threeDaysInSeconds = 3 * 24 * 60 * 60;

const topic = pubsub.topic(TOPIC_NAMES[0]);
await topic.setMetadata({
messageRetentionDuration: {
seconds: threeDaysInSeconds,
},
});
const [metadata] = await topic.getMetadata();
const {seconds, nanos} = metadata.messageRetentionDuration!;

assert.strictEqual(Number(seconds), threeDaysInSeconds);
assert.strictEqual(Number(nanos), 0);
});

describe('ordered messages', () => {
interface Expected {
key: string;
Expand Down
5 changes: 4 additions & 1 deletion test/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ describe('Topic', () => {
describe('setMetadata', () => {
const METADATA = {
labels: {yee: 'haw'},
messageRetentionDuration: {moo: 'cows'},
};

let requestStub: sinon.SinonStub;
Expand All @@ -691,7 +692,9 @@ describe('Topic', () => {
topic.setMetadata(METADATA, assert.ifError);

const expectedTopic = Object.assign({name: topic.name}, METADATA);
const expectedUpdateMask = {paths: ['labels']};
const expectedUpdateMask = {
paths: ['labels', 'message_retention_duration'],
};

const [{reqOpts}] = requestStub.lastCall.args;
assert.deepStrictEqual(reqOpts.topic, expectedTopic);
Expand Down