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