Return proper error message if 'ext' operator is not supported by schema version

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I4b6711feb9274664ef8ee1ed07858a29e60cbad2
This commit is contained in:
Edwin Kempin
2019-01-25 13:05:42 +01:00
parent 38272e466f
commit b746dadf3e
2 changed files with 14 additions and 4 deletions

View File

@@ -735,13 +735,16 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
}
@Operator
public Predicate<ChangeData> ext(String ext) {
public Predicate<ChangeData> ext(String ext) throws QueryParseException {
return extension(ext);
}
@Operator
public Predicate<ChangeData> extension(String ext) {
return new FileExtensionPredicate(ext);
public Predicate<ChangeData> extension(String ext) throws QueryParseException {
if (args.getSchema().hasField(ChangeField.EXTENSION)) {
return new FileExtensionPredicate(ext);
}
throw new QueryParseException("'extension' operator is not supported by change index version");
}
@Operator

View File

@@ -1366,7 +1366,14 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
@Test
public void byExtension() throws Exception {
assume().that(getSchema().hasField(ChangeField.EXTENSION)).isTrue();
if (getSchemaVersion() < 52) {
assertMissingField(ChangeField.EXTENSION);
String unsupportedOperatorMsg =
"'extension' operator is not supported by change index version";
assertFailingQuery("extension:txt", unsupportedOperatorMsg);
assertFailingQuery("ext:txt", unsupportedOperatorMsg);
return;
}
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChangeWithFiles(repo, "foo.h", "foo.cc"));