summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Ioffe <ioffe@google.com>2021-03-24 22:26:31 +0000
committerNikita Ioffe <ioffe@google.com>2021-03-26 15:46:54 +0000
commitfbb86e1f6f45da6ded3a3692ed56038ebfae409d (patch)
tree4e65b14d1000468995e05f296c43fe2d56c321cd
parent66bd61adb95077787c37bf4aa914cb242a52d413 (diff)
Wipe sessions dir before running MigrateToMetadataSessionsDir test
Test: atest ApexTestCases Bug: 183546040 Bug: 183545537 Change-Id: I4a9e412acefa5d364a241b3a3222af5848e4d946 Merged-In: I4a9e412acefa5d364a241b3a3222af5848e4d946 (cherry picked from commit 9e8da8f32ec1cefb427ef6cbbb885c3772f6a420)
-rw-r--r--apexd/apexd_session_test.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/apexd/apexd_session_test.cpp b/apexd/apexd_session_test.cpp
index bec0561..0dc3a78 100644
--- a/apexd/apexd_session_test.cpp
+++ b/apexd/apexd_session_test.cpp
@@ -24,6 +24,7 @@
#include <android-base/result.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
#include <gtest/gtest.h>
#include "apexd_session.h"
@@ -36,6 +37,7 @@ namespace apex {
namespace {
using android::apex::testing::IsOk;
+using android::base::Join;
using android::base::make_scope_guard;
// TODO(b/170329726): add unit tests for apexd_sessions.h
@@ -65,6 +67,12 @@ TEST(ApexdSessionTest, MigrateToMetadataSessionsDir) {
GTEST_SKIP() << "Device doesn't have /metadata partition";
}
+ // This is ugly, but does the job. To have a truly hermetic unit tests we
+ // need to refactor ApexSession class.
+ for (const auto& entry : fs::directory_iterator("/metadata/apex/sessions")) {
+ fs::remove_all(entry.path());
+ }
+
// This is a very ugly test set up, but to have something better we need to
// refactor ApexSession class.
class TestApexSession {
@@ -101,7 +109,8 @@ TEST(ApexdSessionTest, MigrateToMetadataSessionsDir) {
ASSERT_TRUE(IsOk(ApexSession::MigrateToMetadataSessionsDir()));
- ASSERT_EQ(2u, ApexSession::GetSessions().size());
+ auto sessions = ApexSession::GetSessions();
+ ASSERT_EQ(2u, sessions.size()) << Join(sessions, ',');
auto migrated_session_1 = ApexSession::GetSession(239);
ASSERT_TRUE(IsOk(migrated_session_1));