summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/test/qa-tests/jstests/files/mongofiles_prefix.js
blob: 3d19bd141eebae062ec88ad40357a4dc050e4ba4 (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
// mongofiles_prefix.js; ensure that passing --prefix works as expected - the
// provided prefix is used as the collection name prefix
var testName = 'mongofiles_prefix';
load('jstests/files/util/mongofiles_common.js');
(function() {
  jsTest.log('Testing mongofiles --prefix option');

  var runTests = function(topology, passthrough) {
    var t = topology.init(passthrough);
    var conn = t.connection();
    var db = conn.getDB('test');

    jsTest.log('Putting file without --prefix with ' + passthrough.name + ' passthrough');

    // ensure tool runs without error
    assert.eq(runMongoProgram.apply(this, ['mongofiles',
        '--port', conn.port,
        'put', filesToInsert[0]]
      .concat(passthrough.args)),
      0, 'put 1 failed');

    // ensure the default collection name prefix was used
    assert.eq(1, db.fs.files.count(), 'unexpected fs.files count');
    assert.eq(0, db[testName + '.files'].count(), 'unexpected ' + testName + '.files count');

    jsTest.log('Putting file with --prefix with ' + passthrough.name + ' passthrough');

    // ensure tool runs without error
    assert.eq(runMongoProgram.apply(this, ['mongofiles',
          '--port', conn.port,
          '--prefix', testName,
          'put', filesToInsert[0]]
      .concat(passthrough.args)),
        0, 'put 2 failed');

    // ensure the supplied collection name prefix was used
    assert.eq(1, db.fs.files.count(), 'unexpected fs.files count');
    assert.eq(1, db[testName + '.files'].count(), 'unexpected ' + testName + '.files count');

    t.stop();
  };

  // run with plain and auth passthroughs
  passthroughs.forEach(function(passthrough) {
    runTests(standaloneTopology, passthrough);
    runTests(replicaSetTopology, passthrough);
    runTests(shardedClusterTopology, passthrough);
  });
}());