-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file system tests and fix ls output
format
- Loading branch information
1 parent
7dcc133
commit 9b0044b
Showing
7 changed files
with
109 additions
and
17 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
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
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,36 @@ | ||
#include "../src/FileSystem/FileSystem.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
class LsTest : public testing::Test { | ||
protected: | ||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes) | ||
std::string const PATH = "test.fs"; | ||
std::uint64_t const SIZE = 1024; | ||
std::uint64_t const CLUSTER_SIZE = 64; | ||
|
||
std::unique_ptr<FileSystem> file_system_; | ||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes) | ||
|
||
void SetUp() override { | ||
FileSystem::make(PATH, {SIZE, CLUSTER_SIZE}); | ||
|
||
file_system_ = std::make_unique<FileSystem>(PATH); | ||
} | ||
|
||
void TearDown() override { std::filesystem::remove(PATH); } | ||
}; | ||
|
||
TEST_F(LsTest, Empty) { | ||
auto const list = file_system_->ls("/"); | ||
EXPECT_EQ(list.size(), 2); | ||
EXPECT_EQ(list[0].name(), "."); | ||
EXPECT_EQ(list[1].name(), ".."); | ||
} | ||
|
||
TEST_F(LsTest, NonExistent) { | ||
EXPECT_THROW(auto const list = file_system_->ls("/non_existent"), std::invalid_argument); | ||
} | ||
|
||
TEST_F(LsTest, NonExistentNested) { | ||
EXPECT_THROW(auto const list = file_system_->ls("/non_existent/nested"), std::invalid_argument); | ||
} |
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,45 @@ | ||
#include "../src/FileSystem/FileSystem.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
class MkdirTest : public testing::Test { | ||
protected: | ||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes) | ||
std::string const PATH = "test.fs"; | ||
std::uint64_t const SIZE = 2024; | ||
std::uint64_t const CLUSTER_SIZE = 64; | ||
|
||
std::unique_ptr<FileSystem> file_system_; | ||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes) | ||
|
||
void SetUp() override { | ||
FileSystem::make(PATH, {SIZE, CLUSTER_SIZE}); | ||
|
||
file_system_ = std::make_unique<FileSystem>(PATH); | ||
} | ||
|
||
void TearDown() override { std::filesystem::remove(PATH); } | ||
}; | ||
|
||
TEST_F(MkdirTest, Empty) { | ||
file_system_->mkdir("./a"); | ||
file_system_->mkdir("b"); | ||
file_system_->mkdir("/c"); | ||
auto const list = file_system_->ls("/"); | ||
EXPECT_EQ(list.size(), 5); | ||
EXPECT_EQ(list[0].name(), "."); | ||
EXPECT_EQ(list[1].name(), ".."); | ||
EXPECT_EQ(list[2].name(), "a"); | ||
EXPECT_EQ(list[3].name(), "b"); | ||
EXPECT_EQ(list[4].name(), "c"); | ||
} | ||
|
||
TEST_F(MkdirTest, NonExistent) { EXPECT_THROW(file_system_->mkdir("/non_existent/test"), std::invalid_argument); } | ||
|
||
TEST_F(MkdirTest, NonExistentNested) { | ||
EXPECT_THROW(file_system_->mkdir("/non_existent/nested/test"), std::invalid_argument); | ||
} | ||
|
||
TEST_F(MkdirTest, AlreadyExists) { | ||
file_system_->mkdir("/test"); | ||
EXPECT_THROW(file_system_->mkdir("/test"), std::invalid_argument); | ||
} |