@@ -22,6 +22,7 @@ import (
2222 "github.com/blang/semver/v4"
2323 fixtures "github.com/go-git/go-git-fixtures/v4"
2424 "github.com/google/go-cmp/cmp"
25+ "github.com/stretchr/testify/assert"
2526)
2627
2728func TestGetRepo_BasicOne (t * testing.T ) {
@@ -54,15 +55,17 @@ func TestGetRepo_Error(t *testing.T) {
5455}
5556
5657func TestRepo_BestRefFor (t * testing.T ) {
57- repo := & Repo {
58+ repo := Repo {
5859 Ref : "ref" ,
5960 DefaultBranch : "main" ,
6061 Tags : []string {"v0.1.0" , "bar" , "v0.2.0" , "baz" , "v0.2.1" , "v0.2.2-rc.1" , "v0.2.2+build" , "foo" },
6162 Branches : []string {"release-0.1" , "bar" , "release-0.2" , "baz" , "main" , "release-0.3" , "release-1.0" },
6263 }
64+ submoduleRepo := repo
65+ submoduleRepo .Submodule = "sub"
6366
6467 tests := map [string ]struct {
65- repo * Repo
68+ repo Repo
6669 version semver.Version
6770 moduleVersion semver.Version
6871 want string
@@ -83,6 +86,13 @@ func TestRepo_BestRefFor(t *testing.T) {
8386 release : ReleaseRef ,
8487 rule : AnyRule ,
8588 },
89+ "Any - v0.2 - with submodule" : {
90+ repo : submoduleRepo ,
91+ version : semver .MustParse ("0.2.0" ),
92+ want : "ref@release-0.2" ,
93+ release : ReleaseBranchRef ,
94+ rule : AnyRule ,
95+ },
8696 "Any - v0.3" : {
8797 repo : repo ,
8898 version : semver .MustParse ("0.3.0" ),
@@ -120,6 +130,13 @@ func TestRepo_BestRefFor(t *testing.T) {
120130 release : ReleaseRef ,
121131 rule : ReleaseOrReleaseBranchRule ,
122132 },
133+ "ReleaseOrReleaseBranch - v0.2 - Submodule" : {
134+ repo : submoduleRepo ,
135+ version : semver .MustParse ("0.2.0" ),
136+ want : "ref@release-0.2" ,
137+ release : ReleaseBranchRef ,
138+ rule : ReleaseOrReleaseBranchRule ,
139+ },
123140 "ReleaseOrReleaseBranch - v0.3" : {
124141 repo : repo ,
125142 version : semver .MustParse ("0.3.0" ),
@@ -165,6 +182,13 @@ func TestRepo_BestRefFor(t *testing.T) {
165182 release : ReleaseRef ,
166183 rule : ReleaseRule ,
167184 },
185+ "Release - v0.2 - Submodule" : {
186+ repo : submoduleRepo ,
187+ version : semver .MustParse ("0.2.0" ),
188+ want : "ref" ,
189+ release : NoRef ,
190+ rule : ReleaseRule ,
191+ },
168192 "Release - v0.3" : {
169193 repo : repo ,
170194 version : semver .MustParse ("0.3.0" ),
@@ -231,12 +255,8 @@ func TestRepo_BestRefFor(t *testing.T) {
231255 tt .moduleVersion = tt .version
232256 }
233257 got , release := tt .repo .BestRefFor (tt .version , tt .moduleVersion , tt .rule )
234- if got != tt .want {
235- t .Errorf ("repo.BestRefFor() got ref = %v, want %v" , got , tt .want )
236- }
237- if release != tt .release {
238- t .Errorf ("repo.BestRefFor() got isRelease = %v, want %v" , got , tt .want )
239- }
258+ assert .Equal (t , tt .want , got )
259+ assert .Equal (t , tt .release , release )
240260 })
241261 }
242262}
0 commit comments