Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cortex update unit test #1207

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions engine/test/components/test_cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ namespace {
constexpr const auto kNewReleaseFolder = "./cortex-release";
constexpr const auto kNewReleaseFile = "./cortex-release/cortexexe";
constexpr const auto kCurReleaseFile = "./cortexexe";
std::filesystem::path GetCortexTemp() {
return std::filesystem::temp_directory_path() / "cortex_temp";
}
constexpr const auto kCortexTemp = "./cortex_temp";
} // namespace

class CortexUpdCmdTest : public ::testing::Test {
Expand All @@ -31,8 +29,8 @@ class CortexUpdCmdTest : public ::testing::Test {
std::filesystem::remove(kCurReleaseFile);
}

if (std::filesystem::exists(GetCortexTemp())) {
std::filesystem::remove(GetCortexTemp());
if (std::filesystem::exists(kCortexTemp)) {
std::filesystem::remove(kCortexTemp);
}
}
};
Expand All @@ -45,12 +43,12 @@ TEST_F(CortexUpdCmdTest, replace_binary_successfully) {
std::filesystem::path new_binary(kNewReleaseFile);
std::filesystem::path cur_binary(kCurReleaseFile);
EXPECT_TRUE(commands::ReplaceBinaryInflight(new_binary, cur_binary));
EXPECT_TRUE(std::filesystem::exists(GetCortexTemp()));
EXPECT_TRUE(std::filesystem::exists(kCortexTemp));
}

TEST_F(CortexUpdCmdTest, should_restore_old_binary_if_has_error) {
std::filesystem::path new_binary("Non-exist");
std::filesystem::path cur_binary(kCurReleaseFile);
EXPECT_FALSE(commands::ReplaceBinaryInflight(new_binary, cur_binary));
EXPECT_FALSE(std::filesystem::exists(GetCortexTemp()));
EXPECT_FALSE(std::filesystem::exists(kCortexTemp));
}
Loading