Skip to content

Commit b2070ae

Browse files
committed
move the Drop a collection test to the tests folder
1 parent 39971e4 commit b2070ae

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ examples/bench-mongodb/bench-mongodb
4646
examples/bench-urlrouter/bench-urlrouter
4747
*.exe
4848

49+
tests/mongodb/collection/tests

tests/mongodb/collection/dub.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "tests",
3+
"description": "High level MongoDB collection tests for vibe.d",
4+
"dependencies": {
5+
"vibe-d:mongodb": {"path": "../../../"}
6+
}
7+
}

tests/mongodb/collection/source/app.d

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Requires mongo service running on localhost with default port
2+
/// Uses test database
3+
4+
module app;
5+
6+
import vibe.core.core;
7+
import vibe.core.log;
8+
import vibe.data.bson;
9+
import vibe.db.mongo.mongo;
10+
11+
import std.algorithm : all, canFind, equal, map, sort;
12+
import std.conv : to;
13+
import std.encoding : sanitize;
14+
import std.exception : assertThrown;
15+
16+
17+
void runTest(ushort port)
18+
{
19+
MongoClient client = connectMongoDB("127.0.0.1", port);
20+
21+
/// Drop a collection
22+
auto chunks = client.getCollection("test.fs.chunks");
23+
chunks.drop;
24+
}
25+
26+
int main(string[] args)
27+
{
28+
int ret = 0;
29+
ushort port = args.length > 1
30+
? args[1].to!ushort
31+
: MongoClientSettings.defaultPort;
32+
runTask(() nothrow {
33+
try runTest(port);
34+
catch (Exception e) assert(false, e.toString());
35+
finally exitEventLoop(true);
36+
});
37+
runEventLoop();
38+
return ret;
39+
}

0 commit comments

Comments
 (0)