summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/validate_command.js
blob: 9c52c9acad7dbcb07592d1308c944f3b3bbcf8ab (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
// Tests that the basic values returned from the validate command are correct

(function() {
    // Set the number of documents to insert
    var count = 10;

    function testValidate(output) {
        assert.eq(output.nrecords, count, "validate returned an invalid count");
        assert.eq(output.nIndexes, 3, "validate returned an invalid number of indexes");

        var indexNames = output.keysPerIndex;

        for (var i in indexNames) {
            if (!indexNames.hasOwnProperty(i))
                continue;
            assert.eq(indexNames[i], count, "validate returned an invalid number of indexes");
        }
    }

    // Test to confirm that validate is working as expected.

    // SETUP DATA
    t = db.jstests_validate;
    t.drop();

    for (var i = 0; i < count; i++) {
        t.insert({x: i});
    }

    t.ensureIndex({x: 1}, {name: "forward"});
    t.ensureIndex({x: -1}, {name: "reverse"});

    // TEST NORMAL VALIDATE
    var output = t.validate();
    testValidate(output);

    // TEST FULL
    var output = t.validate({full: true});
    testValidate(output);
}());