@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.theInstance ;
import static org.hamcrest.Matchers.theInstance ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertNotNull ;
import static org.junit.Assert.assertThat ;
import static org.junit.Assert.assertThat ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.fail ;
import static org.junit.Assert.fail ;
@ -485,6 +486,8 @@ public class UploadPackTest {
private LsRefsV2Request lsRefsRequest ;
private LsRefsV2Request lsRefsRequest ;
private FetchV2Request fetchRequest ;
@Override
@Override
public void onCapabilities ( CapabilitiesV2Request req ) {
public void onCapabilities ( CapabilitiesV2Request req ) {
capabilitiesRequest = req ;
capabilitiesRequest = req ;
@ -494,6 +497,11 @@ public class UploadPackTest {
public void onLsRefs ( LsRefsV2Request req ) {
public void onLsRefs ( LsRefsV2Request req ) {
lsRefsRequest = req ;
lsRefsRequest = req ;
}
}
@Override
public void onFetch ( FetchV2Request req ) {
fetchRequest = req ;
}
}
}
@Test
@Test
@ -502,18 +510,18 @@ public class UploadPackTest {
ByteArrayInputStream recvStream =
ByteArrayInputStream recvStream =
uploadPackV2Setup ( null , null , hook , PacketLineIn . END ) ;
uploadPackV2Setup ( null , null , hook , PacketLineIn . END ) ;
PacketLineIn pckIn = new PacketLineIn ( recvStream ) ;
PacketLineIn pckIn = new PacketLineIn ( recvStream ) ;
assertThat ( hook . capabilitiesRequest , notNullValue ( ) ) ;
assertThat ( hook . capabilitiesRequest , notNullValue ( ) ) ;
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat (
assertThat (
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ) ,
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ,
// TODO(jonathantanmy) This check is written this way
pckIn . readString ( ) ) ,
// to make it simple to see that we expect this list of
// TODO(jonathantanmy) This check is written this way
// capabilities, but probably should be loosened to
// to make it simple to see that we expect this list of
// allow additional commands to be added to the list,
// capabilities, but probably should be loosened to
// and additional capabilities to be added to existing
// allow additional commands to be added to the list,
// commands without requiring test changes.
// and additional capabilities to be added to existing
hasItems ( "ls-refs" , "fetch=shallow" ) ) ;
// commands without requiring test changes.
hasItems ( "ls-refs" , "fetch=shallow" , "server-option" ) ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
}
}
@ -526,10 +534,11 @@ public class UploadPackTest {
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat (
assertThat (
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ) ,
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ,
// TODO(jonathantanmy) This check overspecifies the
pckIn . readString ( ) ) ,
// order of the capabilities of "fetch".
// TODO(jonathantanmy) This check overspecifies the
hasItems ( "ls-refs" , "fetch=filter shallow" ) ) ;
// order of the capabilities of "fetch".
hasItems ( "ls-refs" , "fetch=filter shallow" , "server-option" ) ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
}
}
@ -542,10 +551,12 @@ public class UploadPackTest {
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat (
assertThat (
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ) ,
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ,
// TODO(jonathantanmy) This check overspecifies the
pckIn . readString ( ) ) ,
// order of the capabilities of "fetch".
// TODO(jonathantanmy) This check overspecifies the
hasItems ( "ls-refs" , "fetch=ref-in-want shallow" ) ) ;
// order of the capabilities of "fetch".
hasItems ( "ls-refs" , "fetch=ref-in-want shallow" ,
"server-option" ) ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
}
}
@ -558,8 +569,9 @@ public class UploadPackTest {
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat (
assertThat (
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ) ,
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ,
hasItems ( "ls-refs" , "fetch=shallow" ) ) ;
pckIn . readString ( ) ) ,
hasItems ( "ls-refs" , "fetch=shallow" , "server-option" ) ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
}
}
@ -573,8 +585,9 @@ public class UploadPackTest {
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat ( pckIn . readString ( ) , is ( "version 2" ) ) ;
assertThat (
assertThat (
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ) ,
Arrays . asList ( pckIn . readString ( ) , pckIn . readString ( ) ,
hasItems ( "ls-refs" , "fetch=shallow" ) ) ;
pckIn . readString ( ) ) ,
hasItems ( "ls-refs" , "fetch=shallow" , "server-option" ) ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
assertTrue ( pckIn . readString ( ) = = PacketLineIn . END ) ;
}
}
@ -719,6 +732,21 @@ public class UploadPackTest {
PacketLineIn . END ) ;
PacketLineIn . END ) ;
}
}
@Test
public void testV2LsRefsServerOptions ( ) throws Exception {
String [ ] lines = { "command=ls-refs\n" ,
"server-option=one\n" , "server-option=two\n" ,
PacketLineIn . DELIM ,
PacketLineIn . END } ;
TestV2Hook testHook = new TestV2Hook ( ) ;
uploadPackV2Setup ( null , null , testHook , lines ) ;
LsRefsV2Request req = testHook . lsRefsRequest ;
assertEquals ( 2 , req . getServerOptions ( ) . size ( ) ) ;
assertThat ( req . getServerOptions ( ) , hasItems ( "one" , "two" ) ) ;
}
/ *
/ *
* Parse multiplexed packfile output from upload - pack using protocol V2
* Parse multiplexed packfile output from upload - pack using protocol V2
* into the client repository .
* into the client repository .
@ -1255,6 +1283,21 @@ public class UploadPackTest {
PacketLineIn . END ) ;
PacketLineIn . END ) ;
}
}
@Test
public void testV2FetchServerOptions ( ) throws Exception {
String [ ] lines = { "command=fetch\n" , "server-option=one\n" ,
"server-option=two\n" , PacketLineIn . DELIM ,
PacketLineIn . END } ;
TestV2Hook testHook = new TestV2Hook ( ) ;
uploadPackV2Setup ( null , null , testHook , lines ) ;
FetchV2Request req = testHook . fetchRequest ;
assertNotNull ( req ) ;
assertEquals ( 2 , req . getServerOptions ( ) . size ( ) ) ;
assertThat ( req . getServerOptions ( ) , hasItems ( "one" , "two" ) ) ;
}
@Test
@Test
public void testV2FetchFilter ( ) throws Exception {
public void testV2FetchFilter ( ) throws Exception {
RevBlob big = remote . blob ( "foobar" ) ;
RevBlob big = remote . blob ( "foobar" ) ;