Skip to content

Commit 6f1bd8f

Browse files
authored
KAFKA-18973 gracefully stopping test execution if .git does not exist (#20703)
The test logic covers three main scenarios: 1. Running from the Kafka Root Directory Action: The test immediately finds the .git directory. Result: It uses this location to correctly find the schema file and runs the test successfully. 2. Running from a Subdirectory Action: The test searches up the directory tree (e.g., from generator/ or generator/src/test/java/). Result: It finds the .git directory at the Kafka root, uses that root to build the correct path to the schema file, and runs the test successfully. 3. Running from a Source Release (No Git) Action: The test searches all the way up the entire directory tree to the filesystem root. Result: It never finds the .git directory, and the test skips gracefully with a message. Reviewers: Chia-Ping Tsai <[email protected]>
1 parent 8c794fc commit 6f1bd8f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

generator/src/test/java/org/apache/kafka/message/checker/MetadataSchemaCheckerToolTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,26 @@
2727

2828
import static org.apache.kafka.message.checker.CheckerTestUtils.messageSpecStringToTempFile;
2929
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
3031

3132
public class MetadataSchemaCheckerToolTest {
3233
@Test
3334
public void testVerifyEvolutionGit() throws Exception {
34-
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
35-
Path rootKafkaDirectory = Paths.get("").toAbsolutePath();
36-
while (!Files.exists(rootKafkaDirectory.resolve(".git"))) {
37-
rootKafkaDirectory = rootKafkaDirectory.getParent();
38-
if (rootKafkaDirectory == null) {
39-
throw new RuntimeException("Invalid directory, need to be within a Git repository");
40-
}
35+
// Try to find the Git root directory
36+
Path rootKafkaDirectory = Paths.get("").toAbsolutePath();
37+
boolean gitFound = false;
38+
39+
while (rootKafkaDirectory != null) {
40+
if (Files.exists(rootKafkaDirectory.resolve(".git"))) {
41+
gitFound = true;
42+
break;
4143
}
44+
rootKafkaDirectory = rootKafkaDirectory.getParent();
45+
}
46+
47+
assumeTrue(gitFound, "Skipping test - not in a Git repository");
48+
49+
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
4250
Path schemaPath = rootKafkaDirectory.resolve("metadata/src/main/resources/common/metadata/AbortTransactionRecord.json");
4351
MetadataSchemaCheckerTool.run(
4452
// In the CI environment because the CI fetch command only creates HEAD and refs/remotes/pull/... references.

0 commit comments

Comments
 (0)