@@ -61,7 +61,7 @@ func setupTestRepo(t *testing.T, url string) string {
6161 runGit (t , repoPath , "commit" , "-m" , "commit 3" )
6262 runGit (t , repoPath , "tag" , "v1.1.0" )
6363
64- return repoPath
64+ return url
6565}
6666
6767// An extremely simple test repository with 1 commit and no tags.
@@ -84,13 +84,13 @@ func setupEmptyTestRepo(t *testing.T, url string) string {
8484 runGit (t , repoPath , "add" , "file1" )
8585 runGit (t , repoPath , "commit" , "-m" , "commit 1" )
8686
87- return repoPath
87+ return url
8888}
8989
9090func TestBuildCommitGraph (t * testing.T ) {
91- setupTestRepo (t , "git://test-repo.git" )
92- r := NewRepository ("git://test-repo.git" )
93- ctx := context .WithValue (t .Context (), urlKey , "git://test-repo.git" )
91+ url := setupTestRepo (t , "git://test-repo.git" )
92+ r := NewRepository (url )
93+ ctx := context .WithValue (t .Context (), urlKey , url )
9494
9595 newCommits , err := r .buildCommitGraph (ctx , nil )
9696
@@ -113,9 +113,9 @@ func TestBuildCommitGraph(t *testing.T) {
113113}
114114
115115func TestCalculatePatchIDs (t * testing.T ) {
116- setupTestRepo (t , "git://test-repo.git" )
117- r := NewRepository ("git://test-repo.git" )
118- ctx := context .WithValue (t .Context (), urlKey , "git://test-repo.git" )
116+ url := setupTestRepo (t , "git://test-repo.git" )
117+ r := NewRepository (url )
118+ ctx := context .WithValue (t .Context (), urlKey , url )
119119
120120 newCommits , err := r .buildCommitGraph (ctx , nil )
121121 if err != nil {
@@ -137,8 +137,9 @@ func TestCalculatePatchIDs(t *testing.T) {
137137}
138138
139139func TestLoadRepository (t * testing.T ) {
140- repoPath := setupTestRepo (t , "git://test-repo.git" )
141- ctx := context .WithValue (t .Context (), urlKey , "git://test-repo.git" )
140+ url := setupTestRepo (t , "git://test-repo.git" )
141+ repoPath := filepath .Join (gitStorePath , getRepoDirName (url ))
142+ ctx := context .WithValue (t .Context (), urlKey , url )
142143
143144 // First loadRepository with a brand new repo
144145 r1 , err := LoadRepository (ctx , repoPath )
@@ -220,7 +221,6 @@ var cmpSHA1Opts = []cmp.Option{
220221
221222func TestExpandByCherrypick (t * testing.T ) {
222223 repo := NewRepository ("git://test-repo.git" )
223- repo .repoPath = "/repo"
224224
225225 // Commit hashes
226226 h1 := decodeSHA1 ("aaaa" )
@@ -276,7 +276,6 @@ func TestExpandByCherrypick(t *testing.T) {
276276// Testing cases with introduced and fixed only.
277277func TestAffected_Introduced_Fixed (t * testing.T ) {
278278 repo := NewRepository ("git://test-repo.git" )
279- repo .repoPath = "/repo"
280279
281280 // Graph: (Parent -> Child)
282281 // -> F -> G
@@ -393,7 +392,6 @@ func TestAffected_Introduced_Fixed(t *testing.T) {
393392
394393func TestAffected_Introduced_LastAffected (t * testing.T ) {
395394 repo := NewRepository ("git://test-repo.git" )
396- repo .repoPath = "/repo"
397395
398396 // Graph: (Parent -> Child)
399397 // -> F -> G
@@ -511,7 +509,6 @@ func TestAffected_Introduced_LastAffected(t *testing.T) {
511509// Testing with both fixed and lastAffected
512510func TestAffected_Combined (t * testing.T ) {
513511 repo := NewRepository ("git://test-repo.git" )
514- repo .repoPath = "/repo"
515512
516513 // Graph: (Parent -> Child)
517514 // -> F -> G
@@ -616,7 +613,6 @@ func TestAffected_Combined(t *testing.T) {
616613
617614func TestAffected_Cherrypick (t * testing.T ) {
618615 repo := NewRepository ("git://test-repo.git" )
619- repo .repoPath = "/repo"
620616
621617 // Graph: (Parent -> Child)
622618 // A -> B -> C -> D
@@ -745,7 +741,6 @@ func TestAffected_Cherrypick(t *testing.T) {
745741
746742func TestLimit (t * testing.T ) {
747743 repo := NewRepository ("git://test-repo.git" )
748- repo .repoPath = "/repo"
749744
750745 // Graph: (Parent -> Child)
751746 // A -> B -> C -> D -> E
@@ -828,7 +823,6 @@ func TestLimit(t *testing.T) {
828823
829824func TestLimit_Cherrypick (t * testing.T ) {
830825 repo := NewRepository ("git://test-repo.git" )
831- repo .repoPath = "/repo"
832826
833827 // Graph: (Parent -> Child)
834828 // A -> B -> C -> D
@@ -1072,7 +1066,7 @@ func TestRunAndParseTags(t *testing.T) {
10721066 }{
10731067 {
10741068 name : "Parse mock data" ,
1075- cmd : exec .Command ("echo" , "000000000000000000000000000000000000aaaa refs/tags/v1.0.0\n 000000000000000000000000000000000000bbbb refs/tags/v1.1.0\n " ),
1069+ cmd : exec .Command ("echo" , "000000000000000000000000000000000000aaaa refs/tags/v1.0.0\n 000000000000000000000000000000000000bbbb refs/tags/v1.1.0\n " ),
10761070 want : map [string ]SHA1 {
10771071 "v1.0.0" : decodeSHA1 ("aaaa" ),
10781072 "v1.1.0" : decodeSHA1 ("bbbb" ),
@@ -1137,9 +1131,9 @@ func TestGetLocalTags(t *testing.T) {
11371131
11381132 for _ , tt := range tests {
11391133 t .Run (tt .name , func (t * testing.T ) {
1140- tt .setupFunc (t , "git://test-repo.git" )
1141- r := NewRepository ("git://test-repo.git" )
1142- ctx := context .WithValue (t .Context (), urlKey , "git://test-repo.git" )
1134+ url := tt .setupFunc (t , "git://test-repo.git" )
1135+ r := NewRepository (url )
1136+ ctx := context .WithValue (t .Context (), urlKey , url )
11431137
11441138 tags , err := r .GetLocalTags (ctx )
11451139 if err != nil {
@@ -1158,3 +1152,51 @@ func TestGetLocalTags(t *testing.T) {
11581152 })
11591153 }
11601154}
1155+
1156+ func TestGetRemoteTags (t * testing.T ) {
1157+ tests := []struct {
1158+ name string
1159+ setupFunc func (t * testing.T , url string ) string
1160+ wantTags []string
1161+ wantCount int
1162+ }{
1163+ {
1164+ name : "Repo with tags" ,
1165+ setupFunc : setupTestRepo ,
1166+ wantTags : []string {"v1.0.0" , "v1.1.0" },
1167+ wantCount : 2 ,
1168+ },
1169+ {
1170+ name : "Empty repo (no tags)" ,
1171+ setupFunc : setupEmptyTestRepo ,
1172+ wantTags : []string {},
1173+ wantCount : 0 ,
1174+ },
1175+ }
1176+
1177+ for _ , tt := range tests {
1178+ t .Run (tt .name , func (t * testing.T ) {
1179+ url := tt .setupFunc (t , "git://test-repo.git" )
1180+ repoPath := filepath .Join (gitStorePath , getRepoDirName (url ))
1181+ r := NewRepository (url )
1182+ // Overwriting URL with repoPath to simulate remote repo without needing to query an actual repo url
1183+ r .URL = r .repoPath
1184+ ctx := context .WithValue (t .Context (), urlKey , repoPath )
1185+
1186+ tags , err := r .GetRemoteTags (ctx )
1187+ if err != nil {
1188+ t .Fatalf ("GetRemoteTags failed: %v" , err )
1189+ }
1190+
1191+ if len (tags ) != tt .wantCount {
1192+ t .Errorf ("expected %d tags, got %d" , tt .wantCount , len (tags ))
1193+ }
1194+
1195+ for _ , wantTag := range tt .wantTags {
1196+ if _ , ok := tags [wantTag ]; ! ok {
1197+ t .Errorf ("expected tag %s to exist" , wantTag )
1198+ }
1199+ }
1200+ })
1201+ }
1202+ }
0 commit comments