Skip to content

Commit c475758

Browse files
committed
Added create collection view test
1 parent 68ae28a commit c475758

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

test/functional/view_tests.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Extend the object
2+
var extend = function(template, fields) {
3+
var object = {};
4+
for(var name in template) {
5+
object[name] = template[name];
6+
}
7+
8+
for(var name in fields) {
9+
object[name] = fields[name];
10+
}
11+
12+
return object;
13+
}
14+
15+
exports['Successfully pass through collation to findAndModify command'] = {
16+
metadata: { requires: { generators: true, topology: "single" } },
17+
18+
test: function(configuration, test) {
19+
var MongoClient = configuration.require.MongoClient,
20+
co = require('co'),
21+
Long = configuration.require.Long,
22+
mockupdb = require('../mock');
23+
24+
// Contain mock server
25+
var singleServer = null;
26+
var running = true;
27+
28+
// Default message fields
29+
var defaultFields = {
30+
"ismaster" : true, "maxBsonObjectSize" : 16777216,
31+
"maxMessageSizeBytes" : 48000000, "maxWriteBatchSize" : 1000,
32+
"localTime" : new Date(), "maxWireVersion" : 5, "minWireVersion" : 0, "ok" : 1
33+
}
34+
35+
// Primary server states
36+
var primary = [extend(defaultFields, {})];
37+
var commandResult = null;
38+
39+
// Boot the mock
40+
co(function*() {
41+
singleServer = yield mockupdb.createServer(32000, 'localhost');
42+
43+
// Primary state machine
44+
co(function*() {
45+
while(running) {
46+
var request = yield singleServer.receive();
47+
var doc = request.document;
48+
// console.log("========================== cmd")
49+
// console.dir(doc)
50+
51+
if(doc.ismaster) {
52+
request.reply(primary[0]);
53+
} else if(doc.listCollections) {
54+
request.reply({ok:1, cursor: {
55+
id: Long.fromNumber(0), ns: 'test.cmd$.listCollections', firstBatch: []
56+
}});
57+
} else if(doc.create) {
58+
commandResult = doc;
59+
request.reply({ok:1});
60+
}
61+
}
62+
}).catch(function(err) {
63+
console.log(err.stack);
64+
});
65+
66+
var commandResult = null;
67+
68+
// Connect to the mocks
69+
MongoClient.connect('mongodb://localhost:32000/test', function(err, db) {
70+
test.equal(null, err);
71+
72+
// Simple findAndModify command returning the new document
73+
db.createCollection('test', {viewOn: 'users', pipeline: [{$match: {}}]}, function(err, r) {
74+
test.equal(null, err);
75+
test.deepEqual({ create: 'test', viewOn: 'users', pipeline: [ { '$match': {} } ] }, commandResult)
76+
77+
singleServer.destroy();
78+
running = false;
79+
80+
db.close();
81+
test.done();
82+
});
83+
});
84+
});
85+
}
86+
}

0 commit comments

Comments
 (0)