@@ -178,6 +178,112 @@ func TestValidAttributesBetaToRelease(t *testing.T) {
178
178
}
179
179
}
180
180
181
+ func TestTargetBetaAndBetaComplex (t * testing.T ) {
182
+ testValues := []string {"2.1.3-beta+1" , "2.1.3+build-1.2.3" }
183
+ scenarios := []struct {
184
+ matchType string
185
+ version string
186
+ expected bool
187
+ }{
188
+ {matchType : "semver_eq" , version : "2.1.3-beta+1.2.3" , expected : false },
189
+ {matchType : "semver_eq" , version : "2.1.3+build-1" , expected : false },
190
+
191
+ {matchType : "semver_ge" , version : "2.1.3-beta+1.2.3" , expected : true },
192
+ {matchType : "semver_ge" , version : "2.1.3+build-1" , expected : false },
193
+
194
+ {matchType : "semver_gt" , version : "2.1.3-beta+1.2.3" , expected : true },
195
+ {matchType : "semver_gt" , version : "2.1.3+build-1" , expected : false },
196
+
197
+ {matchType : "semver_le" , version : "2.1.3-beta+1.2.3" , expected : false },
198
+ {matchType : "semver_le" , version : "2.1.3+build-1" , expected : true },
199
+
200
+ {matchType : "semver_lt" , version : "2.1.3-beta+1.2.3" , expected : false },
201
+ {matchType : "semver_lt" , version : "2.1.3+build-1" , expected : true },
202
+ }
203
+
204
+ for index , scenario := range scenarios {
205
+ condition := entities.Condition {
206
+ Match : scenario .matchType ,
207
+ Value : testValues [index % len (testValues )],
208
+ Name : "version" ,
209
+ }
210
+
211
+ user := entities.UserContext {
212
+ Attributes : map [string ]interface {}{
213
+ "version" : scenario .version ,
214
+ },
215
+ }
216
+
217
+ messageAndArgs := []interface {}{"matchType: %s, condition: %s, attribute: %s" , scenario .matchType , condition .Value , scenario .version }
218
+
219
+ matcher , ok := Get (scenario .matchType )
220
+ assert .True (t , ok , messageAndArgs ... )
221
+
222
+ actual , err := matcher (condition , user , nil )
223
+ assert .NoError (t , err , messageAndArgs ... )
224
+
225
+ assert .Equal (t , scenario .expected , actual , messageAndArgs ... )
226
+ }
227
+ }
228
+
229
+ func TestDifferentAttributeAgainstBuildAndPrerelease (t * testing.T ) {
230
+ testValues := []string {"3.7.0" , "3.7.0" , "3.7.0-prerelease" , "3.7.0-prerelease+build" }
231
+ scenarios := []struct {
232
+ matchType string
233
+ version string
234
+ expected bool
235
+ }{
236
+ {matchType : "semver_eq" , version : "3.7.0+build" , expected : true },
237
+ {matchType : "semver_eq" , version : "3.7.0-prerelease" , expected : false },
238
+ {matchType : "semver_eq" , version : "3.7.0+build" , expected : false },
239
+ {matchType : "semver_eq" , version : "3.7.0-prerelease-prelrease+rc" , expected : false },
240
+
241
+ {matchType : "semver_ge" , version : "3.7.0+build" , expected : true },
242
+ {matchType : "semver_ge" , version : "3.7.0-prerelease" , expected : false },
243
+ {matchType : "semver_ge" , version : "3.7.0+build" , expected : true },
244
+ {matchType : "semver_ge" , version : "3.7.0-prerelease-prelrease+rc" , expected : true },
245
+
246
+ {matchType : "semver_gt" , version : "3.7.0+build" , expected : false },
247
+ {matchType : "semver_gt" , version : "3.7.0-prerelease" , expected : false },
248
+ {matchType : "semver_gt" , version : "3.7.0+build" , expected : true },
249
+ {matchType : "semver_gt" , version : "3.7.0-prerelease-prelrease+rc" , expected : true },
250
+
251
+ {matchType : "semver_le" , version : "3.7.0+build" , expected : true },
252
+ {matchType : "semver_le" , version : "3.7.0-prerelease" , expected : true },
253
+ {matchType : "semver_le" , version : "3.7.0+build" , expected : false },
254
+ {matchType : "semver_le" , version : "3.7.0-prerelease-prelrease+rc" , expected : false },
255
+
256
+ {matchType : "semver_lt" , version : "3.7.0+build" , expected : false },
257
+ {matchType : "semver_lt" , version : "3.7.0-prerelease" , expected : true },
258
+ {matchType : "semver_lt" , version : "3.7.0+build" , expected : false },
259
+ {matchType : "semver_lt" , version : "3.7.0-prerelease-prelrease+rc" , expected : false },
260
+ }
261
+
262
+ for index , scenario := range scenarios {
263
+ condition := entities.Condition {
264
+ Match : scenario .matchType ,
265
+ Value : testValues [index % len (testValues )],
266
+ Name : "version" ,
267
+ }
268
+
269
+ user := entities.UserContext {
270
+ Attributes : map [string ]interface {}{
271
+ "version" : scenario .version ,
272
+ },
273
+ }
274
+
275
+ messageAndArgs := []interface {}{"matchType: %s, condition: %s, attribute: %s" , scenario .matchType , condition .Value , scenario .version }
276
+
277
+ matcher , ok := Get (scenario .matchType )
278
+ assert .True (t , ok , messageAndArgs ... )
279
+
280
+ actual , err := matcher (condition , user , nil )
281
+ assert .NoError (t , err , messageAndArgs ... )
282
+
283
+ assert .Equal (t , scenario .expected , actual , messageAndArgs ... )
284
+ }
285
+ }
286
+
181
287
func TestInvalidAttributes (t * testing.T ) {
182
288
183
289
condition := entities.Condition {
@@ -198,7 +304,6 @@ func TestInvalidAttributes(t *testing.T) {
198
304
true ,
199
305
37 ,
200
306
nil ,
201
- "" ,
202
307
"-" ,
203
308
"." ,
204
309
".." ,
0 commit comments