Add unit test for copying label approvals during cherry-pick
I761fd1f2d added the missing functionality, but missed to add a unit test. Bug: Issue 2652 Change-Id: Ie9ff7d84454f9008ff9372e4def285d960afc4df
This commit is contained in:

committed by
David Ostrovsky

parent
ef12658443
commit
45a66044cd
@@ -21,6 +21,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.LabelInfo;
|
||||
@@ -217,6 +218,63 @@ public class LabelTypeIT extends AbstractDaemonTest {
|
||||
assertApproval(r3, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyAllScoresOnTrivialRebaseAndCherryPick() throws Exception {
|
||||
codeReview.setCopyAllScoresOnTrivialRebase(true);
|
||||
saveLabelConfig();
|
||||
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
git.checkout().setName(r1.getCommit().name()).call();
|
||||
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
|
||||
PushOneCommit.SUBJECT, "b.txt", "other contents");
|
||||
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
|
||||
|
||||
revision(r2).review(ReviewInput.recommend());
|
||||
|
||||
CherryPickInput in = new CherryPickInput();
|
||||
in.destination = "master";
|
||||
in.message = String.format("%s\n\nChange-Id: %s",
|
||||
PushOneCommit.SUBJECT,
|
||||
r2.getChangeId());
|
||||
|
||||
doAssertApproval(1,
|
||||
gApi.changes()
|
||||
.id(r2.getChangeId())
|
||||
.revision(r2.getCommit().name())
|
||||
.cherryPick(in)
|
||||
.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyNoScoresOnReworkAndCherryPick()
|
||||
throws Exception {
|
||||
codeReview.setCopyAllScoresOnTrivialRebase(true);
|
||||
saveLabelConfig();
|
||||
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
|
||||
git.checkout().setName(r1.getCommit().name()).call();
|
||||
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
|
||||
PushOneCommit.SUBJECT, "b.txt", "other contents");
|
||||
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
|
||||
|
||||
revision(r2).review(ReviewInput.recommend());
|
||||
|
||||
CherryPickInput in = new CherryPickInput();
|
||||
in.destination = "master";
|
||||
in.message = String.format("Cherry pick\n\nChange-Id: %s",
|
||||
r2.getChangeId());
|
||||
|
||||
doAssertApproval(0,
|
||||
gApi.changes()
|
||||
.id(r2.getChangeId())
|
||||
.revision(r2.getCommit().name())
|
||||
.cherryPick(in)
|
||||
.get());
|
||||
}
|
||||
|
||||
private void saveLabelConfig() throws Exception {
|
||||
ProjectConfig cfg = projectCache.checkedGet(allProjects).getConfig();
|
||||
cfg.getLabelSections().clear();
|
||||
@@ -254,6 +312,10 @@ public class LabelTypeIT extends AbstractDaemonTest {
|
||||
// Don't use asserts from PushOneCommit so we can test the round-trip
|
||||
// through JSON instead of querying the DB directly.
|
||||
ChangeInfo c = get(r.getChangeId());
|
||||
doAssertApproval(expected, c);
|
||||
}
|
||||
|
||||
private void doAssertApproval(int expected, ChangeInfo c) {
|
||||
LabelInfo cr = c.labels.get("Code-Review");
|
||||
assertEquals(1, cr.all.size());
|
||||
assertEquals("Administrator", cr.all.get(0).name);
|
||||
|
Reference in New Issue
Block a user