Skip to content

Commit 7a8283b

Browse files
committed
test: skip test if no git branch or git commit not found locally
Use CI-friendly git path (/usr/bin/git) just in case it's not in the GH runner's PATH.
1 parent 7fedb1d commit 7a8283b

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

src/test/java/io/weaviate/client6/v1/internal/BuildInfoTest.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,42 @@
55
import java.io.InputStreamReader;
66

77
import org.assertj.core.api.Assertions;
8+
import org.junit.Assume;
89
import org.junit.Test;
910

1011
public class BuildInfoTest {
12+
private static final String BRANCH = gitBranch();
13+
private static final String COMMIT_ID = gitCommit();
1114

1215
@Test
1316
public void testBuildInfo() throws IOException {
14-
Assertions.assertThat(BuildInfo.BRANCH).as("branch").isEqualTo(gitBranch());
15-
Assertions.assertThat(BuildInfo.COMMIT_ID).as("commit.full").isEqualTo(gitCommit());
16-
Assertions.assertThat(gitCommit()).as("commit.abbrev").startsWith(BuildInfo.COMMIT_ID_ABBREV);
17+
Assume.assumeNotNull(BRANCH, COMMIT_ID);
18+
Assume.assumeTrue("found git branch", !BRANCH.isBlank());
19+
Assume.assumeTrue("found git commit", !COMMIT_ID.isBlank());
20+
21+
Assertions.assertThat(BuildInfo.BRANCH).as("branch").isEqualTo(BRANCH);
22+
Assertions.assertThat(BuildInfo.COMMIT_ID).as("commit.full").isEqualTo(COMMIT_ID);
23+
Assertions.assertThat(COMMIT_ID).as("commit.abbrev").startsWith(BuildInfo.COMMIT_ID_ABBREV);
1724
}
1825

1926
/** Get current non-abbreviated Git commit hash. */
20-
private static String gitCommit() throws IOException {
21-
return runCommand("git", "rev-parse", "HEAD");
27+
private static String gitCommit() {
28+
return runCommand("/usr/bin/git", "rev-parse", "HEAD");
2229
}
2330

2431
/** Get current git branch. */
25-
private static String gitBranch() throws IOException {
26-
return runCommand("git", "branch", "--show-current");
32+
private static String gitBranch() {
33+
return runCommand("/usr/bin/git", "branch", "--show-current");
2734
}
2835

2936
/** Run shell command and return the output as multi-line string. */
30-
private static String runCommand(String... cmdarray) throws IOException {
31-
var process = Runtime.getRuntime().exec(cmdarray);
32-
var r = new BufferedReader(new InputStreamReader(process.getInputStream()));
33-
return String.join("\n", (Iterable<String>) () -> r.lines().iterator());
37+
private static String runCommand(String... cmdarray) {
38+
try {
39+
var process = Runtime.getRuntime().exec(cmdarray);
40+
var r = new BufferedReader(new InputStreamReader(process.getInputStream()));
41+
return String.join("\n", (Iterable<String>) () -> r.lines().iterator());
42+
} catch (IOException e) {
43+
return null;
44+
}
3445
}
3546
}

0 commit comments

Comments
 (0)