Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wahaj Shamim committed Aug 23, 2017
2 parents 7b39111 + 0be63e5 commit c7149cd
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 33 deletions.
170 changes: 142 additions & 28 deletions src/tests/backup-restore/parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@
*/

import assert from 'assert';
import _ from 'lodash';
import {generateMongoData, getRandomPort, killMongoInstance, launchSingleInstance} from 'test-utils';
import ConnectionProfile from '../pageObjects/Connection';
import BackupRestore, {ParameterName, TreeActions} from '../pageObjects/BackupRestore';
import TreeAction from '../pageObjects/TreeAction';
import Editor from '../pageObjects/Editor';

import {config, getApp} from '../helpers';

describe('backup restore test suite', () => {
config();
config({initStateStore: true});
let mongoPort;
let connectProfile;
let browser;
let bkRestore;
let app;
let dumpDbName;
let tree;
let editor;

const cleanup = () => {
killMongoInstance(mongoPort);
Expand All @@ -61,6 +62,7 @@ describe('backup restore test suite', () => {
connectProfile = new ConnectionProfile(browser);
bkRestore = new BackupRestore(browser);
tree = new TreeAction(browser);
editor = new Editor(browser);
await connectProfile
.connectProfileByHostname({
alias: 'test dump a database ' + mongoPort,
Expand All @@ -75,6 +77,13 @@ describe('backup restore test suite', () => {
return cleanup();
});

afterEach( async () => {
await bkRestore.closePanel();
await tree.toogleExpandTreeNode(
tree.databasesNodeSelector
);
});

/**
* select one database and click dump database from tree action, verify each parameter values
*/
Expand All @@ -99,13 +108,11 @@ describe('backup restore test suite', () => {
assert.equal(await bkRestore.getParameterValue(ParameterName.viewsAsCollections), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.query), '{user.name: "Joey"}');
assert.equal(await bkRestore.getParameterValue(ParameterName.pathInput), 'data/test/dump');
await bkRestore.closePanel();
await tree.toogleExpandTreeNode(
tree.databasesNodeSelector
);
const cmd = await editor._getEditorContentsAsString();
assert.equal(cmd, `mongodump --host localhost --port ${mongoPort} --db ${dumpDbName} --gzip --repair --dumpDbUsersAndRoles --viewsAsCollections --numParallelCollections 4 -q {user.name: "Joey"} --readPreference primaryPreferred --forceTableScan -o data/test/dump `);
} catch (err) {
console.error('get error ', err);
assert.fail(err.message);
assert.fail(true, false, err.message);
}
});

Expand Down Expand Up @@ -133,13 +140,11 @@ describe('backup restore test suite', () => {
assert.equal(await bkRestore.getParameterValue(ParameterName.viewsAsCollections), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.query), '{user.name: "Joey"}');
assert.equal(await bkRestore.getParameterValue(ParameterName.pathInput), 'data/test/dump');
await bkRestore.closePanel();
await tree.toogleExpandTreeNode(
tree.databasesNodeSelector
);
const cmd = await editor._getEditorContentsAsString();
assert.equal(cmd, `mongodump --host localhost --port ${mongoPort} --gzip --repair --dumpDbUsersAndRoles --viewsAsCollections --numParallelCollections 4 -q {user.name: "Joey"} --readPreference primaryPreferred --forceTableScan -o data/test/dump `);
} catch (err) {
console.error('get error ', err);
assert.fail(err.message);
assert.fail(true, false, err.message);
}
});

Expand Down Expand Up @@ -167,13 +172,11 @@ describe('backup restore test suite', () => {
assert.equal(await bkRestore.getParameterValue(ParameterName.viewsAsCollections), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.query), '{user.name: "Joey"}');
assert.equal(await bkRestore.getParameterValue(ParameterName.pathInput), 'data/test/dump');
await bkRestore.closePanel();
await tree.toogleExpandTreeNode(
tree.databasesNodeSelector
);
const cmd = await editor._getEditorContentsAsString();
assert.equal(cmd, `mongodump --host localhost --port ${mongoPort} --db ${dumpDbName} --gzip --repair --dumpDbUsersAndRoles --viewsAsCollections --numParallelCollections 4 -q {user.name: "Joey"} --readPreference primaryPreferred --forceTableScan -o data/test/dump `);
} catch (err) {
console.error('get error ', err);
assert.fail(err.message);
assert.fail(true, false, err.message);
}
});

Expand Down Expand Up @@ -201,19 +204,130 @@ describe('backup restore test suite', () => {
};
await bkRestore.openMongoBackupRestorePanel(['Databases'], TreeActions.RESTORE_DATABASES, params);
await browser.pause(1000);
_.forOwn(params, async (value, key) => {
console.log('check key ', key);
const nvalue = await bkRestore.getParameterValue(key);
console.log('compare ', nvalue, value);
assert.equal(nvalue, value);
});
await bkRestore.closePanel();
await tree.toogleExpandTreeNode(
tree.databasesNodeSelector
);
assert.equal(await bkRestore.getParameterValue(ParameterName.database), dumpDbName);
assert.equal(await bkRestore.getParameterValue(ParameterName.drop), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.pathInput), 'data/test/dump');
assert.equal(await bkRestore.getParameterValue(ParameterName.dryRun), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.writeConcern), 'majority');
assert.equal(await bkRestore.getParameterValue(ParameterName.noIndexRestore), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.noOptionsRestore), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.keepIndexVersion), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.maintainInsertionOrder), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.numParallelCollections), '5');
assert.equal(await bkRestore.getParameterValue(ParameterName.numInsertionWorkers), '3');
assert.equal(await bkRestore.getParameterValue(ParameterName.stopOnError), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.bypassDocumentValidation), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.objcheck), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.oplogReplay), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.oplogLimit), '10');
assert.equal(await bkRestore.getParameterValue(ParameterName.restoreDbUsersAndRoles), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.gzip), 'true');
const cmd = await editor._getEditorContentsAsString();
assert.equal(cmd, `mongorestore --host localhost --port ${mongoPort} --db ${dumpDbName} --objcheck --oplogReplay --oplogLimit 10 --restoreDbUsersAndRoles --gzip --drop -dryRun --writeConcern majority --noIndexRestore --noOptionsRestore --keepIndexVersion --maintainInsertionOrder --numParallelCollections 5 --numInsertionWorkersPerCollection 3 --stopOnError --bypassDocumentValidation data/test/dump`);
} catch (err) {
console.error('get error ', err);
assert.fail(true, false);
}
});

