Unittests should use utils/files.h, not subcommand
While the subprocess/command libraries work, it might be an
overkill to create directories and clean them up recursively.
Bug: 249617375
Test: atest -c --host --no-bazel-mode cvd_instance_db_test
Change-Id: Ia3813a43d632941152950a87c96f792df70f31f6
diff --git a/host/commands/cvd/unittests/instance_database_test_helper.cpp b/host/commands/cvd/unittests/instance_database_test_helper.cpp
index 77cc946..756ab19 100644
--- a/host/commands/cvd/unittests/instance_database_test_helper.cpp
+++ b/host/commands/cvd/unittests/instance_database_test_helper.cpp
@@ -22,23 +22,13 @@
#include "common/libs/fs/shared_fd.h"
#include "common/libs/utils/environment.h"
-#include "common/libs/utils/subprocess.h"
+#include "common/libs/utils/files.h"
namespace cuttlefish {
namespace instance_db {
namespace unittest {
namespace {
-template <typename... Args>
-void RunCmd(const std::string& exe_path, Args&&... args) {
- Command command(exe_path);
- auto add_param = [&command](const std::string& arg) {
- command.AddParameter(arg);
- };
- (add_param(std::forward<Args>(args)), ...);
- command.Start().Wait();
-}
-
std::string GetRandomInstanceName(const unsigned long len) {
std::string alphabets{
"0123456789"
@@ -64,7 +54,7 @@
void DbTester::Clear() {
if (!tmp_dir_.empty()) {
- RunCmd("/usr/bin/rm", "-fr", tmp_dir_);
+ RecursivelyRemoveDirectory(tmp_dir_);
}
fake_homes_.clear();
}
@@ -77,7 +67,7 @@
for (int i = 1; i < kNGroups + 1; i++) {
std::string subdir = tmp_dir_ + "/cf" + std::to_string(i);
fake_homes_.emplace_back(subdir);
- RunCmd("/usr/bin/mkdir", subdir);
+ EnsureDirectoryExists(subdir);
}
}