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

feat(default_retention_period): Changes to backup.create API to suppo… #1873

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 6 additions & 2 deletions src/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type CreateBackupResponse = [

export interface CreateBackupOptions {
databasePath: string;
expireTime: string | number | p.ITimestamp | PreciseDate;
expireTime?: string | number | p.ITimestamp | PreciseDate;
versionTime?: string | number | p.ITimestamp | PreciseDate;
encryptionConfig?: databaseAdmin.spanner.admin.database.v1.ICreateBackupEncryptionConfig;
gaxOptions?: CallOptions;
Expand Down Expand Up @@ -225,10 +225,14 @@ class Backup {
backupId: this.id,
backup: {
database: options.databasePath,
expireTime: Spanner.timestamp(options.expireTime).toStruct(),
name: this.formattedName_,
},
};
if ('expireTime' in options) {
reqOpts.backup!.expireTime = Spanner.timestamp(
options.expireTime
).toStruct();
}
if ('versionTime' in options) {
reqOpts.backup!.versionTime = Spanner.timestamp(
options.versionTime
Expand Down
31 changes: 31 additions & 0 deletions test/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,37 @@ describe('Backup', () => {
);
});

it('should accept null expire time', done => {
const QUERY = {};
const ORIGINAL_QUERY = extend({}, QUERY);
const expectedReqOpts = extend({}, QUERY, {
parent: INSTANCE_NAME,
backupId: BACKUP_NAME,
backup: {
name: BACKUP_FORMATTED_NAME,
database: DATABASE_FORMATTED_NAME,
},
});

backup.request = config => {
assert.strictEqual(config.client, 'DatabaseAdminClient');
assert.strictEqual(config.method, 'createBackup');
assert.deepStrictEqual(config.reqOpts, expectedReqOpts);

assert.notStrictEqual(config.reqOpts, QUERY);
assert.deepStrictEqual(QUERY, ORIGINAL_QUERY);
assert.deepStrictEqual(config.headers, backup.resourceHeader_);
done();
};

backup.create(
{
databasePath: DATABASE_FORMATTED_NAME,
},
assert.ifError
);
});

it('should accept gaxOptions and a callback', done => {
const gaxOptions = {
timeout: 1000,
Expand Down
Loading