Allow removing approvals from a label in the notedb
This allows the server to indicate a previously-saved approval is for a label that no longer exists or the user no longer has permissions to vote on. Reuse the "Label" footer, with "-Label-Name" indicating a tombstone. Change-Id: I8c390a28c639d1642aa434eb8c816d6c89f0ebdd
This commit is contained in:
@@ -21,6 +21,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -55,7 +56,9 @@ import com.google.gerrit.server.util.TimeUtil;
|
||||
import com.google.gerrit.testutil.FakeAccountCache;
|
||||
import com.google.gerrit.testutil.FakeRealm;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.StandardKeyEncoder;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.util.Providers;
|
||||
@@ -98,6 +101,7 @@ public class ChangeNotesTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
setTimeForTesting();
|
||||
KeyUtil.setEncoderImpl(new StandardKeyEncoder());
|
||||
|
||||
serverIdent = new PersonIdent(
|
||||
"Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
|
||||
@@ -206,6 +210,27 @@ public class ChangeNotesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void approvalTombstoneCommitFormat() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.removeApproval("Code-Review");
|
||||
update.commit();
|
||||
|
||||
RevWalk walk = new RevWalk(repo);
|
||||
try {
|
||||
RevCommit commit = walk.parseCommit(update.getRevision());
|
||||
walk.parseBody(commit);
|
||||
assertEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: -Code-Review\n",
|
||||
commit.getFullMessage());
|
||||
} finally {
|
||||
walk.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void approvalsOnePatchSet() throws Exception {
|
||||
Change c = newChange();
|
||||
@@ -320,6 +345,28 @@ public class ChangeNotesTest {
|
||||
assertEquals(truncate(after(c, 2000)), psas.get(1).getGranted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void approvalsTombstone() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Not-For-Long", (short) 1);
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
PatchSetApproval psa = Iterables.getOnlyElement(
|
||||
notes.getApprovals().get(c.currentPatchSetId()));
|
||||
assertEquals(1, psa.getAccountId().get());
|
||||
assertEquals("Not-For-Long", psa.getLabel());
|
||||
assertEquals((short) 1, psa.getValue());
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.removeApproval("Not-For-Long");
|
||||
update.commit();
|
||||
|
||||
notes = newNotes(c);
|
||||
assertTrue(notes.getApprovals().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleReviewers() throws Exception {
|
||||
Change c = newChange();
|
||||
|
Reference in New Issue
Block a user