Speed up masterlist tests

By cloning from a local bare repository instead of from GitHub.
This commit is contained in:
Oliver Hamlet
2020-06-14 10:36:11 +01:00
parent ccd6e94d84
commit b24f2856b7
3 changed files with 70 additions and 25 deletions
+21
View File
@@ -440,6 +440,27 @@ add_custom_command(TARGET libloot_tests POST_BUILD
${SOURCE_DIR}
"$<TARGET_FILE_DIR:libloot_tests>/testing-metadata")
IF (GIT_FOUND)
# Clone a mirror of the testing-metadata repository for faster tests.
# Remove the directory if it already exists before cloning, as the clone
# will fail if the target directory exists and is not empty.
# Tests will fail if this is not done.
add_custom_command(TARGET libloot_internals_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory
"$<TARGET_FILE_DIR:libloot_internals_tests>/testing-metadata.git")
add_custom_command(TARGET libloot_internals_tests POST_BUILD
COMMAND git clone --bare https://github.com/loot/testing-metadata.git "$<TARGET_FILE_DIR:libloot_internals_tests>/testing-metadata.git")
add_custom_command(TARGET libloot_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory
"$<TARGET_FILE_DIR:libloot_tests>/testing-metadata.git")
add_custom_command(TARGET libloot_tests POST_BUILD
COMMAND git clone --bare https://github.com/loot/testing-metadata.git "$<TARGET_FILE_DIR:libloot_tests>/testing-metadata.git")
ENDIF()
# Copy testing plugins
ExternalProject_Get_Property(testing-plugins SOURCE_DIR)
add_custom_command(TARGET libloot_internals_tests POST_BUILD
@@ -36,7 +36,7 @@ protected:
DatabaseInterfaceTest() :
db_(nullptr),
userlistPath_(localPath / "userlist.yaml"),
url_("https://github.com/loot/testing-metadata.git"),
url_("./testing-metadata.git"),
branch_("master"),
oldBranch_("old-branch"),
minimalOutputPath_(localPath / "minimal.yml"),
+48 -24
View File
@@ -36,9 +36,10 @@ protected:
MasterlistTest() :
repoBranch("master"),
oldBranch("old-branch"),
repoUrl("https://github.com/loot/testing-metadata.git"),
repoPath("./testing-metadata.git"),
masterlistPath(localPath / "masterlist.yaml"),
nonAsciiMasterlistPath(localPath / std::filesystem::u8path(u8"masterl\u00EDst.yaml")) {}
nonAsciiMasterlistPath(
localPath / std::filesystem::u8path(u8"masterl\u00EDst.yaml")) {}
void SetUp() {
CommonGameTestFixture::SetUp();
@@ -60,7 +61,7 @@ protected:
std::filesystem::current_path(testPath);
}
const std::string repoUrl;
const std::string repoPath;
const std::string repoBranch;
const std::string oldBranch;
@@ -82,28 +83,28 @@ INSTANTIATE_TEST_CASE_P(,
TEST_P(MasterlistTest, updateShouldThrowIfAnInvalidPathIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update("//\?", repoUrl, repoBranch),
EXPECT_THROW(masterlist.Update("//\?", repoPath, repoBranch),
std::system_error);
}
TEST_P(MasterlistTest, updateShouldThrowIfABlankPathIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update("", repoUrl, repoBranch),
EXPECT_THROW(masterlist.Update("", repoPath, repoBranch),
std::invalid_argument);
}
TEST_P(MasterlistTest, updateShouldThrowIfABranchThatDoesNotExistIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(masterlistPath, repoUrl, "missing-branch"),
EXPECT_THROW(masterlist.Update(masterlistPath, repoPath, "missing-branch"),
std::system_error);
}
TEST_P(MasterlistTest, updateShouldThrowIfABlankBranchIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(masterlistPath, repoUrl, ""),
EXPECT_THROW(masterlist.Update(masterlistPath, repoPath, ""),
std::invalid_argument);
}
@@ -122,38 +123,60 @@ TEST_P(MasterlistTest, updateShouldThrowIfABlankUrlIsGiven) {
std::invalid_argument);
}
TEST_P(MasterlistTest, updateShouldBeAbleToCloneAGitHubRepository) {
Masterlist masterlist;
EXPECT_NO_THROW(
masterlist.Update(masterlistPath,
"https://github.com/loot/testing-metadata.git",
repoBranch));
EXPECT_TRUE(std::filesystem::exists(masterlistPath));
}
TEST_P(MasterlistTest, updateShouldBeAbleToCloneALocalRepository) {
Masterlist masterlist;
EXPECT_NO_THROW(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_TRUE(std::filesystem::exists(masterlistPath));
}
TEST_P(MasterlistTest, updateShouldReturnTrueIfNoMasterlistExists) {
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
EXPECT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_TRUE(std::filesystem::exists(masterlistPath));
}
TEST_P(MasterlistTest, updateShouldReturnFalseIfAnUpToDateMasterlistExists) {
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
EXPECT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_FALSE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
EXPECT_FALSE(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_TRUE(std::filesystem::exists(masterlistPath));
}
TEST_P(MasterlistTest, updateShouldReturnFalseIfAnUpToDateMasterlistWithANonAsciiFilenameExists) {
TEST_P(
MasterlistTest,
updateShouldReturnFalseIfAnUpToDateMasterlistWithANonAsciiFilenameExists) {
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(nonAsciiMasterlistPath, repoUrl, repoBranch));
EXPECT_TRUE(masterlist.Update(nonAsciiMasterlistPath, repoPath, repoBranch));
EXPECT_TRUE(std::filesystem::exists(nonAsciiMasterlistPath));
EXPECT_FALSE(masterlist.Update(nonAsciiMasterlistPath, repoUrl, repoBranch));
EXPECT_FALSE(masterlist.Update(nonAsciiMasterlistPath, repoPath, repoBranch));
EXPECT_TRUE(std::filesystem::exists(nonAsciiMasterlistPath));
}
TEST_P(MasterlistTest,
updateShouldDiscardLocalHistoryIfRemoteHistoryIsDifferent) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
runRepoCommand("git config commit.gpgsign false");
runRepoCommand("git commit --amend -m \"changing local history\"");
EXPECT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
EXPECT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_TRUE(std::filesystem::exists(masterlistPath));
}
TEST_P(MasterlistTest, getInfoShouldThrowIfNoMasterlistExistsAtTheGivenPath) {
@@ -174,7 +197,7 @@ TEST_P(
MasterlistTest,
getInfoShouldReturnRevisionAndDateStringsOfTheCorrectLengthsWhenRequestingALongId) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
MasterlistInfo info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(40, info.revision_id.length());
@@ -186,7 +209,7 @@ TEST_P(
MasterlistTest,
getInfoShouldReturnRevisionAndDateStringsOfTheCorrectLengthsWhenRequestingAShortId) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
MasterlistInfo info = masterlist.GetInfo(masterlistPath, true);
EXPECT_GE((unsigned)40, info.revision_id.length());
@@ -199,7 +222,7 @@ TEST_P(
MasterlistTest,
getInfoShouldAppendSuffixesToReturnedStringsIfTheMasterlistHasBeenEdited) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
std::ofstream out(masterlistPath);
out.close();
@@ -210,11 +233,12 @@ TEST_P(
}
TEST_P(MasterlistTest,
getInfoShouldDetectWhenAMasterlistWithANonAsciiFilenameHasBeenEdited) {
getInfoShouldDetectWhenAMasterlistWithANonAsciiFilenameHasBeenEdited) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
auto nonAsciiPath = masterlistPath.parent_path() / std::filesystem::u8path(u8"non\u00C1scii.yaml");
auto nonAsciiPath = masterlistPath.parent_path() /
std::filesystem::u8path(u8"non\u00C1scii.yaml");
std::filesystem::copy_file(masterlistPath, nonAsciiPath);
runRepoCommand("git add " + nonAsciiPath.string());
@@ -237,7 +261,7 @@ TEST_P(MasterlistTest,
TEST_P(MasterlistTest, isLatestShouldThrowIfTheGivenBranchIsAnEmptyString) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_THROW(Masterlist::IsLatest(masterlistPath, ""), std::invalid_argument);
}
@@ -246,7 +270,7 @@ TEST_P(
MasterlistTest,
isLatestShouldReturnFalseIfTheCurrentRevisionIsNotTheLatestRevisionInTheGivenBranch) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, oldBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, oldBranch));
EXPECT_FALSE(Masterlist::IsLatest(masterlistPath, repoBranch));
}
@@ -255,7 +279,7 @@ TEST_P(
MasterlistTest,
isLatestShouldReturnTrueIfTheCurrentRevisionIsTheLatestRevisioninTheGivenBranch) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
ASSERT_TRUE(masterlist.Update(masterlistPath, repoPath, repoBranch));
EXPECT_TRUE(Masterlist::IsLatest(masterlistPath, repoBranch));
}