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 3b4f3f9 commit 427140f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
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
10 changes: 9 additions & 1 deletion src/telemetry/tests/testDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,15 @@ TEST(TelemetryDirectory, addSymlink)
EXPECT_THROW((void) root->addSymlink("link", info), TelemetryException);
EXPECT_THROW((void) root->addSymlink("info", info), TelemetryException);

auto symlink1 = root->addSymlink("link1", symlink);
auto symlinkToSymlink = root->addSymlink("linkToLink", symlink);

EXPECT_EQ("linkToLink", symlinkToSymlink->getName());
EXPECT_EQ("/linkToLink", symlinkToSymlink->getFullPath());
EXPECT_EQ(symlink, symlinkToSymlink->getTarget());

auto targetOfSymlinkToSymlink
= std::dynamic_pointer_cast<Symlink>(symlinkToSymlink->getTarget())->getTarget();
EXPECT_EQ(info, targetOfSymlinkToSymlink);
}

} // namespace telemetry
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 <siska@cesnet.cz>
* @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 427140f

Please sign in to comment.