@@ -303,6 +303,39 @@ func TestLessThan(t *testing.T) {
303
303
}
304
304
}
305
305
306
+ func TestLessThanEqual (t * testing.T ) {
307
+ tests := []struct {
308
+ v1 string
309
+ v2 string
310
+ expected bool
311
+ }{
312
+ {"1.2.3" , "1.5.1" , true },
313
+ {"2.2.3" , "1.5.1" , false },
314
+ {"1.5.1" , "1.5.1" , true },
315
+ }
316
+
317
+ for _ , tc := range tests {
318
+ v1 , err := NewVersion (tc .v1 )
319
+ if err != nil {
320
+ t .Errorf ("Error parsing version: %s" , err )
321
+ }
322
+
323
+ v2 , err := NewVersion (tc .v2 )
324
+ if err != nil {
325
+ t .Errorf ("Error parsing version: %s" , err )
326
+ }
327
+
328
+ a := v1 .LessThanEqual (v2 )
329
+ e := tc .expected
330
+ if a != e {
331
+ t .Errorf (
332
+ "Comparison of '%s' and '%s' failed. Expected '%t', got '%t'" ,
333
+ tc .v1 , tc .v2 , e , a ,
334
+ )
335
+ }
336
+ }
337
+ }
338
+
306
339
func TestGreaterThan (t * testing.T ) {
307
340
tests := []struct {
308
341
v1 string
@@ -341,6 +374,39 @@ func TestGreaterThan(t *testing.T) {
341
374
}
342
375
}
343
376
377
+ func TestGreaterThanEqual (t * testing.T ) {
378
+ tests := []struct {
379
+ v1 string
380
+ v2 string
381
+ expected bool
382
+ }{
383
+ {"1.2.3" , "1.5.1" , false },
384
+ {"2.2.3" , "1.5.1" , true },
385
+ {"1.5.1" , "1.5.1" , true },
386
+ }
387
+
388
+ for _ , tc := range tests {
389
+ v1 , err := NewVersion (tc .v1 )
390
+ if err != nil {
391
+ t .Errorf ("Error parsing version: %s" , err )
392
+ }
393
+
394
+ v2 , err := NewVersion (tc .v2 )
395
+ if err != nil {
396
+ t .Errorf ("Error parsing version: %s" , err )
397
+ }
398
+
399
+ a := v1 .GreaterThanEqual (v2 )
400
+ e := tc .expected
401
+ if a != e {
402
+ t .Errorf (
403
+ "Comparison of '%s' and '%s' failed. Expected '%t', got '%t'" ,
404
+ tc .v1 , tc .v2 , e , a ,
405
+ )
406
+ }
407
+ }
408
+ }
409
+
344
410
func TestEqual (t * testing.T ) {
345
411
tests := []struct {
346
412
v1 * Version
0 commit comments