Skip to content

Commit

Permalink
Merge pull request #49 from xxanxnie/CI/buildDB
Browse files Browse the repository at this point in the history
Add setup database in ci
  • Loading branch information
suranimaria authored Nov 26, 2024
2 parents e5e37ed + 88268dc commit 7cae48e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y libmongoc-1.0-0 curl cmake build-essential \
libssl-dev libboost-all-dev libpoco-dev libcurl4-openssl-dev
sudo apt-get install -y docker
- name: Install spdlog
run: |
git clone https://github.com/gabime/spdlog.git
Expand Down Expand Up @@ -96,6 +96,9 @@ jobs:
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: setup database
run: docker compose up -d

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set(TEST_FILES
test/RouteControllerUnitTests.cpp
test/AuthUnitTests.cpp
test/SubscriptionManagerUnitTests.cpp
test/DataBaseTest.cpp
)

set(SOURCE_FILES_NO_MAIN
Expand Down
29 changes: 29 additions & 0 deletions test/DataBaseTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 COMSW4156-Git-Gud

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include "DatabaseManager.h"

class DataBaseTest : public ::testing::Test {
protected:
DatabaseManager* DbManager;
void SetUp() override {
DbManager = new DatabaseManager("mongodb://localhost:27017");
DbManager->createCollection("test");
}

void TearDown() override {
DbManager->deleteCollection("test");
delete DbManager;
}
};

TEST_F(DataBaseTest, Checksetup) {
std::vector<bsoncxx::document::value> result;
DbManager->findCollection(0, "test", {}, result);
EXPECT_EQ(result.size(), 0);
}

0 comments on commit 7cae48e

Please sign in to comment.