@ -58,6 +58,29 @@ func TestAPIReposGitCommitList(t *testing.T) {
session := loginUser ( t , user . Name )
token := getTokenForLoggedInUser ( t , session )
// Test getting commits (Page 1)
req := NewRequestf ( t , "GET" , "/api/v1/repos/%s/repo20/commits?token=" + token + "¬=master&sha=remove-files-a" , user . Name )
resp := MakeRequest ( t , req , http . StatusOK )
var apiData [ ] api . Commit
DecodeJSON ( t , resp , & apiData )
assert . Len ( t , apiData , 2 )
assert . EqualValues ( t , "cfe3b3c1fd36fba04f9183287b106497e1afe986" , apiData [ 0 ] . CommitMeta . SHA )
compareCommitFiles ( t , [ ] string { "link_hi" , "test.csv" } , apiData [ 0 ] . Files )
assert . EqualValues ( t , "c8e31bc7688741a5287fcde4fbb8fc129ca07027" , apiData [ 1 ] . CommitMeta . SHA )
compareCommitFiles ( t , [ ] string { "test.csv" } , apiData [ 1 ] . Files )
assert . EqualValues ( t , resp . Header ( ) . Get ( "X-Total" ) , "2" )
}
func TestAPIReposGitCommitListNotMaster ( t * testing . T ) {
defer tests . PrepareTestEnv ( t ) ( )
user := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } )
// Login as User2.
session := loginUser ( t , user . Name )
token := getTokenForLoggedInUser ( t , session )
// Test getting commits (Page 1)
req := NewRequestf ( t , "GET" , "/api/v1/repos/%s/repo16/commits?token=" + token , user . Name )
resp := MakeRequest ( t , req , http . StatusOK )
@ -72,6 +95,8 @@ func TestAPIReposGitCommitList(t *testing.T) {
compareCommitFiles ( t , [ ] string { "readme.md" } , apiData [ 1 ] . Files )
assert . EqualValues ( t , "5099b81332712fe655e34e8dd63574f503f61811" , apiData [ 2 ] . CommitMeta . SHA )
compareCommitFiles ( t , [ ] string { "readme.md" } , apiData [ 2 ] . Files )
assert . EqualValues ( t , resp . Header ( ) . Get ( "X-Total" ) , "3" )
}
func TestAPIReposGitCommitListPage2Empty ( t * testing . T ) {
@ -148,4 +173,26 @@ func TestGetFileHistory(t *testing.T) {
assert . Len ( t , apiData , 1 )
assert . Equal ( t , "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441" , apiData [ 0 ] . CommitMeta . SHA )
compareCommitFiles ( t , [ ] string { "readme.md" } , apiData [ 0 ] . Files )
assert . EqualValues ( t , resp . Header ( ) . Get ( "X-Total" ) , "1" )
}
func TestGetFileHistoryNotOnMaster ( t * testing . T ) {
defer tests . PrepareTestEnv ( t ) ( )
user := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } )
// Login as User2.
session := loginUser ( t , user . Name )
token := getTokenForLoggedInUser ( t , session )
req := NewRequestf ( t , "GET" , "/api/v1/repos/%s/repo20/commits?path=test.csv&token=" + token + "&sha=add-csv¬=master" , user . Name )
resp := MakeRequest ( t , req , http . StatusOK )
var apiData [ ] api . Commit
DecodeJSON ( t , resp , & apiData )
assert . Len ( t , apiData , 1 )
assert . Equal ( t , "c8e31bc7688741a5287fcde4fbb8fc129ca07027" , apiData [ 0 ] . CommitMeta . SHA )
compareCommitFiles ( t , [ ] string { "test.csv" } , apiData [ 0 ] . Files )
assert . EqualValues ( t , resp . Header ( ) . Get ( "X-Total" ) , "1" )
}