Fix tests in the plugin to avoid implicit merges.
Some tests resets repo to an incorrect commit and instead of creating
sibling change(s) they created child changes in a differnt branch.
Tests were verified with the following command:
bazel test //plugins/automerger/...
Change-Id: Iefe9222a65c64f2c8dd066ae6ff516f014cd1767
diff --git a/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java b/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
index cb36aaa..52cf29e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
@@ -144,6 +144,7 @@
@Test
public void testDiamondMerge() throws Exception {
Project.NameKey manifestNameKey = defaultSetup();
+ ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
// Create initial change
PushOneCommit.Result initialResult = createChange("subject", "filename", "echo Hello");
// Project name is scoped by test, so we need to get it from our initial change
@@ -152,13 +153,18 @@
createBranch(BranchNameKey.create(projectName, "right"));
initialResult.assertOkStatus();
merge(initialResult);
+ ObjectId masterWithMergedChange = repo().exactRef("HEAD").getLeaf().getObjectId();
// Reset to create a sibling
- ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
testRepo.reset(initial);
// Make left != right
PushOneCommit.Result left =
createChange(
- testRepo, "left", "subject", "filename", "echo \"Hello asdfsd World\"", "randtopic");
+ testRepo,
+ "left",
+ "subject",
+ "filename-left",
+ "echo \"Hello asdfsd World\"",
+ "randtopic");
left.assertOkStatus();
merge(left);
@@ -169,6 +175,7 @@
createBranch(BranchNameKey.create(projectName, "bottom"));
pushDiamondConfig(manifestNameKey.get(), projectName);
// After we upload our config, we upload a new patchset to create the downstreams
+ testRepo.reset(masterWithMergedChange);
PushOneCommit.Result result =
createChange(testRepo, "master", "subject", "filename2", "echo Hello", "sometopic");
result.assertOkStatus();
@@ -471,6 +478,7 @@
@Test
public void testDownstreamMergeConflict() throws Exception {
Project.NameKey manifestNameKey = defaultSetup();
+ ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
// Create initial change
PushOneCommit.Result result = createChange("subject", "filename", "echo Hello");
// Project name is scoped by test, so we need to get it from our initial change
@@ -480,7 +488,6 @@
result.assertOkStatus();
merge(result);
// Reset to create a sibling
- ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
testRepo.reset(initial);
// Set up a merge conflict between master and ds_one
PushOneCommit.Result ds1Result =
@@ -534,6 +541,7 @@
@Test
public void testRestrictedVotePermissions() throws Exception {
Project.NameKey manifestNameKey = defaultSetup();
+ ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
// Create initial change
PushOneCommit.Result result = createChange("subject", "filename", "echo Hello");
// Project name is scoped by test, so we need to get it from our initial change
@@ -543,7 +551,6 @@
result.assertOkStatus();
merge(result);
// Reset to create a sibling
- ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
testRepo.reset(initial);
// Set up a merge conflict between master and ds_one
PushOneCommit.Result ds1Result =
@@ -855,6 +862,7 @@
public void testContextUser_mergeConflictOnDownstreamVotesOnTopLevel() throws Exception {
// Branch flow for contextUser is master -> ds_one -> ds_two
Project.NameKey manifestNameKey = defaultSetup();
+ ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
// Create initial change
PushOneCommit.Result initialResult = createChange("subject", "filename", "echo Hello");
// Project name is scoped by test, so we need to get it from our initial change
@@ -866,7 +874,7 @@
merge(initialResult);
// Reset to create a sibling
- ObjectId initial = repo().exactRef("HEAD").getLeaf().getObjectId();
+ testRepo.reset(initial);
PushOneCommit.Result ds1Result =
createChange(
testRepo, "ds_one", "subject", "filename", "echo \"Hello asdfsd World\"", "randtopic");