Add tests for checking notedb commits on change/ps creation
The new tests verify that a commit on the notedb branch is done when a new change or patch set is created. It asserts that the commit on the notedb branch has the correct author, committer and timestamp. Change-Id: I94208eba385b8ccd5d7733a113b3f5b007f13466 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.acceptance.api.change;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.TruthJUnit.assume;
|
||||
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
|
||||
import static com.google.gerrit.acceptance.PushOneCommit.SUBJECT;
|
||||
import static com.google.gerrit.extensions.client.ReviewerState.CC;
|
||||
@@ -58,11 +59,17 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.notedb.ChangeNoteUtil;
|
||||
import com.google.gerrit.server.project.Util;
|
||||
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -876,6 +883,42 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
.review(ReviewInput.approve());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notedbCommitsOnPatchSetCreation() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
PushOneCommit.Result r = createChange();
|
||||
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT,
|
||||
"b.txt", "4711", r.getChangeId()).to("refs/for/master").assertOkStatus();
|
||||
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
|
||||
try (Repository repo = repoManager.openMetadataRepository(project);
|
||||
RevWalk rw = new RevWalk(repo)) {
|
||||
RevCommit commitPatchSetCreation = rw.parseCommit(
|
||||
repo.exactRef(ChangeNoteUtil.changeRefName(new Change.Id(c._number)))
|
||||
.getObjectId());
|
||||
|
||||
PersonIdent expectedAuthor = ChangeNoteUtil.newIdent(
|
||||
accountCache.get(admin.id).getAccount(), c.updated,
|
||||
serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
|
||||
assertThat(commitPatchSetCreation.getAuthorIdent())
|
||||
.isEqualTo(expectedAuthor);
|
||||
assertThat(commitPatchSetCreation.getCommitterIdent())
|
||||
.isEqualTo(new PersonIdent(serverIdent.get(), c.updated));
|
||||
assertThat(commitPatchSetCreation.getParentCount()).isEqualTo(1);
|
||||
|
||||
RevCommit commitChangeCreation =
|
||||
rw.parseCommit(commitPatchSetCreation.getParent(0));
|
||||
expectedAuthor = ChangeNoteUtil.newIdent(
|
||||
accountCache.get(admin.id).getAccount(), c.created, serverIdent.get(),
|
||||
AnonymousCowardNameProvider.DEFAULT);
|
||||
assertThat(commitChangeCreation.getAuthorIdent())
|
||||
.isEqualTo(expectedAuthor);
|
||||
assertThat(commitChangeCreation.getCommitterIdent())
|
||||
.isEqualTo(new PersonIdent(serverIdent.get(), c.created));
|
||||
assertThat(commitChangeCreation.getParentCount()).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static Iterable<Account.Id> getReviewers(
|
||||
Collection<AccountInfo> r) {
|
||||
return Iterables.transform(r, new Function<AccountInfo, Account.Id>() {
|
||||
|
||||
@@ -26,10 +26,17 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
||||
import com.google.gerrit.server.notedb.ChangeNoteUtil;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gerrit.testutil.TestTimeUtil;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -95,6 +102,28 @@ public class CreateChangeIT extends AbstractDaemonTest {
|
||||
"draft workflow is disabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notedbCommit() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
ChangeInfo c = assertCreateSucceeds(newChangeInfo(ChangeStatus.NEW));
|
||||
try (Repository repo = repoManager.openMetadataRepository(project);
|
||||
RevWalk rw = new RevWalk(repo)) {
|
||||
RevCommit commit = rw.parseCommit(
|
||||
repo.exactRef(ChangeNoteUtil.changeRefName(new Change.Id(c._number)))
|
||||
.getObjectId());
|
||||
|
||||
PersonIdent expectedAuthor = ChangeNoteUtil.newIdent(
|
||||
accountCache.get(admin.id).getAccount(), c.created, serverIdent.get(),
|
||||
AnonymousCowardNameProvider.DEFAULT);
|
||||
assertThat(commit.getAuthorIdent()).isEqualTo(expectedAuthor);
|
||||
|
||||
assertThat(commit.getCommitterIdent())
|
||||
.isEqualTo(new PersonIdent(serverIdent.get(), c.created));
|
||||
assertThat(commit.getParentCount()).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
private ChangeInfo newChangeInfo(ChangeStatus status) {
|
||||
ChangeInfo in = new ChangeInfo();
|
||||
in.project = project.get();
|
||||
@@ -105,7 +134,7 @@ public class CreateChangeIT extends AbstractDaemonTest {
|
||||
return in;
|
||||
}
|
||||
|
||||
private void assertCreateSucceeds(ChangeInfo in) throws Exception {
|
||||
private ChangeInfo assertCreateSucceeds(ChangeInfo in) throws Exception {
|
||||
ChangeInfo out = gApi.changes().create(in).get();
|
||||
assertThat(out.branch).isEqualTo(in.branch);
|
||||
assertThat(out.subject).isEqualTo(in.subject);
|
||||
@@ -114,6 +143,7 @@ public class CreateChangeIT extends AbstractDaemonTest {
|
||||
assertThat(out.revisions).hasSize(1);
|
||||
Boolean draft = Iterables.getOnlyElement(out.revisions.values()).draft;
|
||||
assertThat(booleanToDraftStatus(draft)).isEqualTo(in.status);
|
||||
return out;
|
||||
}
|
||||
|
||||
private void assertCreateFails(ChangeInfo in,
|
||||
|
||||
Reference in New Issue
Block a user