-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(inventory): add unit test for SendDeltaEvent method
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
add_executable(inventory_unit_test inventory_test.cpp) | ||
configure_target(inventory_unit_test) | ||
target_include_directories(inventory_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) | ||
target_link_libraries(inventory_unit_test PRIVATE | ||
Inventory | ||
GTest::gtest | ||
GTest::gtest_main | ||
GTest::gmock | ||
GTest::gmock_main) | ||
if(NOT WIN32) | ||
add_test(NAME InventoryTest COMMAND inventory_unit_test) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <cstdio> | ||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
#include "inventory.hpp" | ||
|
||
constexpr auto INVENTORY_DB_PATH {"TEMP.db"}; | ||
|
||
class InventoryTest : public ::testing::Test | ||
{ | ||
protected: | ||
|
||
void SetUp() override {} | ||
void TearDown() override | ||
{ | ||
std::remove(INVENTORY_DB_PATH); | ||
} | ||
|
||
Inventory &inventory = Inventory::Instance(); | ||
}; | ||
|
||
TEST_F(InventoryTest, SendUpdateEvent) { | ||
::testing::MockFunction<int(const Message&)> mockPushMessage; | ||
|
||
inventory.SetPushMessageFunction(mockPushMessage.AsStdFunction()); | ||
|
||
EXPECT_CALL(mockPushMessage, Call(::testing::_)) | ||
.WillOnce([](const Message& msg) | ||
{ | ||
auto expectedData = R"({"key":"value"})"; | ||
auto expectedMetadata = R"({"id":"123","module":"inventory","operation":"update","type":"hardware"})"; | ||
|
||
EXPECT_EQ(msg.data.dump(), expectedData); | ||
EXPECT_EQ(msg.metaData, expectedMetadata); | ||
return 1; | ||
}); | ||
|
||
auto inputData = R"({ | ||
"type": "hardware", | ||
"operation": "update", | ||
"id": "123", | ||
"data": {"key": "value"} | ||
})"; | ||
|
||
inventory.SendDeltaEvent(inputData); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |