Skip to content

Commit

Permalink
Get the first copy backup test working
Browse files Browse the repository at this point in the history
Copy the backup into the same cluster test is working. Still need to work on copy backup for test that looks at a different cluster to get that test working.
  • Loading branch information
danieljbruce committed Jan 3, 2024
1 parent 3259115 commit 4534399
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions system-test/bigtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import {Table} from '../src/table.js';
import {RawFilter} from '../src/filter';
import {generateId, PREFIX} from './common';

function replaceProjectName(name: string): string {
return name
.split('/')
.map((item, index) => (index === 1 ? '{{projectId}}' : item))
.join('/');
}

describe.only('Bigtable', () => {

Check failure on line 38 in system-test/bigtable.ts

View workflow job for this annotation

GitHub Actions / lint

'describe.only' is restricted from being used
const bigtable = new Bigtable();
const INSTANCE = bigtable.instance(generateId('instance'));
Expand Down Expand Up @@ -139,22 +146,29 @@ describe.only('Bigtable', () => {
const id = config.backupId;
const name = config.parent.name;
const backupPath = `${config.parent.name}/backups/${id}`;
assert.strictEqual(operation?.metadata?.name, backupPath);
assert(operation);
assert(operation.metadata);
// Ensure that the backup specified by the config and id match the backup name for the operation returned by the server.
assert.strictEqual(
replaceProjectName(operation.metadata.name),
backupPath
);
// Check that there is now one more backup
const [backupsAfterCopy] = await INSTANCE.getBackups();
const newBackups = backupsAfterCopy.filter(
backup => !backupIdsBeforeCopy.includes(backup.id)
);
assert.strictEqual(newBackups.length, 1);
const [fetchedNewBackup] = newBackups;
// Ensure the fetched backup matches
assert.strictEqual(fetchedNewBackup.id, id);
assert.strictEqual(fetchedNewBackup.name, name);
assert.strictEqual(fetchedNewBackup.name, backupPath);
} catch (e) {
console.log('test');
}
}

it('should create backup of a table and copy it', async () => {
it('should create backup of a table and copy it in the same cluster', async () => {
const expireTimeEncoded = new PreciseDate(expireTime).toStruct();
const copyExpireTimeEncoded = new PreciseDate(copyExpireTime).toStruct();
const backupId = generateId('backup');
Expand Down Expand Up @@ -1330,6 +1344,9 @@ describe.only('Bigtable', () => {
const updateExpireTime = new PreciseDate(
expireTime.getTime() + 2 + 60 * 60 * 1000
);
const sourceExpireTime = new PreciseDate(
PreciseDate.now() + (8 + 300) * 60 * 60 * 1000
);
const copyExpireTime = new PreciseDate(
PreciseDate.now() + (8 + 600) * 60 * 60 * 1000
);
Expand Down Expand Up @@ -1484,46 +1501,53 @@ describe.only('Bigtable', () => {
Object.keys(policy).forEach(key => assert(key in updatedPolicy));
});
describe('copying backups', () => {
const sourceExpireTime = new PreciseDate(
PreciseDate.now() + (8 + 300) * 60 * 60 * 1000
);
const copyExpireTime = new PreciseDate(
PreciseDate.now() + (8 + 600) * 60 * 60 * 1000
);
async function testCopyBackup(backup: Backup, config: CopyBackupConfig) {
// Get a list of backup ids before the copy
const [backupsBeforeCopy] = await INSTANCE.getBackups();
const backupIdsBeforeCopy = backupsBeforeCopy.map(backup => backup.id);
// Copy the backup
const results = await backup.copy(config);
const [, operation] = results;
const [, operation] = await backup.copy(config);
await operation.promise();
assert(config.parent);
const clusterName = `${config.parent.name.replace(
'{{projectId}}',
backup.bigtable.projectId
)}`;
const id = config.backupId;
const name = config.parent.name;
const backupPath = `${config.parent.name}/backups/${id}`;
assert.strictEqual(operation?.metadata?.name, backupPath);
assert(operation);
assert(operation.metadata);
// Ensure that the backup specified by the config and id match the backup name for the operation returned by the server.
assert.strictEqual(
replaceProjectName(operation.metadata.name),
backupPath
);
// Check that there is now one more backup
const [backupsAfterCopy] = await INSTANCE.getBackups();
const newBackups = backupsAfterCopy.filter(
backup => !backupIdsBeforeCopy.includes(backup.id)
);
assert.strictEqual(newBackups.length, 1);
const [fetchedNewBackup] = newBackups;
// Ensure the fetched backup matches
assert.strictEqual(fetchedNewBackup.id, id);
assert.strictEqual(fetchedNewBackup.name, name);
assert.strictEqual(fetchedNewBackup.name, backupPath);
}

it('should create backup of a table and copy it', async () => {
const expireTimeEncoded = new PreciseDate(expireTime).toStruct();
const copyExpireTimeEncoded = new PreciseDate(
copyExpireTime
).toStruct();
const backupId = generateId('backup');
const [backup, op] = await TABLE.createBackup(backupId, {
expireTime,
expireTime: sourceExpireTime,
});
await op.promise();
await backup.getMetadata();
assert.deepStrictEqual(backup.expireDate, expireTime);
assert.deepStrictEqual(backup.expireDate, sourceExpireTime);
const newBackupId = generateId('backup');
const config = {
parent: backup.cluster,
Expand All @@ -1537,11 +1561,11 @@ describe.only('Bigtable', () => {
it('should create backup of a table and copy it on another cluster', async () => {
const backupId = generateId('backup');
const [backup, op] = await TABLE.createBackup(backupId, {
expireTime,
expireTime: sourceExpireTime,
});
await op.promise();
await backup.getMetadata();
assert.deepStrictEqual(backup.expireDate, expireTime);
assert.deepStrictEqual(backup.expireDate, sourceExpireTime);
// Create another instance
const instanceId = generateId('instance');
const instance = bigtable.instance(instanceId);
Expand Down

0 comments on commit 4534399

Please sign in to comment.