From cb4de02e5e7502705ef52264eb76d03a90c950d1 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Tue, 28 Aug 2018 13:57:52 -0700 Subject: Move ls-refs parsing code to the ProtocolV2Parser Fetch code has been moved to a ProtocolV2Parser, but ls-refs code is still in UploadPack. Moving it to the parser makes it easier to test, keeps the parsing together and makes the two commands follow similar structure. Change-Id: I573ce543e804ddeb9f83303b4af250b7cddc8cad Signed-off-by: Ivan Frade --- .../jgit/transport/ProtocolV2ParserTest.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'org.eclipse.jgit.test') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java index 4d1150844c..c2e8b5b621 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.transport; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItems; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -333,4 +334,60 @@ public class ProtocolV2ParserTest { testRepo.getRepository().getRefDatabase()); } + @Test + public void testLsRefsMinimalReq() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + PacketLineIn.END); + + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + LsRefsV2Request req = parser.parseLsRefsRequest(pckIn); + assertFalse(req.getPeel()); + assertFalse(req.getSymrefs()); + assertEquals(0, req.getRefPrefixes().size()); + } + + @Test + public void testLsRefsSymrefs() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, "symrefs", + PacketLineIn.END); + + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + LsRefsV2Request req = parser.parseLsRefsRequest(pckIn); + assertFalse(req.getPeel()); + assertTrue(req.getSymrefs()); + assertEquals(0, req.getRefPrefixes().size()); + + } + + @Test + public void testLsRefsPeel() throws IOException { + PacketLineIn pckIn = formatAsPacketLine( + PacketLineIn.DELIM, + "peel", + PacketLineIn.END); + + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + LsRefsV2Request req = parser.parseLsRefsRequest(pckIn); + assertTrue(req.getPeel()); + assertFalse(req.getSymrefs()); + assertEquals(0, req.getRefPrefixes().size()); + } + + @Test + public void testLsRefsRefPrefixes() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "ref-prefix refs/for", "ref-prefix refs/heads", + PacketLineIn.END); + + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + LsRefsV2Request req = parser.parseLsRefsRequest(pckIn); + assertFalse(req.getPeel()); + assertFalse(req.getSymrefs()); + assertEquals(2, req.getRefPrefixes().size()); + assertThat(req.getRefPrefixes(), hasItems("refs/for", "refs/heads")); + } } -- cgit v1.2.3