From 24d88cbffcc5aa5fa547559b47fe3c9bba16cba0 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Mon, 27 Jan 2025 13:00:02 +0100 Subject: [PATCH] move the Drop a collection test to the tests folder --- .gitignore | 1 + mongodb/vibe/db/mongo/collection.d | 9 ------- tests/mongodb/collection/dub.json | 7 +++++ tests/mongodb/collection/source/app.d | 39 +++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 tests/mongodb/collection/dub.json create mode 100644 tests/mongodb/collection/source/app.d diff --git a/.gitignore b/.gitignore index adca066502..aacea43a4e 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 57829b3cd7..92b4e9a564 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 0000000000..386e26a002 --- /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 0000000000..9d65527ba5 --- /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; +}