Add tests for submit whole topic on multiple projects/branches
Change-Id: I9ac7b5c7743e7c931859900ce4333ffe6914cd4b
This commit is contained in:
@@ -26,6 +26,7 @@ import com.google.common.collect.Iterables;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.primitives.Chars;
|
import com.google.common.primitives.Chars;
|
||||||
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
|
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
|
||||||
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.data.AccessSection;
|
import com.google.gerrit.common.data.AccessSection;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.common.data.PermissionRule;
|
import com.google.gerrit.common.data.PermissionRule;
|
||||||
@@ -37,6 +38,7 @@ import com.google.gerrit.extensions.api.projects.BranchInput;
|
|||||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||||
|
import com.google.gerrit.extensions.client.SubmitType;
|
||||||
import com.google.gerrit.extensions.common.ActionInfo;
|
import com.google.gerrit.extensions.common.ActionInfo;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.EditInfo;
|
import com.google.gerrit.extensions.common.EditInfo;
|
||||||
@@ -353,10 +355,18 @@ public abstract class AbstractDaemonTest {
|
|||||||
protected Project.NameKey createProject(String nameSuffix,
|
protected Project.NameKey createProject(String nameSuffix,
|
||||||
Project.NameKey parent, boolean createEmptyCommit)
|
Project.NameKey parent, boolean createEmptyCommit)
|
||||||
throws RestApiException {
|
throws RestApiException {
|
||||||
|
return createProject(
|
||||||
|
nameSuffix, parent, createEmptyCommit, SubmitType.MERGE_IF_NECESSARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Project.NameKey createProject(String nameSuffix,
|
||||||
|
Project.NameKey parent, boolean createEmptyCommit, SubmitType submitType)
|
||||||
|
throws RestApiException {
|
||||||
ProjectInput in = new ProjectInput();
|
ProjectInput in = new ProjectInput();
|
||||||
in.name = name(nameSuffix);
|
in.name = name(nameSuffix);
|
||||||
in.parent = parent != null ? parent.get() : null;
|
in.parent = parent != null ? parent.get() : null;
|
||||||
in.createEmptyCommit = createEmptyCommit;
|
in.createEmptyCommit = createEmptyCommit;
|
||||||
|
in.submitType = submitType;
|
||||||
return createProject(in);
|
return createProject(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,4 +652,13 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
})).containsExactly((Object[])expected).inOrder();
|
})).containsExactly((Object[])expected).inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TestRepository<?> createProjectWithPush(String name,
|
||||||
|
@Nullable Project.NameKey parent,
|
||||||
|
SubmitType submitType) throws Exception {
|
||||||
|
Project.NameKey project = createProject(name, parent, true, submitType);
|
||||||
|
grant(Permission.PUSH, project, "refs/heads/*");
|
||||||
|
grant(Permission.SUBMIT, project, "refs/for/refs/heads/*");
|
||||||
|
return cloneProject(project);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import com.google.gerrit.common.EventListener;
|
|||||||
import com.google.gerrit.common.EventSource;
|
import com.google.gerrit.common.EventSource;
|
||||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||||
import com.google.gerrit.extensions.api.projects.BranchInfo;
|
import com.google.gerrit.extensions.api.projects.BranchInfo;
|
||||||
|
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||||
@@ -143,22 +144,100 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
assertThat(getRemoteHead().getId()).isEqualTo(change.getCommitId());
|
assertThat(getRemoteHead().getId()).isEqualTo(change.getCommitId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void submitWholeTopicMultipleProjects() throws Exception {
|
||||||
|
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
||||||
|
String topic = "test-topic";
|
||||||
|
|
||||||
|
// Create test projects
|
||||||
|
TestRepository<?> repoA = createProjectWithPush(
|
||||||
|
"project-a", null, getSubmitType());
|
||||||
|
TestRepository<?> repoB = createProjectWithPush(
|
||||||
|
"project-b", null, getSubmitType());
|
||||||
|
|
||||||
|
// Create changes on project-a
|
||||||
|
PushOneCommit.Result change1 =
|
||||||
|
createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
|
||||||
|
PushOneCommit.Result change2 =
|
||||||
|
createChange(repoA, "master", "Change 2", "b.txt", "content", topic);
|
||||||
|
|
||||||
|
// Create changes on project-b
|
||||||
|
PushOneCommit.Result change3 =
|
||||||
|
createChange(repoB, "master", "Change 3", "a.txt", "content", topic);
|
||||||
|
PushOneCommit.Result change4 =
|
||||||
|
createChange(repoB, "master", "Change 4", "b.txt", "content", topic);
|
||||||
|
|
||||||
|
approve(change1.getChangeId());
|
||||||
|
approve(change2.getChangeId());
|
||||||
|
approve(change3.getChangeId());
|
||||||
|
approve(change4.getChangeId());
|
||||||
|
submit(change4.getChangeId());
|
||||||
|
|
||||||
|
String expectedTopic = name(topic);
|
||||||
|
change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
change3.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
change4.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void submitWholeTopicMultipleBranchesOnSameProject() throws Exception {
|
||||||
|
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
||||||
|
String topic = "test-topic";
|
||||||
|
|
||||||
|
// Create test project
|
||||||
|
TestRepository<?> repoA = createProjectWithPush(
|
||||||
|
"project-a", null, getSubmitType());
|
||||||
|
|
||||||
|
// Create the dev branch on the test project
|
||||||
|
BranchInput in = new BranchInput();
|
||||||
|
gApi.projects().name(name("project-a")).branch("dev").create(in);
|
||||||
|
RevCommit initialHead = getRemoteHead(project, "master");
|
||||||
|
|
||||||
|
// Create changes on master
|
||||||
|
PushOneCommit.Result change1 =
|
||||||
|
createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
|
||||||
|
PushOneCommit.Result change2 =
|
||||||
|
createChange(repoA, "master", "Change 2", "b.txt", "content", topic);
|
||||||
|
|
||||||
|
// Create changes on dev
|
||||||
|
repoA.reset(initialHead);
|
||||||
|
PushOneCommit.Result change3 =
|
||||||
|
createChange(repoA, "dev", "Change 3", "a.txt", "content", topic);
|
||||||
|
PushOneCommit.Result change4 =
|
||||||
|
createChange(repoA, "dev", "Change 4", "b.txt", "content", topic);
|
||||||
|
|
||||||
|
approve(change1.getChangeId());
|
||||||
|
approve(change2.getChangeId());
|
||||||
|
approve(change3.getChangeId());
|
||||||
|
approve(change4.getChangeId());
|
||||||
|
submit(change4.getChangeId());
|
||||||
|
|
||||||
|
String expectedTopic = name(topic);
|
||||||
|
change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
change3.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
change4.assertChange(Change.Status.MERGED, expectedTopic, admin);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submitWholeTopic() throws Exception {
|
public void submitWholeTopic() throws Exception {
|
||||||
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
assume().that(isSubmitWholeTopicEnabled()).isTrue();
|
||||||
|
String topic = "test-topic";
|
||||||
PushOneCommit.Result change1 =
|
PushOneCommit.Result change1 =
|
||||||
createChange("Change 1", "a.txt", "content", "test-topic");
|
createChange("Change 1", "a.txt", "content", topic);
|
||||||
PushOneCommit.Result change2 =
|
PushOneCommit.Result change2 =
|
||||||
createChange("Change 2", "b.txt", "content", "test-topic");
|
createChange("Change 2", "b.txt", "content", topic);
|
||||||
PushOneCommit.Result change3 =
|
PushOneCommit.Result change3 =
|
||||||
createChange("Change 3", "c.txt", "content", "test-topic");
|
createChange("Change 3", "c.txt", "content", topic);
|
||||||
approve(change1.getChangeId());
|
approve(change1.getChangeId());
|
||||||
approve(change2.getChangeId());
|
approve(change2.getChangeId());
|
||||||
approve(change3.getChangeId());
|
approve(change3.getChangeId());
|
||||||
submit(change3.getChangeId());
|
submit(change3.getChangeId());
|
||||||
change1.assertChange(Change.Status.MERGED, "test-topic", admin);
|
|
||||||
change2.assertChange(Change.Status.MERGED, "test-topic", admin);
|
change1.assertChange(Change.Status.MERGED, topic, admin);
|
||||||
change3.assertChange(Change.Status.MERGED, "test-topic", admin);
|
change2.assertChange(Change.Status.MERGED, topic, admin);
|
||||||
|
change3.assertChange(Change.Status.MERGED, topic, admin);
|
||||||
// Check for the exact change to have the correct submitter.
|
// Check for the exact change to have the correct submitter.
|
||||||
assertSubmitter(change3);
|
assertSubmitter(change3);
|
||||||
// Also check submitters for changes submitted via the topic relationship.
|
// Also check submitters for changes submitted via the topic relationship.
|
||||||
@@ -183,7 +262,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
|||||||
"Initial empty repository", "Change 1", "Change 2", "Change 3");
|
"Initial empty repository", "Change 1", "Change 2", "Change 3");
|
||||||
if (getSubmitType() == SubmitType.MERGE_ALWAYS) {
|
if (getSubmitType() == SubmitType.MERGE_ALWAYS) {
|
||||||
assertThat(commitsInRepo).contains(
|
assertThat(commitsInRepo).contains(
|
||||||
"Merge changes from topic 'test-topic'");
|
"Merge changes from topic '" + topic + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user