@@ -607,6 +607,54 @@ func TestRunTask_WithTaskNetworking(t *testing.T) {
607
607
assert .NoError (t , err , "Unexpected error when calling RunTask" )
608
608
}
609
609
610
+ func TestRunTask_WithTaskPlacement (t * testing.T ) {
611
+ mockEcs , _ , client , ctrl := setupTestController (t , getDefaultCLIConfigParams (t ))
612
+ defer ctrl .Finish ()
613
+
614
+ td := "taskDef"
615
+ group := "taskGroup"
616
+ count := 5
617
+
618
+ placementConstraints := []* ecs.PlacementConstraint {
619
+ {
620
+ Type : aws .String ("distinctInstance" ),
621
+ }, {
622
+ Expression : aws .String ("attribute:ecs.instance-type =~ t2.*" ),
623
+ Type : aws .String ("memberOf" ),
624
+ },
625
+ }
626
+ placementStrategy := []* ecs.PlacementStrategy {
627
+ {
628
+ Type : aws .String ("random" ),
629
+ }, {
630
+ Field : aws .String ("instanceId" ),
631
+ Type : aws .String ("binpack" ),
632
+ },
633
+ }
634
+
635
+ mockEcs .EXPECT ().RunTask (gomock .Any ()).Do (func (input interface {}) {
636
+ req := input .(* ecs.RunTaskInput )
637
+ assert .Equal (t , clusterName , aws .StringValue (req .Cluster ), "Expected clusterName to match" )
638
+ assert .Equal (t , td , aws .StringValue (req .TaskDefinition ), "Expected taskDefinition to match" )
639
+ assert .Equal (t , group , aws .StringValue (req .Group ), "Expected group to match" )
640
+ assert .Equal (t , int64 (count ), aws .Int64Value (req .Count ), "Expected count to match" )
641
+ assert .Equal (t , placementConstraints , req .PlacementConstraints , "Expected placement constraints to match" )
642
+ assert .Equal (t , placementStrategy , req .PlacementStrategy , "Expected placement strategy to match" )
643
+ }).Return (& ecs.RunTaskOutput {}, nil )
644
+
645
+ runTaskInput := & ecs.RunTaskInput {
646
+ Cluster : aws .String (clusterName ),
647
+ TaskDefinition : aws .String (td ),
648
+ Group : aws .String (group ),
649
+ Count : aws .Int64 (int64 (count )),
650
+ LaunchType : aws .String ("EC2" ),
651
+ PlacementConstraints : placementConstraints ,
652
+ PlacementStrategy : placementStrategy ,
653
+ }
654
+ _ , err := client .RunTask (runTaskInput )
655
+ assert .NoError (t , err , "Unexpected error when calling RunTask" )
656
+ }
657
+
610
658
func TestIsActiveCluster (t * testing.T ) {
611
659
mockEcs , _ , client , ctrl := setupTestController (t , getDefaultCLIConfigParams (t ))
612
660
defer ctrl .Finish ()
0 commit comments