@@ -332,12 +332,13 @@ func TestConvertToTaskDefinitionLaunchTypeFargate(t *testing.T) {
332
332
}
333
333
334
334
// Tests for ConvertToContainerDefinition with ECS Params
335
- func TestConvertToTaskDefinitionWithECSParams_DefaultMemoryLessThanMemoryRes (t * testing.T ) {
335
+ func TestConvertToTaskDefinitionWithECSParams_ComposeMemoryLessThanMemoryRes (t * testing.T ) {
336
336
// set up containerConfig w/o value for Memory
337
337
containerConfig := & adapter.ContainerConfig {
338
- Name : "web" ,
339
- Image : "httpd" ,
340
- CPU : int64 (5 ),
338
+ Name : "web" ,
339
+ Image : "httpd" ,
340
+ CPU : int64 (5 ),
341
+ Memory : int64 (512 ),
341
342
}
342
343
343
344
// define ecs-params value we expect to be present in final containerDefinition
@@ -942,7 +943,7 @@ task_definition:
942
943
}
943
944
}
944
945
945
- func TestConvertToTaskDefinitionWithECSParams_SomeContainerResourcesProvided (t * testing.T ) {
946
+ func TestConvertToTaskDefinitionWithECSParams_MemLimitOnlyProvided (t * testing.T ) {
946
947
// set up containerConfig w/o value for Memory
947
948
containerConfig := & adapter.ContainerConfig {
948
949
Name : "web" ,
@@ -993,6 +994,48 @@ task_definition:
993
994
}
994
995
}
995
996
997
+ func TestConvertToTaskDefinitionWithECSParams_MemReservationOnlyProvided (t * testing.T ) {
998
+ containerConfigs := testContainerConfigs ([]string {"web" })
999
+
1000
+ // define ecs-params value we expect to be present in final containerDefinition
1001
+ webMem := int64 (20 )
1002
+
1003
+ ecsParamsString := `version: 1
1004
+ task_definition:
1005
+ services:
1006
+ web:
1007
+ mem_reservation: 20m`
1008
+
1009
+ content := []byte (ecsParamsString )
1010
+
1011
+ tmpfile , err := ioutil .TempFile ("" , "ecs-params" )
1012
+ assert .NoError (t , err , "Could not create ecs params tempfile" )
1013
+
1014
+ defer os .Remove (tmpfile .Name ())
1015
+
1016
+ _ , err = tmpfile .Write (content )
1017
+ assert .NoError (t , err , "Could not write data to ecs params tempfile" )
1018
+
1019
+ err = tmpfile .Close ()
1020
+ assert .NoError (t , err , "Could not close tempfile" )
1021
+
1022
+ ecsParamsFileName := tmpfile .Name ()
1023
+ ecsParams , err := ReadECSParams (ecsParamsFileName )
1024
+ assert .NoError (t , err , "Could not read ECS Params file" )
1025
+
1026
+ taskDefinition , err := convertToTaskDefWithEcsParamsInTest (t , containerConfigs , "" , ecsParams )
1027
+
1028
+ containerDefs := taskDefinition .ContainerDefinitions
1029
+ web := findContainerByName ("web" , containerDefs )
1030
+
1031
+ if assert .NoError (t , err ) {
1032
+ assert .Equal (t , webMem , aws .Int64Value (web .Memory ), "Expected Memory to match" )
1033
+ assert .Equal (t , webMem , aws .Int64Value (web .MemoryReservation ), "Expected MemoryReservation to match" )
1034
+ // check config values not present in ecs-params are present
1035
+ assert .Empty (t , web .Cpu , "Expected CPU to be empty" )
1036
+ }
1037
+ }
1038
+
996
1039
func TestConvertToTaskDefinitionWithECSParams_MemResGreaterThanMemLimit (t * testing.T ) {
997
1040
containerConfig := & adapter.ContainerConfig {Name : "web" }
998
1041
ecsParamsString := `version: 1
@@ -1058,28 +1101,56 @@ task_definition:
1058
1101
}
1059
1102
}
1060
1103
1061
- func TestMemReservationHigherThanMemLimit (t * testing.T ) {
1062
- cpu := int64 (131072 ) // 128 * 1024
1063
- command := "cmd"
1064
- hostname := "local360"
1065
- image := "testimage"
1066
- memory := int64 ( 65536 ) // 64mb
1067
- privileged := true
1068
- readOnly := true
1069
- user := "user"
1070
- workingDir := "/var"
1104
+ func TestConvertToTaskDefinition_MemLimitOnlyProvided (t * testing.T ) {
1105
+ webMem := int64 (1048576 )
1106
+ containerConfig := & adapter. ContainerConfig {
1107
+ Name : "web" ,
1108
+ Memory : webMem ,
1109
+ }
1110
+
1111
+ taskDefinition := convertToTaskDefinitionInTest ( t , containerConfig , "" , "" )
1112
+ containerDefs := taskDefinition . ContainerDefinitions
1113
+ web := findContainerByName ( "web" , containerDefs )
1071
1114
1115
+ assert .Equal (t , webMem , aws .Int64Value (web .Memory ), "Expected Memory to match" )
1116
+ assert .Empty (t , web .MemoryReservation , "Expected MemoryReservation to be empty" )
1117
+ assert .Empty (t , web .Cpu , "Expected CPU to be empty" )
1118
+ }
1119
+
1120
+ func TestConvertToTaskDefinition_MemReservationOnlyProvided (t * testing.T ) {
1121
+ webMem := int64 (1048576 )
1122
+ containerConfig := & adapter.ContainerConfig {
1123
+ Name : "web" ,
1124
+ MemoryReservation : webMem ,
1125
+ }
1126
+
1127
+ taskDefinition := convertToTaskDefinitionInTest (t , containerConfig , "" , "" )
1128
+ containerDefs := taskDefinition .ContainerDefinitions
1129
+ web := findContainerByName ("web" , containerDefs )
1130
+
1131
+ assert .Equal (t , webMem , aws .Int64Value (web .Memory ), "Expected Memory to match" )
1132
+ assert .Equal (t , webMem , aws .Int64Value (web .MemoryReservation ), "Expected MemoryReservation to match" )
1133
+ assert .Empty (t , web .Cpu , "Expected CPU to be empty" )
1134
+ }
1135
+
1136
+ func TestConvertToTaskDefinition_NoMemoryProvided (t * testing.T ) {
1137
+ containerConfig := & adapter.ContainerConfig {
1138
+ Name : "web" ,
1139
+ }
1140
+
1141
+ taskDefinition := convertToTaskDefinitionInTest (t , containerConfig , "" , "" )
1142
+ containerDefs := taskDefinition .ContainerDefinitions
1143
+ web := findContainerByName ("web" , containerDefs )
1144
+
1145
+ assert .Equal (t , aws .Int64 (defaultMemLimit ), web .Memory , "Expected Memory to match default" )
1146
+ assert .Empty (t , web .MemoryReservation , "Expected MemoryReservation to be empty" )
1147
+ assert .Empty (t , web .Cpu , "Expected CPU to be empty" )
1148
+ }
1149
+
1150
+ func TestMemReservationHigherThanMemLimit (t * testing.T ) {
1072
1151
containerConfig := adapter.ContainerConfig {
1073
- CPU : cpu ,
1074
- Command : []string {command },
1075
- Hostname : hostname ,
1076
- Image : image ,
1077
- Memory : int64 (524288 ) * memory ,
1078
- MemoryReservation : int64 (1048576 ) * memory ,
1079
- Privileged : privileged ,
1080
- ReadOnly : readOnly ,
1081
- User : user ,
1082
- WorkingDirectory : workingDir ,
1152
+ Memory : int64 (524288 ),
1153
+ MemoryReservation : int64 (1048576 ),
1083
1154
}
1084
1155
1085
1156
volumeConfigs := adapter .NewVolumes ()
0 commit comments