Skip to content

Commit

Permalink
fix: add versionTime support when creating backup
Browse files Browse the repository at this point in the history
  • Loading branch information
skuruppu committed Feb 5, 2021
1 parent 1c1aa4f commit 57277b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type CreateBackupResponse = [
export interface CreateBackupOptions {
databasePath: string;
expireTime: string | number | p.ITimestamp | PreciseDate;
versionTime?: string | number | p.ITimestamp | PreciseDate;
gaxOptions?: CallOptions;
}

Expand Down Expand Up @@ -119,6 +120,8 @@ class Backup {
* @property {string} databasePath The database path.
* @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
* expireTime The expire time of the backup.
* @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
* versionTime Take a backup of the state of the database at this time.
* @property {CallOptions} [gaxOptions] The request configuration options
* outlined here:
* https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
Expand Down Expand Up @@ -178,6 +181,10 @@ class Backup {
name: this.formattedName_,
},
};
if ('versionTime' in options) {
reqOpts.backup!.versionTime =
Spanner.timestamp(options.versionTime).toStruct();
}
this.request(
{
client: 'DatabaseAdminClient',
Expand Down
40 changes: 40 additions & 0 deletions test/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ describe('Backup', () => {
INSTANCE.formattedName_ + '/backups/' + BACKUP_NAME;
const BACKUP_EXPIRE_TIME = '2019-02-08T10:34:29.481145231Z';
const EXP_BACKUP_EXPIRE_TIME = Spanner.timestamp(BACKUP_EXPIRE_TIME);
const BACKUP_VERSION_TIME = '2019-02-07T10:34:29.481145231Z';
const EXP_BACKUP_VERSION_TIME = Spanner.timestamp(BACKUP_VERSION_TIME);

let backup: bu.Backup;

Expand Down Expand Up @@ -232,6 +234,44 @@ describe('Backup', () => {
);
});

it('versionTime should not be set by default', done => {
const spanner_timestamp_ = Spanner.timestamp;

backup.request = config => {
assert.strictEqual(config.reqOpts.backup.versionTime, undefined);
done();
};

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

it('should make request with versionTime when provided', done => {
const spanner_timestamp_ = Spanner.timestamp;

backup.request = config => {
assert.deepStrictEqual(
config.reqOpts.backup.versionTime,
EXP_BACKUP_VERSION_TIME.toStruct()
);
done();
};

backup.create(
{
databasePath: DATABASE_FORMATTED_NAME,
expireTime: BACKUP_EXPIRE_TIME,
versionTime: BACKUP_VERSION_TIME,
},
assert.ifError
);
});

describe('error', () => {
const API_RESPONSE = {};
const REQUEST_RESPONSE_ARGS = [new Error('Error.'), null, API_RESPONSE];
Expand Down

0 comments on commit 57277b4

Please sign in to comment.