@ -16,11 +16,17 @@ import (
func TestRepository_GetTags ( t * testing . T ) {
func TestRepository_GetTags ( t * testing . T ) {
bareRepo1Path := filepath . Join ( testReposDir , "repo1_bare" )
bareRepo1Path := filepath . Join ( testReposDir , "repo1_bare" )
bareRepo1 , err := OpenRepository ( bareRepo1Path )
bareRepo1 , err := OpenRepository ( bareRepo1Path )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
defer bareRepo1 . Close ( )
defer bareRepo1 . Close ( )
tags , total , err := bareRepo1 . GetTagInfos ( 0 , 0 )
tags , total , err := bareRepo1 . GetTagInfos ( 0 , 0 )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
assert . Len ( t , tags , 1 )
assert . Len ( t , tags , 1 )
assert . Equal ( t , len ( tags ) , total )
assert . Equal ( t , len ( tags ) , total )
assert . EqualValues ( t , "test" , tags [ 0 ] . Name )
assert . EqualValues ( t , "test" , tags [ 0 ] . Name )
@ -31,40 +37,75 @@ func TestRepository_GetTags(t *testing.T) {
func TestRepository_GetTag ( t * testing . T ) {
func TestRepository_GetTag ( t * testing . T ) {
bareRepo1Path := filepath . Join ( testReposDir , "repo1_bare" )
bareRepo1Path := filepath . Join ( testReposDir , "repo1_bare" )
clonedPath , err := cloneRepo ( bareRepo1Path , testReposDir , "repo1_TestRepository_GetTag" )
clonedPath , err := cloneRepo ( bareRepo1Path , "TestRepository_GetTag" )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
defer util . RemoveAll ( clonedPath )
defer util . RemoveAll ( clonedPath )
bareRepo1 , err := OpenRepository ( clonedPath )
bareRepo1 , err := OpenRepository ( clonedPath )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
defer bareRepo1 . Close ( )
defer bareRepo1 . Close ( )
// LIGHTWEIGHT TAGS
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
lTagName := "lightweightTag"
lTagName := "lightweightTag"
bareRepo1 . CreateTag ( lTagName , lTagCommitID )
aTagCommitID := "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"
// Create the lightweight tag
aTagName := "annotatedTag"
err = bareRepo1 . CreateTag ( lTagName , lTagCommitID )
aTagMessage := "my annotated message \n - test two line"
if err != nil {
bareRepo1 . CreateAnnotatedTag ( aTagName , aTagMessage , aTagCommitID )
assert . NoError ( t , err , "Unable to create the lightweight tag: %s for ID: %s. Error: %v" , lTagName , lTagCommitID , err )
aTagID , _ := bareRepo1 . GetTagID ( aTagName )
return
}
// and try to get the Tag for lightweight tag
lTag , err := bareRepo1 . GetTag ( lTagName )
lTag , err := bareRepo1 . GetTag ( lTagName )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . NotNil ( t , lTag )
return
}
if lTag == nil {
if lTag == nil {
assert . NotNil ( t , lTag )
assert . FailNow ( t , "nil lTag: %s" , lTagName )
assert . FailNow ( t , "nil lTag: %s" , lTagName )
return
}
}
assert . EqualValues ( t , lTagName , lTag . Name )
assert . EqualValues ( t , lTagName , lTag . Name )
assert . EqualValues ( t , lTagCommitID , lTag . ID . String ( ) )
assert . EqualValues ( t , lTagCommitID , lTag . ID . String ( ) )
assert . EqualValues ( t , lTagCommitID , lTag . Object . String ( ) )
assert . EqualValues ( t , lTagCommitID , lTag . Object . String ( ) )
assert . EqualValues ( t , "commit" , lTag . Type )
assert . EqualValues ( t , "commit" , lTag . Type )
// ANNOTATED TAGS
aTagCommitID := "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"
aTagName := "annotatedTag"
aTagMessage := "my annotated message \n - test two line"
// Create the annotated tag
err = bareRepo1 . CreateAnnotatedTag ( aTagName , aTagMessage , aTagCommitID )
if err != nil {
assert . NoError ( t , err , "Unable to create the annotated tag: %s for ID: %s. Error: %v" , aTagName , aTagCommitID , err )
return
}
// Now try to get the tag for the annotated Tag
aTagID , err := bareRepo1 . GetTagID ( aTagName )
if err != nil {
assert . NoError ( t , err )
return
}
aTag , err := bareRepo1 . GetTag ( aTagName )
aTag , err := bareRepo1 . GetTag ( aTagName )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . NotNil ( t , aTag )
return
}
if aTag == nil {
if aTag == nil {
assert . NotNil ( t , aTag )
assert . FailNow ( t , "nil aTag: %s" , aTagName )
assert . FailNow ( t , "nil aTag: %s" , aTagName )
return
}
}
assert . EqualValues ( t , aTagName , aTag . Name )
assert . EqualValues ( t , aTagName , aTag . Name )
assert . EqualValues ( t , aTagID , aTag . ID . String ( ) )
assert . EqualValues ( t , aTagID , aTag . ID . String ( ) )
@ -72,26 +113,47 @@ func TestRepository_GetTag(t *testing.T) {
assert . EqualValues ( t , aTagCommitID , aTag . Object . String ( ) )
assert . EqualValues ( t , aTagCommitID , aTag . Object . String ( ) )
assert . EqualValues ( t , "tag" , aTag . Type )
assert . EqualValues ( t , "tag" , aTag . Type )
// RELEASE TAGS
rTagCommitID := "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"
rTagCommitID := "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"
rTagName := "release/" + lTagName
rTagName := "release/" + lTagName
bareRepo1 . CreateTag ( rTagName , rTagCommitID )
err = bareRepo1 . CreateTag ( rTagName , rTagCommitID )
if err != nil {
assert . NoError ( t , err , "Unable to create the tag: %s for ID: %s. Error: %v" , rTagName , rTagCommitID , err )
return
}
rTagID , err := bareRepo1 . GetTagID ( rTagName )
rTagID , err := bareRepo1 . GetTagID ( rTagName )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
assert . EqualValues ( t , rTagCommitID , rTagID )
assert . EqualValues ( t , rTagCommitID , rTagID )
oTagID , err := bareRepo1 . GetTagID ( lTagName )
oTagID , err := bareRepo1 . GetTagID ( lTagName )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
assert . EqualValues ( t , lTagCommitID , oTagID )
assert . EqualValues ( t , lTagCommitID , oTagID )
}
}
func TestRepository_GetAnnotatedTag ( t * testing . T ) {
func TestRepository_GetAnnotatedTag ( t * testing . T ) {
bareRepo1Path := filepath . Join ( testReposDir , "repo1_bare" )
bareRepo1Path := filepath . Join ( testReposDir , "repo1_bare" )
clonedPath , err := cloneRepo ( bareRepo1Path , testReposDir , "repo1_TestRepository_GetTag" )
clonedPath , err := cloneRepo ( bareRepo1Path , "TestRepository_GetAnnotatedTag" )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
defer util . RemoveAll ( clonedPath )
defer util . RemoveAll ( clonedPath )
bareRepo1 , err := OpenRepository ( clonedPath )
bareRepo1 , err := OpenRepository ( clonedPath )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
defer bareRepo1 . Close ( )
defer bareRepo1 . Close ( )
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
lTagCommitID := "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1"
@ -106,7 +168,10 @@ func TestRepository_GetAnnotatedTag(t *testing.T) {
// Try an annotated tag
// Try an annotated tag
tag , err := bareRepo1 . GetAnnotatedTag ( aTagID )
tag , err := bareRepo1 . GetAnnotatedTag ( aTagID )
if err != nil {
assert . NoError ( t , err )
assert . NoError ( t , err )
return
}
assert . NotNil ( t , tag )
assert . NotNil ( t , tag )
assert . EqualValues ( t , aTagName , tag . Name )
assert . EqualValues ( t , aTagName , tag . Name )
assert . EqualValues ( t , aTagID , tag . ID . String ( ) )
assert . EqualValues ( t , aTagID , tag . ID . String ( ) )