From 422f71f19e5f4e5d84fa0e42811537997ec26db5 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 24 Jan 2022 15:02:15 +0100 Subject: [PATCH] Test: Add system file test cases --- test/testdotfile.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/testdotfile.cpp b/test/testdotfile.cpp index d195075..e62fb12 100644 --- a/test/testdotfile.cpp +++ b/test/testdotfile.cpp @@ -196,3 +196,35 @@ TEST_CASE(PushDotfiles) removeTestDotfiles(fileNames); } + +TEST_CASE(AddSystemDotfiles) +{ + VERIFY(geteuid() == 0); + + Dotfile::the().setSystemDirectories({ "/etc", "/usr/lib" }); + Dotfile::the().add({ "/etc/group", "/usr/lib/os-release" }); + Dotfile::the().setSystemDirectories({}); + + EXPECT(std::filesystem::exists("etc/group")); + EXPECT(std::filesystem::exists("usr/lib/os-release")); + + std::filesystem::remove_all(Dotfile::the().workingDirectory() / "etc"); + std::filesystem::remove_all(Dotfile::the().workingDirectory() / "usr"); +} + +TEST_CASE(PullSystemDotfiles) +{ + VERIFY(geteuid() == 0); + + createTestDotfiles({ "etc/group" }, { "" }); + + Dotfile::the().setSystemDirectories({ "/etc" }); + Dotfile::the().pull({ "etc/group" }); + Dotfile::the().setSystemDirectories({}); + + Util::File lhs("/etc/group"); + Util::File rhs(Dotfile::the().workingDirectory() / "etc/group"); + EXPECT_EQ(lhs.data(), rhs.data()); + + std::filesystem::remove_all(Dotfile::the().workingDirectory() / "etc"); +}