Skip to content

Commit 0ea761b

Browse files
committed
test: skip test if no git branch or git commit found locally
1 parent 7fedb1d commit 0ea761b

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,40 @@
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+
19+
Assertions.assertThat(BuildInfo.BRANCH).as("branch").isEqualTo(BRANCH);
20+
Assertions.assertThat(BuildInfo.COMMIT_ID).as("commit.full").isEqualTo(COMMIT_ID);
21+
Assertions.assertThat(COMMIT_ID).as("commit.abbrev").startsWith(BuildInfo.COMMIT_ID_ABBREV);
1722
}
1823

1924
/** Get current non-abbreviated Git commit hash. */
20-
private static String gitCommit() throws IOException {
25+
private static String gitCommit() {
2126
return runCommand("git", "rev-parse", "HEAD");
2227
}
2328

2429
/** Get current git branch. */
25-
private static String gitBranch() throws IOException {
30+
private static String gitBranch() {
2631
return runCommand("git", "branch", "--show-current");
2732
}
2833

2934
/** 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());
35+
private static String runCommand(String... cmdarray) {
36+
try {
37+
var process = Runtime.getRuntime().exec(cmdarray);
38+
var r = new BufferedReader(new InputStreamReader(process.getInputStream()));
39+
return String.join("\n", (Iterable<String>) () -> r.lines().iterator());
40+
} catch (IOException e) {
41+
return null;
42+
}
3443
}
3544
}

0 commit comments

Comments
 (0)