diff --git a/.gitignore b/.gitignore index adca06650..aacea43a4 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ examples/bench-mongodb/bench-mongodb examples/bench-urlrouter/bench-urlrouter *.exe +tests/mongodb/collection/tests diff --git a/mongodb/vibe/db/mongo/collection.d b/mongodb/vibe/db/mongo/collection.d index 57829b3cd..92b4e9a56 100644 --- a/mongodb/vibe/db/mongo/collection.d +++ b/mongodb/vibe/db/mongo/collection.d @@ -1313,15 +1313,6 @@ struct MongoCollection { } } -/// Drop a collection -@safe unittest { - import vibe.db.mongo.mongo; - auto client = connectMongoDB("127.0.0.1"); - auto chunks = client.getCollection("test.fs.chunks"); - - chunks.drop; -} - /** Specifies a level of isolation for read operations. For example, you can use read concern to only read data that has propagated to a majority of nodes in a replica set. diff --git a/tests/mongodb/collection/dub.json b/tests/mongodb/collection/dub.json new file mode 100644 index 000000000..386e26a00 --- /dev/null +++ b/tests/mongodb/collection/dub.json @@ -0,0 +1,7 @@ +{ + "name": "tests", + "description": "High level MongoDB collection tests for vibe.d", + "dependencies": { + "vibe-d:mongodb": {"path": "../../../"} + } +} diff --git a/tests/mongodb/collection/source/app.d b/tests/mongodb/collection/source/app.d new file mode 100644 index 000000000..9d65527ba --- /dev/null +++ b/tests/mongodb/collection/source/app.d @@ -0,0 +1,39 @@ +/// Requires mongo service running on localhost with default port +/// Uses test database + +module app; + +import vibe.core.core; +import vibe.core.log; +import vibe.data.bson; +import vibe.db.mongo.mongo; + +import std.algorithm : all, canFind, equal, map, sort; +import std.conv : to; +import std.encoding : sanitize; +import std.exception : assertThrown; + + +void runTest(ushort port) +{ + MongoClient client = connectMongoDB("127.0.0.1", port); + + /// Drop a collection + auto chunks = client.getCollection("test.fs.chunks"); + chunks.drop; +} + +int main(string[] args) +{ + int ret = 0; + ushort port = args.length > 1 + ? args[1].to!ushort + : MongoClientSettings.defaultPort; + runTask(() nothrow { + try runTest(port); + catch (Exception e) assert(false, e.toString()); + finally exitEventLoop(true); + }); + runEventLoop(); + return ret; +}