-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
uri_tests.js
200 lines (169 loc) · 6.25 KB
/
uri_tests.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"use strict";
/**
* @ignore
*/
exports['Should correctly connect using MongoClient to a single server using connect with optional server setting'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient
, Server = configuration.require.Server;
// Connect using the connection string
MongoClient.connect("mongodb://localhost:27017/integration_tests", {
db: {
native_parser: false
},
server: {
socketOptions: {
connectTimeoutMS: 500
}
}
}, function(err, db) {
test.equal(null, err);
test.equal(500, db.serverConfig.connections()[0].connectionTimeout);
db.collection('mongoclient_test').update({a:1}, {b:1}, {upsert:true}, function(err, result) {
test.equal(null, err);
test.equal(1, result.result.n);
db.close();
test.done();
});
});
}
}
/**
* @ignore
*/
exports['Should correctly allow for w:0 overriding on the connect url'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient
, Server = configuration.require.Server;
// Connect using the connection string
MongoClient.connect("mongodb://localhost:27017/integration_tests?w=0", function(err, db) {
test.equal(null, err);
db.collection('mongoclient_test').update({a:1}, {b:1}, {upsert:true}, function(err, result) {
test.equal(null, err);
if(result) test.equal(1, result.result.ok);
else test.equal(null, result);
db.close();
test.done();
});
});
}
}
exports['Should correctly connect via domain socket'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient;
if(process.platform != "win32") {
MongoClient.connect("mongodb:///tmp/mongodb-27017.sock?safe=false", function(err, db) {
test.equal(null, err);
db.close();
test.done();
});
} else {
test.done();
}
}
}
exports['Should correctly connect via normal url using connect'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var mongodb = configuration.require;
mongodb.connect("mongodb://localhost/?safe=false", function(err, db) {
db.close();
test.done();
});
}
}
exports['Should correctly connect via normal url using require'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
require('../..')("mongodb://localhost/", function(err, db) {
db.close();
test.done();
});
}
}
exports['Should correctly connect via normal url journal option'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient;
MongoClient.connect("mongodb://localhost/?journal=true", function(err, db) {
test.equal(true, db.writeConcern.j);
db.close();
test.done();
});
}
}
exports['Should correctly connect via normal url using ip'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient;
MongoClient.connect("mongodb://127.0.0.1:27017/?fsync=true", function(err, db) {
test.equal(true, db.writeConcern.fsync);
db.close();
test.done();
});
}
}
exports['Should correctly connect via normal url setting up poolsize of 1'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient;
MongoClient.connect("mongodb://127.0.0.1:27017/?maxPoolSize=1", function(err, db) {
test.deepEqual(1, db.serverConfig.connections().length);
test.equal('admin', db.databaseName);
db.close();
test.done();
});
}
}
exports['Should correctly connect using uri encoded username and password'] = {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single'} },
// The actual test we wish to run
test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient;
MongoClient.connect("mongodb://localhost:27017/integration_tests", {native_parser:true}, function(err, db) {
test.equal(null, err);
var user = 'u$ser'
, pass = '$specialch@rs'
;
db.addUser(user, pass, function(err) {
test.equal(null, err);
var uri = "mongodb://" + encodeURIComponent(user) + ":" + encodeURIComponent(pass) + "@localhost:27017/integration_tests";
MongoClient.connect(uri, {native_parser:true}, function(err, authenticatedDb) {
test.equal(null, err);
db.close();
authenticatedDb.close();
test.done();
});
});
});
}
}