Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Tan2018-05-02 23:35:48 +0000
committerJonathan Nieder2018-06-05 05:09:07 +0000
commitc9d4609ecbe3e8ed74f8fc169d541a1d7c8c5f15 (patch)
tree81ede8b253e6acd83585b0651113432fd94cf114
parente319a6f8d4e014214fe5433b1ffc7e5d528f3541 (diff)
downloadjgit-c9d4609ecbe3e8ed74f8fc169d541a1d7c8c5f15.tar.gz
jgit-c9d4609ecbe3e8ed74f8fc169d541a1d7c8c5f15.tar.xz
jgit-c9d4609ecbe3e8ed74f8fc169d541a1d7c8c5f15.zip
Refactor test of capabilities output
A subsequent patch will dynamically generate the capability advertisement, so the capability advertisements produced are not always the same. Separate the checking of the advertisements into its own test method. Change-Id: I768d14b9d1a244d5d886c42ffd62ef3957b518fb Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java44
1 files changed, 33 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 6550f1a52c..d1a31720b6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -336,12 +336,12 @@ public class UploadPackTest {
}
/*
- * Invokes UploadPack with protocol v2 and sends it the given lines.
- * Returns UploadPack's output stream, not including the capability
- * advertisement by the server.
+ * Invokes UploadPack with protocol v2 and sends it the given lines,
+ * and returns UploadPack's output stream.
*/
- private ByteArrayInputStream uploadPackV2(RequestPolicy requestPolicy,
+ private ByteArrayInputStream uploadPackV2Setup(RequestPolicy requestPolicy,
RefFilter refFilter, String... inputLines) throws Exception {
+
ByteArrayOutputStream send = new ByteArrayOutputStream();
PacketLineOut pckOut = new PacketLineOut(send);
for (String line : inputLines) {
@@ -365,10 +365,37 @@ public class UploadPackTest {
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(new ByteArrayInputStream(send.toByteArray()), recv, null);
- ByteArrayInputStream recvStream = new ByteArrayInputStream(recv.toByteArray());
+ return new ByteArrayInputStream(recv.toByteArray());
+ }
+
+ /*
+ * Invokes UploadPack with protocol v2 and sends it the given lines.
+ * Returns UploadPack's output stream, not including the capability
+ * advertisement by the server.
+ */
+ private ByteArrayInputStream uploadPackV2(RequestPolicy requestPolicy,
+ RefFilter refFilter, String... inputLines) throws Exception {
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(requestPolicy, refFilter, inputLines);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // drain capabilities
+ while (pckIn.readString() != PacketLineIn.END) {
+ // do nothing
+ }
+ return recvStream;
+ }
+
+ private ByteArrayInputStream uploadPackV2(String... inputLines) throws Exception {
+ return uploadPackV2(null, null, inputLines);
+ }
+
+ @Test
+ public void testV2Capabilities() throws Exception {
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, PacketLineIn.END);
PacketLineIn pckIn = new PacketLineIn(recvStream);
- // capability advertisement (always sent)
assertThat(pckIn.readString(), is("version 2"));
assertThat(
Arrays.asList(pckIn.readString(), pckIn.readString()),
@@ -380,11 +407,6 @@ public class UploadPackTest {
// commands without requiring test changes.
hasItems("ls-refs", "fetch=shallow"));
assertTrue(pckIn.readString() == PacketLineIn.END);
- return recvStream;
- }
-
- private ByteArrayInputStream uploadPackV2(String... inputLines) throws Exception {
- return uploadPackV2(null, null, inputLines);
}
@Test

Back to the top