diff options
author | Edwin Kempin <ekempin@google.com> | 2019-12-05 09:57:10 +0100 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2019-12-06 09:30:30 +0900 |
commit | ece80db8e9d9e0c0b5d4bf2fa135a7b948c16815 (patch) | |
tree | f244d82d0bedf638f50f91fd05d7598cf370edb8 | |
parent | 9a5061212fbaf2158e728d43a82e63889ea211e6 (diff) |
CreateBranchIT: Add tests that set revision in the input
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I75c4424c9f516d46ce7ce34fdea568c05567cc84
-rw-r--r-- | javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java b/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java index df896864e5..a4a87d5464 100644 --- a/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java +++ b/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java @@ -28,12 +28,14 @@ import com.google.gerrit.extensions.api.projects.BranchApi; import com.google.gerrit.extensions.api.projects.BranchInfo; import com.google.gerrit.extensions.api.projects.BranchInput; import com.google.gerrit.extensions.restapi.AuthException; +import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.RefNames; +import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; import org.junit.Test; @@ -127,6 +129,74 @@ public class CreateBranchIT extends AbstractDaemonTest { "Not allowed to create group branch."); } + @Test + public void createWithRevision() throws Exception { + RevCommit revision = getRemoteHead(project, "master"); + + // update master so that points to a different revision than the revision on which we create the + // new branch + pushTo("refs/heads/master"); + assertThat(getRemoteHead(project, "master")).isNotEqualTo(revision); + + BranchInput input = new BranchInput(); + input.revision = revision.name(); + BranchInfo created = branch(testBranch).create(input).get(); + assertThat(created.ref).isEqualTo(testBranch.get()); + assertThat(created.revision).isEqualTo(revision.name()); + assertThat(getRemoteHead(project, testBranch.getShortName())).isEqualTo(revision); + } + + @Test + public void createWithBranchNameAsRevision() throws Exception { + RevCommit expectedRevision = getRemoteHead(project, "master"); + + BranchInput input = new BranchInput(); + input.revision = "master"; + BranchInfo created = branch(testBranch).create(input).get(); + assertThat(created.ref).isEqualTo(testBranch.get()); + assertThat(created.revision).isEqualTo(expectedRevision.name()); + assertThat(getRemoteHead(project, testBranch.getShortName())).isEqualTo(expectedRevision); + } + + @Test + public void createWithFullBranchNameAsRevision() throws Exception { + RevCommit expectedRevision = getRemoteHead(project, "master"); + + BranchInput input = new BranchInput(); + input.revision = "refs/heads/master"; + BranchInfo created = branch(testBranch).create(input).get(); + assertThat(created.ref).isEqualTo(testBranch.get()); + assertThat(created.revision).isEqualTo(expectedRevision.name()); + assertThat(getRemoteHead(project, testBranch.getShortName())).isEqualTo(expectedRevision); + } + + @Test + public void cannotCreateWithNonExistingBranchNameAsRevision() throws Exception { + assertCreateFails( + testBranch, + "refs/heads/non-existing", + BadRequestException.class, + "invalid revision \"refs/heads/non-existing\""); + } + + @Test + public void cannotCreateWithNonExistingRevision() throws Exception { + assertCreateFails( + testBranch, + "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", + BadRequestException.class, + "invalid revision \"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef\""); + } + + @Test + public void cannotCreateWithInvalidRevision() throws Exception { + assertCreateFails( + testBranch, + "invalid\trevision", + BadRequestException.class, + "invalid revision \"invalid\trevision\""); + } + private void blockCreateReference() throws Exception { block("refs/*", Permission.CREATE, ANONYMOUS_USERS); } |