test('restore a database to verify its parameter values', async () => {
try {
const params = {
[ParameterName.drop]: true,
[ParameterName.collection]: 'testcol',
[ParameterName.pathInput]: 'data/test/dump',
[ParameterName.dryRun]: true,
[ParameterName.writeConcern]: 'majority',
[ParameterName.noIndexRestore]: true,
[ParameterName.noOptionsRestore]: true,
[ParameterName.keepIndexVersion]: true,
[ParameterName.maintainInsertionOrder]: true,
[ParameterName.numParallelCollections]: 5,
[ParameterName.numInsertionWorkers]: 3,
[ParameterName.stopOnError]: true,
[ParameterName.bypassDocumentValidation]: true,
[ParameterName.objcheck]: true,
[ParameterName.oplogReplay]: true,
[ParameterName.oplogLimit]: 10,
[ParameterName.restoreDbUsersAndRoles]: true,
[ParameterName.gzip]: true,
};
await bkRestore.openMongoBackupRestorePanel(['Databases', dumpDbName], TreeActions.RESTORE_DATABASE, params);
await browser.pause(1000);
assert.equal(await bkRestore.getParameterValue(ParameterName.database), dumpDbName);
assert.equal(await bkRestore.getParameterValue(ParameterName.collection), 'testcol');
assert.equal(await bkRestore.getParameterValue(ParameterName.drop), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.pathInput), 'data/test/dump');
assert.equal(await bkRestore.getParameterValue(ParameterName.dryRun), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.writeConcern), 'majority');
assert.equal(await bkRestore.getParameterValue(ParameterName.noIndexRestore), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.noOptionsRestore), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.keepIndexVersion), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.maintainInsertionOrder), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.numParallelCollections), '5');
assert.equal(await bkRestore.getParameterValue(ParameterName.numInsertionWorkers), '3');
assert.equal(await bkRestore.getParameterValue(ParameterName.stopOnError), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.bypassDocumentValidation), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.objcheck), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.oplogReplay), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.oplogLimit), '10');
assert.equal(await bkRestore.getParameterValue(ParameterName.restoreDbUsersAndRoles), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.gzip), 'true');
const cmd = await editor._getEditorContentsAsString();
assert.equal(cmd, `mongorestore --host localhost --port ${mongoPort} --db ${dumpDbName} --collection testcol --objcheck --oplogReplay --oplogLimit 10 --restoreDbUsersAndRoles --gzip --drop -dryRun --writeConcern majority --noIndexRestore --noOptionsRestore --keepIndexVersion --maintainInsertionOrder --numParallelCollections 5 --numInsertionWorkersPerCollection 3 --stopOnError --bypassDocumentValidation data/test/dump`);
} catch (err) {
console.error('get error ', err);
assert.fail(true, false);
}
});

