Skip to content

Commit c05b619

Browse files
authored
Fix VCS test (#597)
* Fix VCS test Copy test resource to a new test folder and test vcs extraction. instead of relaying on the existence of this project .git folder. * Fix Gradle tests
1 parent 02f38f3 commit c05b619

18 files changed

+34
-14
lines changed

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/GitUtils.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import org.eclipse.jgit.lib.Repository;
77
import org.eclipse.jgit.revwalk.RevCommit;
88
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
9-
import org.jfrog.build.extractor.ci.Vcs;
109
import org.jfrog.build.api.util.Log;
10+
import org.jfrog.build.extractor.ci.Vcs;
1111

1212
import java.io.BufferedReader;
1313
import java.io.File;
@@ -196,7 +196,6 @@ private static String extractVcsMessage(File dotGit, Log log) throws IOException
196196
Repository repository = repositoryBuilder.setGitDir(dotGit)
197197
.readEnvironment()
198198
.findGitDir()
199-
.setMustExist(true)
200199
.build();
201200
RevCommit latestCommit;
202201
try {
@@ -206,7 +205,7 @@ private static String extractVcsMessage(File dotGit, Log log) throws IOException
206205
return "";
207206
}
208207

209-
return latestCommit.getFullMessage();
208+
return latestCommit.getFullMessage().trim();
210209
}
211210

212211
/**

build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/util/GitUtilsTest.java

+19-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@ public class GitUtilsTest {
2121
* Tests extracting Vcs details manually by comparing results to those received from the git executable
2222
*/
2323
@Test
24-
private void testReadGitConfig() throws IOException, InterruptedException {
25-
File curDir = new File("").getAbsoluteFile();
26-
Log testLog = new TestingLog();
27-
Vcs vcs = GitUtils.extractVcs(curDir, testLog);
28-
29-
Assert.assertNotNull(vcs);
30-
Assert.assertEquals(vcs.getUrl(), getGitUrlWithExecutor(curDir, testLog));
31-
Assert.assertEquals(vcs.getRevision(), getGitRevisionWithExecutor(curDir, testLog));
32-
Assert.assertEquals(vcs.getBranch(), getGitBranchWithExecutor(curDir, testLog));
33-
Assert.assertEquals(vcs.getMessage(), getGitMessageWithExecutor(curDir, testLog));
24+
private void testReadGitConfig() throws IOException, InterruptedException, URISyntaxException {
25+
String gitResource = "git_simple_.git_suffix";
26+
File testResourcesPath = new File(this.getClass().getResource("/gitutils").toURI()).getCanonicalFile();
27+
File dotGitDir = new File(testResourcesPath, ".git").getAbsoluteFile();
28+
try {
29+
FileUtils.copyDirectory(new File(testResourcesPath, gitResource), dotGitDir);
30+
Log testLog = new TestingLog();
31+
Vcs vcs = GitUtils.extractVcs(dotGitDir, testLog);
32+
33+
Assert.assertNotNull(vcs);
34+
Assert.assertEquals(vcs.getUrl(), getGitUrlWithExecutor(dotGitDir, testLog));
35+
Assert.assertEquals(vcs.getRevision(), getGitRevisionWithExecutor(dotGitDir, testLog));
36+
Assert.assertEquals(vcs.getBranch(), getGitBranchWithExecutor(dotGitDir, testLog));
37+
Assert.assertEquals(vcs.getMessage(), getGitMessageWithExecutor(dotGitDir, testLog));
38+
39+
} finally {
40+
// Cleanup.
41+
FileUtils.deleteDirectory(dotGitDir);
42+
}
3443
}
3544

3645
private String getGitFieldWithExecutor(File execDir, Log log, List<String> args) throws IOException, InterruptedException {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[remote "origin"]
2+
url = https://github.com/jfrog/jfrog-cli-go.git
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0000000000000000000000000000000000000000 90d9cc9bf05666e6910bdfa4f914e96c706454c3 barbelity <barb@jfrog.com> 1550163053 +0200 commit (initial): TEST-1 - Adding file1.txt
2+
90d9cc9bf05666e6910bdfa4f914e96c706454c3 6198a6294722fdc75a570aac505784d2ec0d1818 barbelity <barb@jfrog.com> 1550163093 +0200 commit: TEST-2 - Adding text to file1.txt
3+
6198a6294722fdc75a570aac505784d2ec0d1818 a9eecfb2a71b8b0a73ecf027faf6d6f3739575dd barbelity <barb@jfrog.com> 1550172526 +0200 commit: TEST-3 - Adding file2.txt
4+
a9eecfb2a71b8b0a73ecf027faf6d6f3739575dd b033a0e508bdb52eee25654c9e12db33ff01b8ff barbelity <barb@jfrog.com> 1550172571 +0200 commit: TEST-4 - Adding text to file2.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��K
2+
�0@]����̴�� � O��|Z+�H����������y �]�)�'�QB���F�4��4�xOܢ�N=%����Ή���D} ��� �ٺ6R
3+
:�C��U�k/٧i,8�����:�a����-1�k�Zmv{+�J�.�[�@��e�~���]�TKEy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b033a0e508bdb52eee25654c9e12db33ff01b8ff

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ subprojects {
107107
from {
108108
configurations.uberJar.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
109109
}
110+
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
110111
with jar
111112
archiveClassifier.set('uber')
112113
}
@@ -266,7 +267,7 @@ project('build-info-extractor') {
266267
apply plugin: 'java-test-fixtures'
267268
description = 'JFrog Build-Info Extractor'
268269
dependencies {
269-
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.1.16.202106041830-r'
270+
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
270271
implementation project(':build-info-client')
271272
implementation project(':build-info-api')
272273

0 commit comments

Comments
 (0)