Skip to content

Commit

Permalink
move the Drop a collection test to the tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Jan 27, 2025
1 parent 39971e4 commit 24d88cb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ examples/bench-mongodb/bench-mongodb
examples/bench-urlrouter/bench-urlrouter
*.exe

tests/mongodb/collection/tests
9 changes: 0 additions & 9 deletions mongodb/vibe/db/mongo/collection.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tests/mongodb/collection/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "tests",
"description": "High level MongoDB collection tests for vibe.d",
"dependencies": {
"vibe-d:mongodb": {"path": "../../../"}
}
}
39 changes: 39 additions & 0 deletions tests/mongodb/collection/source/app.d
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 24d88cb

Please sign in to comment.