summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/test/qa-tests/jstests/restore/drop_nonexistent_db.js
blob: fded2c8706ee676a75ecdd62212d45800e68b120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(function() {

  if (typeof getToolTest === 'undefined') {
    load('jstests/configs/plain_28.config.js');
  }

  // Tests that running mongorestore with --drop on a database with
  // nothing to drop does not error out, and completes the
  // restore successfully.

  jsTest.log('Testing restoration with --drop on a nonexistent db');

  var toolTest = getToolTest('drop_nonexistent_db');
  var commonToolArgs = getCommonToolArguments();

  // where we'll put the dump
  var dumpTarget = 'drop_nonexistent_db_dump';
  resetDbpath(dumpTarget);

  // the db we will use
  var testDB = toolTest.db.getSiblingDB('test');

  // insert a bunch of data
  for (var i = 0; i < 500; i++) {
    testDB.coll.insert({_id: i});
  }
  // sanity check the insertion worked
  assert.eq(500, testDB.coll.count());

  // dump the data
  var ret = toolTest.runTool.apply(toolTest, ['dump']
    .concat(getDumpTarget(dumpTarget))
    .concat(commonToolArgs));
  assert.eq(0, ret);

  // drop the database we are using
  testDB.dropDatabase();
  // sanity check the drop worked
  assert.eq(0, testDB.coll.count());

  // restore the data with --drop
  ret = toolTest.runTool.apply(toolTest, ['restore', '--drop']
    .concat(getRestoreTarget(dumpTarget))
    .concat(commonToolArgs));
  assert.eq(0, ret);

  // make sure the data was restored
  assert.eq(500, testDB.coll.count());
  for (i = 0; i < 500; i++) {
    assert.eq(1, testDB.coll.count({_id: i}));
  }

  // success
  toolTest.stop();

}());