test('restore a collection to verify its parameter values', async () => {
try {
const params = {
[ParameterName.drop]: true,
[ParameterName.pathInput]: 'data/test/dump',
[ParameterName.dryRun]: true,
[ParameterName.writeConcern]: 'majority',
[ParameterName.noIndexRestore]: true,
[ParameterName.noOptionsRestore]: true,
[ParameterName.keepIndexVersion]: true,
[ParameterName.maintainInsertionOrder]: true,
[ParameterName.numParallelCollections]: 5,
[ParameterName.numInsertionWorkers]: 3,
[ParameterName.stopOnError]: true,
[ParameterName.bypassDocumentValidation]: true,
[ParameterName.objcheck]: true,
[ParameterName.oplogReplay]: true,
[ParameterName.oplogLimit]: 10,
[ParameterName.restoreDbUsersAndRoles]: true,
[ParameterName.gzip]: true,
};
await bkRestore.openMongoBackupRestorePanel(['Databases', dumpDbName, 'testcol'], TreeActions.RESTORE_COLLECTION, params);
await browser.pause(1000);
assert.equal(await bkRestore.getParameterValue(ParameterName.database), dumpDbName);
assert.equal(await bkRestore.getParameterValue(ParameterName.collection), 'testcol');
assert.equal(await bkRestore.getParameterValue(ParameterName.drop), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.pathInput), 'data/test/dump');
assert.equal(await bkRestore.getParameterValue(ParameterName.dryRun), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.writeConcern), 'majority');
assert.equal(await bkRestore.getParameterValue(ParameterName.noIndexRestore), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.noOptionsRestore), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.keepIndexVersion), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.maintainInsertionOrder), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.numParallelCollections), '5');
assert.equal(await bkRestore.getParameterValue(ParameterName.numInsertionWorkers), '3');
assert.equal(await bkRestore.getParameterValue(ParameterName.stopOnError), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.bypassDocumentValidation), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.objcheck), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.oplogReplay), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.oplogLimit), '10');
assert.equal(await bkRestore.getParameterValue(ParameterName.restoreDbUsersAndRoles), 'true');
assert.equal(await bkRestore.getParameterValue(ParameterName.gzip), 'true');
const cmd = await editor._getEditorContentsAsString();
assert.equal(cmd, `mongorestore --host localhost --port ${mongoPort} --db ${dumpDbName} --collection testcol --objcheck --oplogReplay --oplogLimit 10 --restoreDbUsersAndRoles --gzip --drop -dryRun --writeConcern majority --noIndexRestore --noOptionsRestore --keepIndexVersion --maintainInsertionOrder --numParallelCollections 5 --numInsertionWorkersPerCollection 3 --stopOnError --bypassDocumentValidation data/test/dump`);
} catch (err) {
console.error('get error ', err);
assert.fail(err.message);
assert.fail(true, false);
}
});
});
11 changes: 6 additions & 5 deletions src/tests/pageObjects/BackupRestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {DELAY_TIMEOUT} from '../helpers/config';
*/
export const ParameterName = {
database: 'database',
collection: 'collection',
pathInput: 'pathInput',
gzip: 'gzip',
allCollections: 'all-collections',
Expand Down Expand Up @@ -65,6 +66,7 @@ export const ParameterName = {
*/
export const Options = {
[ParameterName.database]: {clsName: 'database-input', type: 'input'},
[ParameterName.collection]: {clsName: 'collection-input', type: 'input'},
[ParameterName.pathInput]: {clsName: 'path-input', type: 'input'},
[ParameterName.gzip]: {clsName: 'gzip input', type: 'checkbox'},
[ParameterName.allCollections]: {clsName: 'all-collections input', type: 'checkbox'},
Expand All @@ -82,14 +84,14 @@ export const Options = {
[ParameterName.noOptionsRestore]: {clsName: 'no-options-restore input', type: 'checkbox'},
[ParameterName.keepIndexVersion]: {clsName: 'keep-index-version input', type: 'checkbox'},
[ParameterName.maintainInsertionOrder]: {clsName: 'maintain-insertion-order input', type: 'checkbox'},
[ParameterName.numParallelCollections]: {clsName: 'num-parallel-collections', type: 'input'},
[ParameterName.numInsertionWorkers]: {clsName: 'num-insertion-workers', type: 'input'},
[ParameterName.stopOnError]: {clsName: 'stop-on-error', type: 'checkbox'},
[ParameterName.numParallelCollections]: {clsName: 'num-parallel-collections input', type: 'input'},
[ParameterName.numInsertionWorkers]: {clsName: 'num-insertion-workers input', type: 'input'},
[ParameterName.stopOnError]: {clsName: 'stop-on-error input', type: 'checkbox'},
[ParameterName.bypassDocumentValidation]: {clsName: 'bypass-document-validation input', type: 'checkbox'},
[ParameterName.objcheck]: {clsName: 'objcheck input', type: 'checkbox'},
[ParameterName.oplogReplay]: {clsName: 'oplog-replay input', type: 'checkbox'},
[ParameterName.oplogLimit]: {clsName: 'oplog-limit', type: 'input'},
[ParameterName.restoreDbUsersAndRoles]: {clsName: 'restore-db-users-and-roles', type: 'input'},
[ParameterName.restoreDbUsersAndRoles]: {clsName: 'restore-db-users-and-roles input', type: 'checkbox'},
};

/**
Expand Down Expand Up @@ -244,7 +246,6 @@ export default class BackupRestore extends Page {
*/
async _setCheckbox(selector, checked) {
const current = await this.browser.getAttribute(selector, 'checked');
console.log('get current value ', current, selector);
if (checked && current !== 'true') {
await this.browser.click(selector.replace(' input', ''));
} else if (!checked && current === 'true') {
Expand Down

0 comments on commit c7149cd

Please sign in to comment.