Skip to content

Commit 246e87e

Browse files
committed
improve tests by using a dedicated 'git repo' for testing
1 parent 77ef143 commit 246e87e

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

src/test/java/pl/project13/core/AvailableGitTestRepo.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ public enum AvailableGitTestRepo {
116116
* </pre>
117117
*/
118118
WITH_THREE_COMMITS_AND_TWO_TAGS_CURRENTLY_ON_COMMIT_WITHOUT_TAG("src/test/resources/_git_three_commits_and_two_tags_currently_on_commit_without_tag"),
119+
/**
120+
* <pre>
121+
* 4862e42508099d359d791269f3735baff36d9102 a change in the root pom (HEAD, master)
122+
* 2b91f8b730121f66a833f771cb7241919fed5917 a change in submodule-two
123+
* 8e88956d45d57725463550f4406a54d12a46ae78 a change in submodule-one
124+
* 9c5d2e13d042b0acb71c48232a9c408e42da87f7 new repo for testing (based on git-commit-id-maven-debugging)
125+
* </pre>
126+
*/
127+
WITH_SUBMODULES_AND_MULTIPLE_COMMITS("src/test/resources/_git_with_submodules_and_multiple_commits"),
119128
// TODO: Why do the tests get stuck when we use .git??
120129
MAVEN_GIT_COMMIT_ID_PLUGIN("src/test/resources/_git_one_commit_with_umlaut")
121130
;

src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
3030
import org.junit.jupiter.params.ParameterizedTest;
31+
import org.junit.jupiter.params.provider.Arguments;
3132
import org.junit.jupiter.params.provider.MethodSource;
3233
import pl.project13.core.git.GitDescribeConfig;
3334
import pl.project13.core.util.GenericFileManager;
@@ -43,17 +44,16 @@
4344
import java.util.*;
4445
import java.util.regex.Pattern;
4546
import java.util.stream.Collectors;
47+
import java.util.stream.Stream;
4648

47-
import static java.util.Arrays.asList;
4849
import static org.assertj.core.api.Assertions.assertThat;
4950

5051
public class GitCommitIdPluginIntegrationTest {
51-
public static Collection<?> useNativeGit() {
52-
return asList(true, false);
53-
}
54-
55-
public static Collection<?> useDirty() {
56-
return asList(true, false);
52+
public static Stream<Arguments> useNativeGit() {
53+
return Stream.of(
54+
Arguments.of(true),
55+
Arguments.of(false)
56+
);
5757
}
5858

5959
private Path sandbox;
@@ -1743,38 +1743,48 @@ public void verifyAllowedCharactersForEvaluateOnCommit() {
17431743
Assertions.assertFalse(p.matcher("&&cat /etc/passwd").matches());
17441744
}
17451745

1746+
static Stream<Arguments> useNativeGitWithSubmoduleName() {
1747+
return useNativeGit().flatMap(arg ->
1748+
Stream.of(
1749+
"submodule-one",
1750+
"submodule-two"
1751+
).map(str ->
1752+
Arguments.of(arg.get()[0], str)
1753+
)
1754+
);
1755+
}
1756+
17461757
@ParameterizedTest
1747-
@MethodSource("useNativeGit")
1748-
public void shouldGiveCommitIdForEachFolderWhenPerModuleVersionsEnabled(boolean useNativeGit) throws Exception {
1758+
@MethodSource("useNativeGitWithSubmoduleName")
1759+
public void shouldGiveCommitIdForEachFolderWhenPerModuleVersionsEnabled(boolean useNativeGit, String submoduleName) throws Exception {
17491760
// given
1750-
File dotGitDirectory = createTmpDotGitDirectory(AvailableGitTestRepo.GIT_COMMIT_ID);
1761+
File dotGitDirectory = createTmpDotGitDirectory(AvailableGitTestRepo.WITH_SUBMODULES_AND_MULTIPLE_COMMITS);
17511762

1752-
GitCommitIdPlugin.Callback cbSrc =
1753-
new GitCommitIdTestCallback()
1754-
.setDotGitDirectory(dotGitDirectory)
1755-
.setUseNativeGit(useNativeGit)
1756-
.setPerModuleVersions(true)
1757-
.setModuleBaseDir(dotGitDirectory.getParentFile().toPath().resolve("src").toFile())
1758-
.build();
1759-
Properties propertiesSrcFolder = new Properties();
1760-
1761-
GitCommitIdPlugin.Callback cbSrcTest =
1763+
GitCommitIdPlugin.Callback cb =
17621764
new GitCommitIdTestCallback()
17631765
.setDotGitDirectory(dotGitDirectory)
17641766
.setUseNativeGit(useNativeGit)
17651767
.setPerModuleVersions(true)
1766-
.setModuleBaseDir(dotGitDirectory.getParentFile().toPath().resolve("src/test").toFile())
1768+
.setModuleBaseDir(dotGitDirectory.getParentFile().toPath().resolve(submoduleName).toFile())
17671769
.build();
1768-
Properties propertiesSrcTestFolder = new Properties();
1770+
Properties properties = new Properties();
17691771

17701772
// when
1771-
GitCommitIdPlugin.runPlugin(cbSrc, propertiesSrcFolder);
1772-
GitCommitIdPlugin.runPlugin(cbSrcTest, propertiesSrcTestFolder);
1773+
GitCommitIdPlugin.runPlugin(cb, properties);
17731774

17741775
// then
1775-
assertThat(propertiesSrcFolder).containsKey("git.commit.id");
1776-
assertThat(propertiesSrcTestFolder).containsKey("git.commit.id");
1777-
assertThat(propertiesSrcFolder.getProperty("git.commit.id")).isNotEqualTo(propertiesSrcTestFolder.getProperty("git.commit.id"));
1776+
assertThat(properties).containsKey("git.commit.id");
1777+
1778+
String expectedGitCommitId = null;
1779+
if (submoduleName.equals("submodule-one")) {
1780+
expectedGitCommitId = "8e88956d45d57725463550f4406a54d12a46ae78";
1781+
} else if (submoduleName.equals("submodule-two")) {
1782+
expectedGitCommitId = "2b91f8b730121f66a833f771cb7241919fed5917";
1783+
}
1784+
assertThat(expectedGitCommitId).isNotNull();
1785+
assertThat(properties.getProperty("git.commit.id"))
1786+
.as("useNativeGit=%s", useNativeGit)
1787+
.isEqualTo(expectedGitCommitId);
17781788
}
17791789

17801790
private GitDescribeConfig createGitDescribeConfig(boolean forceLongFormat, int abbrev) {

src/test/resources

Submodule resources updated 49 files

0 commit comments

Comments
 (0)