Skip to content

Commit

Permalink
Stop updater_test from deleting its own binary (youtube#3450)
Browse files Browse the repository at this point in the history
The tests were written such that they deleted not only their own test
data files, but the unit test shared library itself. This meant that in
some cases, the tests could not be rerun. Thanks @kaidokert for pointing
that out.

b/322248208

Change-Id: Icc563102732acddac13914dea7107f83cb7d2036
  • Loading branch information
hlwarriner committed Jun 5, 2024
1 parent a24c6ab commit d9f923d
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions chrome/updater/utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,29 @@ class UtilsTest : public testing::Test {
ASSERT_TRUE(SbFileDelete(manifest_path.c_str()));
}

void CreateEmptyLibrary(const std::string& name,
const std::string& installation_path) {
std::string GetLibraryPath(const std::string& name,
const std::string& installation_path) {
std::string lib_path = base::StrCat(
{installation_path, kSbFileSepString, kEvergreenLibDirname});
ASSERT_TRUE(EnsureDirectoryExists(lib_path.c_str()));
EXPECT_TRUE(EnsureDirectoryExists(lib_path.c_str()));
return base::StrCat({lib_path, kSbFileSepString, name});
}

lib_path = base::StrCat({lib_path, kSbFileSepString, name});
void CreateEmptyLibrary(const std::string& name,
const std::string& installation_path) {
std::string lib_path = GetLibraryPath(name, installation_path);
SbFile sb_file = SbFileOpen(
lib_path.c_str(), kSbFileOpenAlways | kSbFileRead, nullptr, nullptr);
ASSERT_TRUE(SbFileIsValid(sb_file));
ASSERT_TRUE(SbFileClose(sb_file));
}

void DeleteLibraryDirRecursively(const std::string& installation_path) {
std::string lib_path = base::StrCat(
{installation_path, kSbFileSepString, kEvergreenLibDirname});
ASSERT_TRUE(starboard::SbFileDeleteRecursive(lib_path.c_str(), false));
void DeleteLibrary(const std::string& name,
const std::string& installation_path) {
std::string lib_path = GetLibraryPath(name, installation_path);
struct stat file_info;
ASSERT_TRUE(stat(lib_path.c_str(), &file_info) == 0);
ASSERT_TRUE(SbFileDelete(lib_path.c_str()));
}

std::vector<char> temp_dir_path_;
Expand Down Expand Up @@ -437,7 +443,8 @@ TEST_F(UtilsTest,
"version": "1.2.0"
})json";
CreateManifest(manifest_content, installation_path);
CreateEmptyLibrary("libcobalt.so", installation_path);
std::string library_name = "libcobalt.so";
CreateEmptyLibrary(library_name, installation_path);

EvergreenLibraryMetadata metadata =
GetCurrentEvergreenLibraryMetadata(stub_get_extension_fn);
Expand All @@ -446,7 +453,7 @@ TEST_F(UtilsTest,
ASSERT_EQ(metadata.file_type, "Uncompressed");

DeleteManifest(installation_path);
DeleteLibraryDirRecursively(installation_path);
DeleteLibrary(library_name, installation_path);
}

TEST_F(UtilsTest,
Expand All @@ -472,14 +479,15 @@ TEST_F(UtilsTest,
[](const char* name) { return &kStubInstallationManagerApi; };

ASSERT_TRUE(EnsureDirectoryExists(installation_path.c_str()));
CreateEmptyLibrary("libcobalt.unexpected", installation_path);
std::string library_name = "libcobalt.unexpected";
CreateEmptyLibrary(library_name, installation_path);

EvergreenLibraryMetadata metadata =
GetCurrentEvergreenLibraryMetadata(stub_get_extension_fn);

ASSERT_EQ(metadata.file_type, "FileTypeUnknown");

DeleteLibraryDirRecursively(installation_path);
DeleteLibrary(library_name, installation_path);
}

TEST_F(UtilsTest,
Expand All @@ -506,7 +514,8 @@ TEST_F(UtilsTest,
"version": "1.2.0"
})json";
CreateManifest(manifest_content, installation_path);
CreateEmptyLibrary("libcobalt.lz4", installation_path);
std::string library_name = "libcobalt.lz4";
CreateEmptyLibrary(library_name, installation_path);

EvergreenLibraryMetadata metadata =
GetCurrentEvergreenLibraryMetadata(stub_get_extension_fn);
Expand All @@ -515,7 +524,7 @@ TEST_F(UtilsTest,
ASSERT_EQ(metadata.file_type, "Compressed");

DeleteManifest(installation_path);
DeleteLibraryDirRecursively(installation_path);
DeleteLibrary(library_name, installation_path);
}

} // namespace
Expand Down

0 comments on commit d9f923d

Please sign in to comment.