@@ -471,6 +471,86 @@ func TestConvertToECSNetworkConfiguration_NoNetworkConfig(t *testing.T) {
471
471
}
472
472
}
473
473
474
+ func TestConvertToECSPlacementConstraints (t * testing.T ) {
475
+ constraint1 := Constraint {
476
+ Expression : "attribute:ecs.instance-type =~ t2.*" ,
477
+ Type : ecs .PlacementConstraintTypeMemberOf ,
478
+ }
479
+ constraint2 := Constraint {
480
+ Type : ecs .PlacementConstraintTypeDistinctInstance ,
481
+ }
482
+ constraints := []Constraint {constraint1 , constraint2 }
483
+ taskPlacement := TaskPlacement {
484
+ Constraints : constraints ,
485
+ }
486
+
487
+ ecsParams := & ECSParams {
488
+ RunParams : RunParams {
489
+ TaskPlacement : taskPlacement ,
490
+ },
491
+ }
492
+
493
+ expectedConstraints := []* ecs.PlacementConstraint {
494
+ & ecs.PlacementConstraint {
495
+ Expression : aws .String ("attribute:ecs.instance-type =~ t2.*" ),
496
+ Type : aws .String (ecs .PlacementConstraintTypeMemberOf ),
497
+ },
498
+ & ecs.PlacementConstraint {
499
+ Type : aws .String (ecs .PlacementConstraintTypeDistinctInstance ),
500
+ },
501
+ }
502
+
503
+ ecsPlacementConstraints , err := ConvertToECSPlacementConstraints (ecsParams )
504
+
505
+ if assert .NoError (t , err ) {
506
+ assert .ElementsMatch (t , expectedConstraints , ecsPlacementConstraints , "Expected placement constraints to match" )
507
+ }
508
+ }
509
+
510
+ func TestConvertToECSPlacementStrategy (t * testing.T ) {
511
+ strategy1 := Strategy {
512
+ Field : "instanceId" ,
513
+ Type : ecs .PlacementStrategyTypeBinpack ,
514
+ }
515
+ strategy2 := Strategy {
516
+ Field : "attribute:ecs.availability-zone" ,
517
+ Type : ecs .PlacementStrategyTypeSpread ,
518
+ }
519
+ strategy3 := Strategy {
520
+ Type : ecs .PlacementStrategyTypeRandom ,
521
+ }
522
+ strategy := []Strategy {strategy1 , strategy2 , strategy3 }
523
+ taskPlacement := TaskPlacement {
524
+ Strategies : strategy ,
525
+ }
526
+
527
+ ecsParams := & ECSParams {
528
+ RunParams : RunParams {
529
+ TaskPlacement : taskPlacement ,
530
+ },
531
+ }
532
+
533
+ expectedStrategy := []* ecs.PlacementStrategy {
534
+ & ecs.PlacementStrategy {
535
+ Field : aws .String ("instanceId" ),
536
+ Type : aws .String (ecs .PlacementStrategyTypeBinpack ),
537
+ },
538
+ & ecs.PlacementStrategy {
539
+ Field : aws .String ("attribute:ecs.availability-zone" ),
540
+ Type : aws .String (ecs .PlacementStrategyTypeSpread ),
541
+ },
542
+ & ecs.PlacementStrategy {
543
+ Type : aws .String (ecs .PlacementStrategyTypeRandom ),
544
+ },
545
+ }
546
+
547
+ ecsPlacementStrategy , err := ConvertToECSPlacementStrategy (ecsParams )
548
+
549
+ if assert .NoError (t , err ) {
550
+ assert .ElementsMatch (t , expectedStrategy , ecsPlacementStrategy , "Expected placement strategy to match" )
551
+ }
552
+ }
553
+
474
554
func TestReadECSParams_WithHealthCheck (t * testing.T ) {
475
555
ecsParamsString := `version: 1
476
556
task_definition:
0 commit comments