Skip to content

Commit

Permalink
test - introduce unit tests for telemetry::Symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
SiskaPavel committed Oct 7, 2024
1 parent 947313c commit 8b12cb4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/telemetry/symlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Symlink::Symlink(
}

} // namespace telemetry

#ifdef TELEMETRY_ENABLE_TESTS
#include "tests/testSymlink.cpp"
#endif
52 changes: 52 additions & 0 deletions src/telemetry/tests/testSymlink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file
* @author Pavel Siska <[email protected]>
* @brief Unit tests of telemetry::File class
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <telemetry/directory.hpp>

#include <gtest/gtest.h>

namespace telemetry {

/**
* @test Test checking symlink target
*/
TEST(TelemetrySymlink, hasTarget)
{
auto root = Directory::create();
auto dir = root->addDir("dir");
auto file = dir->addFile("file", {});
auto symlink = root->addSymlink("symlink", file);

auto target = symlink->getTarget();

EXPECT_EQ(file, target);
}

/**
* @test Test checking symlink target lifetime
*/
TEST(TelemetrySymlink, targetScopeLifetime)
{
auto root = Directory::create();
auto dir = root->addDir("dir");

std::shared_ptr<Symlink> symlink;

{
auto file = dir->addFile("file", {});
symlink = root->addSymlink("symlink", file);

auto target = symlink->getTarget();
EXPECT_EQ(file, target);
}

auto target = symlink->getTarget();
EXPECT_EQ(nullptr, target);
}

} // namespace telemetry

0 comments on commit 8b12cb4

Please sign in to comment.