VisibleRefFilterIT: Enable notedb
The set of tests and the expected value is almost exactly identical in the notedb/non-notedb case except for the presence of meta refs. Hack this into the assert method so we write the notedb-enabled version of tests, and meta refs are stripped from the expected sets in this case. This is fairly hacky, but avoids duplication of the test methods themselves (or, worse, forgetting to duplicate them.) Change-Id: I8bb071c920aa2c5be7b4d328036af735a020e1e1
This commit is contained in:
@@ -26,19 +26,36 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.notedb.NotesMigration;
|
||||
import com.google.gerrit.server.project.Util;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(ConfigSuite.class)
|
||||
public class VisibleRefFilterIT extends AbstractDaemonTest {
|
||||
@ConfigSuite.Config
|
||||
public static Config noteDbWriteEnabled() {
|
||||
Config cfg = new Config();
|
||||
cfg.setBoolean("notedb", null, "write", true);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Inject
|
||||
AllProjectsName allProjects;
|
||||
private AllProjectsName allProjects;
|
||||
|
||||
@Inject
|
||||
private NotesMigration notesMigration;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -79,7 +96,9 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
||||
assertRefs(
|
||||
"HEAD",
|
||||
"refs/changes/01/1/1",
|
||||
"refs/changes/01/1/meta",
|
||||
"refs/changes/02/2/1",
|
||||
"refs/changes/02/2/meta",
|
||||
"refs/heads/branch",
|
||||
"refs/heads/master");
|
||||
}
|
||||
@@ -92,7 +111,9 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
||||
assertRefs(
|
||||
"HEAD",
|
||||
"refs/changes/01/1/1",
|
||||
"refs/changes/01/1/meta",
|
||||
"refs/changes/02/2/1",
|
||||
"refs/changes/02/2/meta",
|
||||
"refs/heads/branch",
|
||||
"refs/heads/master",
|
||||
"refs/meta/config");
|
||||
@@ -106,6 +127,7 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
||||
assertRefs(
|
||||
"HEAD",
|
||||
"refs/changes/01/1/1",
|
||||
"refs/changes/01/1/meta",
|
||||
"refs/heads/master");
|
||||
}
|
||||
|
||||
@@ -116,16 +138,32 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
||||
|
||||
assertRefs(
|
||||
"refs/changes/02/2/1",
|
||||
"refs/changes/02/2/meta",
|
||||
"refs/heads/branch");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that refs seen by a non-admin user match expected.
|
||||
*
|
||||
* @param expected expected refs, in order. If notedb is disabled by the
|
||||
* configuration, any notedb refs (i.e. ending in "/meta") are removed
|
||||
* from the expected list before comparing to the actual results.
|
||||
* @throws Exception
|
||||
*/
|
||||
private void assertRefs(String... expected) throws Exception {
|
||||
String out = sshSession.exec(String.format(
|
||||
"gerrit ls-user-refs -p %s -u %s",
|
||||
project.get(), user.getId().get()));
|
||||
assertFalse(sshSession.getError(), sshSession.hasError());
|
||||
|
||||
List<String> filtered = new ArrayList<>(expected.length);
|
||||
for (String r : expected) {
|
||||
if (notesMigration.write() || !r.endsWith(RefNames.META_SUFFIX)) {
|
||||
filtered.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
Splitter s = Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings();
|
||||
assertEquals(Arrays.asList(expected),
|
||||
Ordering.natural().sortedCopy(s.split(out)));
|
||||
assertEquals(filtered, Ordering.natural().sortedCopy(s.split(out)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user