Add more test coverage for ListFiles
This change adds two tests for ListFiles, which covers the code paths when 'base' or 'query' field is set. Bug: Issue 6189 Change-Id: I6afd2881abb46732ea9a973d1ba7f21d6b23506a
This commit is contained in:
@@ -887,6 +887,54 @@ public class RevisionIT extends AbstractDaemonTest {
|
||||
.containsExactly(COMMIT_MSG, MERGE_LIST, "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFilesOnDifferentBases() throws Exception {
|
||||
PushOneCommit.Result result1 = createChange();
|
||||
String changeId = result1.getChangeId();
|
||||
PushOneCommit.Result result2 = amendChange(changeId, SUBJECT, "b.txt", "b");
|
||||
PushOneCommit.Result result3 = amendChange(changeId, SUBJECT, "c.txt", "c");
|
||||
|
||||
String revId1 = result1.getCommit().name();
|
||||
String revId2 = result2.getCommit().name();
|
||||
String revId3 = result3.getCommit().name();
|
||||
|
||||
assertThat(gApi.changes().id(changeId).revision(revId1).files(null).keySet())
|
||||
.containsExactly(COMMIT_MSG, "a.txt");
|
||||
assertThat(gApi.changes().id(changeId).revision(revId2).files(null).keySet())
|
||||
.containsExactly(COMMIT_MSG, "a.txt", "b.txt");
|
||||
assertThat(gApi.changes().id(changeId).revision(revId3).files(null).keySet())
|
||||
.containsExactly(COMMIT_MSG, "a.txt", "b.txt", "c.txt");
|
||||
|
||||
assertThat(gApi.changes().id(changeId).revision(revId2).files(revId1).keySet())
|
||||
.containsExactly(COMMIT_MSG, "b.txt");
|
||||
assertThat(gApi.changes().id(changeId).revision(revId3).files(revId1).keySet())
|
||||
.containsExactly(COMMIT_MSG, "b.txt", "c.txt");
|
||||
assertThat(gApi.changes().id(changeId).revision(revId3).files(revId2).keySet())
|
||||
.containsExactly(COMMIT_MSG, "c.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryRevisionFiles() throws Exception {
|
||||
Map<String, String> files = ImmutableMap.of("file1.txt", "content 1", "file2.txt", "content 2");
|
||||
PushOneCommit.Result result =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo, SUBJECT, files).to("refs/for/master");
|
||||
result.assertOkStatus();
|
||||
String changeId = result.getChangeId();
|
||||
|
||||
assertThat(gApi.changes().id(changeId).current().queryFiles("file1.txt"))
|
||||
.containsExactly("file1.txt");
|
||||
assertThat(gApi.changes().id(changeId).current().queryFiles("file2.txt"))
|
||||
.containsExactly("file2.txt");
|
||||
assertThat(gApi.changes().id(changeId).current().queryFiles("file1"))
|
||||
.containsExactly("file1.txt");
|
||||
assertThat(gApi.changes().id(changeId).current().queryFiles("file2"))
|
||||
.containsExactly("file2.txt");
|
||||
assertThat(gApi.changes().id(changeId).current().queryFiles("file"))
|
||||
.containsExactly("file1.txt", "file2.txt");
|
||||
assertThat(gApi.changes().id(changeId).current().queryFiles(""))
|
||||
.containsExactly("file1.txt", "file2.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void description() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
|
||||
@@ -69,6 +69,8 @@ public interface RevisionApi {
|
||||
|
||||
Map<String, FileInfo> files(int parentNum) throws RestApiException;
|
||||
|
||||
List<String> queryFiles(String query) throws RestApiException;
|
||||
|
||||
FileApi file(String path);
|
||||
|
||||
CommitInfo commit(boolean addLinks) throws RestApiException;
|
||||
@@ -238,6 +240,11 @@ public interface RevisionApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryFiles(String query) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileApi file(String path) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.api.changes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -387,6 +388,17 @@ class RevisionApiImpl implements RevisionApi {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<String> queryFiles(String query) throws RestApiException {
|
||||
try {
|
||||
checkArgument(query != null, "no query provided");
|
||||
return (List<String>) listFiles.setQuery(query).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve files", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileApi file(String path) {
|
||||
return fileApi.create(files.parse(revision, IdString.fromDecoded(path)));
|
||||
|
||||
@@ -316,6 +316,11 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
}
|
||||
}
|
||||
|
||||
public ListFiles setQuery(String query) {
|
||||
this.query = query;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListFiles setBase(String base) {
|
||||
this.base = base;
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user