Test that OWNERS file with invalid keyword in per-file line cannot be parsed
This slighly increases the test coverage for
FindOwnersCodeOwnerConfigParser from 98.3% to 98.9%.
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I567160f3a6b59d01410da04c6e69e53e62e35808
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/findowners/FindOwnersCodeOwnerConfigParserTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/findowners/FindOwnersCodeOwnerConfigParserTest.java
index f0ec10b..7864b84 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/findowners/FindOwnersCodeOwnerConfigParserTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/findowners/FindOwnersCodeOwnerConfigParserTest.java
@@ -580,6 +580,26 @@
}
@Test
+ public void cannotParseCodeOwnerConfigWithPerFileLineThatHasAnInvalidImportKeyword()
+ throws Exception {
+ // The 'import' keyword doesn't exist
+ String invalidLine = "per-file foo=import /foo/bar/OWNERS";
+
+ CodeOwnerConfigParseException exception =
+ assertThrows(
+ CodeOwnerConfigParseException.class,
+ () ->
+ codeOwnerConfigParser.parse(
+ TEST_REVISION,
+ CodeOwnerConfig.Key.create(project, "master", "/"),
+ invalidLine));
+ assertThat(exception.getFullMessage(FindOwnersBackend.CODE_OWNER_CONFIG_FILE_NAME))
+ .isEqualTo(
+ String.format(
+ "invalid code owner config file '/OWNERS':\n" + " invalid line: %s", invalidLine));
+ }
+
+ @Test
public void perFileCodeOwnerConfigImportWithImportModeGlobalCodeOwnerSetsOnly() throws Exception {
CodeOwnerConfigReference codeOwnerConfigReference =
CodeOwnerConfigReference.builder(