@@ -83,6 +83,65 @@ func Test_LatestVersion(t *testing.T) {
8383 newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
8484 assert .NoError (t , err )
8585 assert .NotNil (t , newTag )
86+ assert .Equal (t , "2025.01.25" , newTag .TagName )
87+ })
88+
89+ t .Run ("Find latest version with YYYY.MM calver format" , func (t * testing.T ) {
90+ tagList := newImageTagList ([]string {"2021.01" , "2022.02" , "2023.05" , "2025.01" })
91+ img := NewFromIdentifier ("jannfis/test:2021.01" )
92+ vc := VersionConstraint {Constraint : "2022.01" , Strategy : StrategyCalVer , MatchArgs : "YYYY.MM" }
93+ newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
94+ assert .NoError (t , err )
95+ assert .NotNil (t , newTag )
96+ assert .Equal (t , "2025.01" , newTag .TagName )
97+ })
98+
99+ t .Run ("Find latest version with YY.MM.DD calver format" , func (t * testing.T ) {
100+ tagList := newImageTagList ([]string {"21.01.01" , "22.02.02" , "23.05.01" , "25.01.25" })
101+ img := NewFromIdentifier ("jannfis/test:21.01.01" )
102+ vc := VersionConstraint {Constraint : "22.01.01" , Strategy : StrategyCalVer , MatchArgs : "YY.MM.DD" }
103+ newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
104+ assert .NoError (t , err )
105+ assert .NotNil (t , newTag )
106+ assert .Equal (t , "25.01.25" , newTag .TagName )
107+ })
108+
109+ t .Run ("Invalid calver format should return error" , func (t * testing.T ) {
110+ tagList := newImageTagList ([]string {"2021.01.01" , "2022.02.02" })
111+ img := NewFromIdentifier ("jannfis/test:2021.01.01" )
112+ vc := VersionConstraint {Constraint : "2022.01.01" , Strategy : StrategyCalVer , MatchArgs : "invalid-format" }
113+ newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
114+ assert .Error (t , err )
115+ assert .Nil (t , newTag )
116+ })
117+
118+ t .Run ("Tags not matching calver format should be ignored" , func (t * testing.T ) {
119+ tagList := newImageTagList ([]string {"2021.01.01" , "invalid" , "2023.05.01" , "not-a-date" })
120+ img := NewFromIdentifier ("jannfis/test:2021.01.01" )
121+ vc := VersionConstraint {Constraint : "2022.01.01" , Strategy : StrategyCalVer , MatchArgs : "YYYY.MM.DD" }
122+ newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
123+ assert .NoError (t , err )
124+ assert .NotNil (t , newTag )
125+ assert .Equal (t , "2023.05.01" , newTag .TagName )
126+ })
127+
128+ t .Run ("Empty tag list with calver should return nil" , func (t * testing.T ) {
129+ tagList := newImageTagList ([]string {})
130+ img := NewFromIdentifier ("jannfis/test:2021.01.01" )
131+ vc := VersionConstraint {Constraint : "2022.01.01" , Strategy : StrategyCalVer , MatchArgs : "YYYY.MM.DD" }
132+ newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
133+ assert .NoError (t , err )
134+ assert .Nil (t , newTag )
135+ })
136+
137+ t .Run ("Missing constraint with calver should use current date" , func (t * testing.T ) {
138+ tagList := newImageTagList ([]string {"2021.01.01" , "2022.02.02" , "2023.05.01" })
139+ img := NewFromIdentifier ("jannfis/test:2021.01.01" )
140+ vc := VersionConstraint {Strategy : StrategyCalVer , MatchArgs : "YYYY.MM.DD" }
141+ newTag , err := img .GetNewestVersionFromTags (& vc , tagList )
142+ assert .NoError (t , err )
143+ assert .NotNil (t , newTag )
144+ assert .Equal (t , "2023.05.01" , newTag .TagName )
86145 })
87146
88147 t .Run ("Find the latest version with no tags" , func (t * testing.T ) {
@@ -149,6 +208,7 @@ func Test_UpdateStrategy_String(t *testing.T) {
149208 {"StrategyNewestBuild" , StrategyNewestBuild , "newest-build" },
150209 {"StrategyAlphabetical" , StrategyAlphabetical , "alphabetical" },
151210 {"StrategyDigest" , StrategyDigest , "digest" },
211+ {"StrategyCalVer" , StrategyCalVer , "calver" },
152212 {"unknown" , UpdateStrategy (- 1 ), "unknown" },
153213 }
154214 for _ , tt := range tests {
@@ -180,26 +240,30 @@ func Test_UpdateStrategy_IsCacheable(t *testing.T) {
180240 assert .True (t , StrategySemVer .IsCacheable ())
181241 assert .True (t , StrategyNewestBuild .IsCacheable ())
182242 assert .True (t , StrategyAlphabetical .IsCacheable ())
243+ assert .True (t , StrategyCalVer .IsCacheable ())
183244 assert .False (t , StrategyDigest .IsCacheable ())
184245}
185246
186247func Test_UpdateStrategy_NeedsMetadata (t * testing.T ) {
187248 assert .False (t , StrategySemVer .NeedsMetadata ())
188249 assert .True (t , StrategyNewestBuild .NeedsMetadata ())
189250 assert .False (t , StrategyAlphabetical .NeedsMetadata ())
251+ assert .False (t , StrategyCalVer .NeedsMetadata ())
190252 assert .False (t , StrategyDigest .NeedsMetadata ())
191253}
192254
193255func Test_UpdateStrategy_NeedsVersionConstraint (t * testing.T ) {
194256 assert .False (t , StrategySemVer .NeedsVersionConstraint ())
195257 assert .False (t , StrategyNewestBuild .NeedsVersionConstraint ())
196258 assert .False (t , StrategyAlphabetical .NeedsVersionConstraint ())
259+ assert .True (t , StrategyCalVer .NeedsVersionConstraint ())
197260 assert .True (t , StrategyDigest .NeedsVersionConstraint ())
198261}
199262
200263func Test_UpdateStrategy_WantsOnlyConstraintTag (t * testing.T ) {
201264 assert .False (t , StrategySemVer .WantsOnlyConstraintTag ())
202265 assert .False (t , StrategyNewestBuild .WantsOnlyConstraintTag ())
203266 assert .False (t , StrategyAlphabetical .WantsOnlyConstraintTag ())
267+ assert .False (t , StrategyCalVer .WantsOnlyConstraintTag ())
204268 assert .True (t , StrategyDigest .WantsOnlyConstraintTag ())
205269}
0 commit comments