@@ -409,3 +409,74 @@ func (s *instanceTypeSuite) TestSortByCost(c *gc.C) {
409
409
c .Check (names , gc .DeepEquals , t .expectedItypes )
410
410
}
411
411
}
412
+
413
+ var byNameTests = []struct {
414
+ about string
415
+ itypesToUse []InstanceType
416
+ expectedItypes []string
417
+ }{
418
+ {
419
+ about : "when different Name, pick lowest Name after delimiter" ,
420
+ itypesToUse : []InstanceType {
421
+ {Id : "2" , Name : "a1.xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 240 },
422
+ {Id : "1" , Name : "c2.12xLarge" , CpuCores : 1 , Mem : 2048 , Cost : 241 },
423
+ },
424
+ expectedItypes : []string {
425
+ "a1.xLarge" , "c2.12xLarge" ,
426
+ },
427
+ }, {
428
+ about : "when differentsame Name before delimiter, pick lowest cost" ,
429
+ itypesToUse : []InstanceType {
430
+ {Id : "2" , Name : "a1.xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 240 },
431
+ {Id : "3" , Name : "a1.6xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 440 },
432
+ {Id : "1" , Name : "a1.12xLarge" , CpuCores : 1 , Mem : 2048 , Cost : 800 },
433
+ },
434
+ expectedItypes : []string {
435
+ "a1.xLarge" , "a1.6xLarge" , "a1.12xLarge" ,
436
+ },
437
+ },
438
+ {
439
+ about : "when name mixture, same and different, before delimiter, pick lowest cost" ,
440
+ itypesToUse : []InstanceType {
441
+ {Id : "2" , Name : "a1.xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 240 },
442
+ {Id : "3" , Name : "a1.6xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 440 },
443
+ {Id : "4" , Name : "b1.4xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 500 },
444
+ {Id : "5" , Name : "b1.2xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 400 },
445
+ {Id : "1" , Name : "a1.12xLarge" , CpuCores : 1 , Mem : 2048 , Cost : 800 },
446
+ },
447
+ expectedItypes : []string {
448
+ "a1.xLarge" , "a1.6xLarge" , "a1.12xLarge" , "b1.2xLarge" , "b1.4xLarge" ,
449
+ },
450
+ },
451
+ {
452
+ about : "when different no delimiter, base to lexical sort" ,
453
+ itypesToUse : []InstanceType {
454
+ {Id : "2" , Name : "a1xLarge" , CpuCores : 2 , Mem : 4096 , Cost : 300 },
455
+ {Id : "1" , Name : "c212xLarge" , CpuCores : 1 , Mem : 2048 , Cost : 241 },
456
+ },
457
+ expectedItypes : []string {
458
+ "a1xLarge" , "c212xLarge" ,
459
+ },
460
+ }, {
461
+ about : "when different not defined delimiter, base to lexical sort" ,
462
+ itypesToUse : []InstanceType {
463
+ {Id : "2" , Name : "a1+12xlarge" , CpuCores : 2 , Mem : 4096 , Cost : 890 },
464
+ {Id : "1" , Name : "c2+12xLarge" , CpuCores : 1 , Mem : 2048 , Cost : 800 },
465
+ },
466
+ expectedItypes : []string {
467
+ "a1+12xlarge" , "c2+12xLarge" ,
468
+ },
469
+ },
470
+ }
471
+
472
+ func (s * instanceTypeSuite ) TestSortByName (c * gc.C ) {
473
+ for i , t := range byNameTests {
474
+ c .Logf ("test %d: %s" , i , t .about )
475
+ sort .Sort (ByName (t .itypesToUse ))
476
+ names := make ([]string , len (t .itypesToUse ))
477
+ for i , itype := range t .itypesToUse {
478
+ names [i ] = itype .Name
479
+ }
480
+ c .Check (names , gc .DeepEquals , t .expectedItypes )
481
+ }
482
+ }
0 commit comments