Skip to content

Commit

Permalink
+ mongo utest
Browse files Browse the repository at this point in the history
  • Loading branch information
kpavlov00 committed Jun 28, 2024
1 parent 64aa399 commit 9e96c1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions samples/mongo_service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ find_package(userver COMPONENTS mongo REQUIRED)
add_executable(${PROJECT_NAME} "mongo_service.cpp")
target_link_libraries(${PROJECT_NAME} userver::mongo)

add_executable(${PROJECT_NAME}-unittest "unittests/mongo_test.cpp")
target_link_libraries(${PROJECT_NAME}-unittest userver::utest userver::mongo)

userver_add_utest(NAME ${PROJECT_NAME}-unittest DATABASES mongo)

userver_testsuite_add_simple()
13 changes: 13 additions & 0 deletions samples/mongo_service/unittests/mongo_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <userver/storages/mongo/utest/mongo_fixture.hpp>
#include <userver/utest/using_namespace_userver.hpp>

#include <userver/formats/bson/inline.hpp>

using MongoTest = storages::mongo::utest::MongoTest;

UTEST_F(MongoTest, Sample) {
auto collection = GetPool()->GetCollection("xyz");
EXPECT_EQ(0, collection.Count({}));
collection.InsertOne(formats::bson::MakeDoc("x", 2));
EXPECT_EQ(1, collection.Count({}));
}

0 comments on commit 9e96c1a

Please sign in to comment.