@@ -23,6 +23,7 @@ import (
23
23
24
24
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
25
25
apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
26
+ "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/restart"
26
27
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
27
28
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
28
29
"github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/response"
@@ -197,6 +198,61 @@ func TestContainerResponse(t *testing.T) {
197
198
assert .Equal (t , expectedContainerResponse , containerResponse )
198
199
}
199
200
201
+ func TestContainerResponseWithRestartPolicy (t * testing.T ) {
202
+ restartPolicy := & restart.RestartPolicy {
203
+ Enabled : true ,
204
+ }
205
+ container := & apicontainer.Container {
206
+ Name : containerName ,
207
+ Image : imageName ,
208
+ ImageID : imageID ,
209
+ Ports : []apicontainer.PortBinding {
210
+ {
211
+ ContainerPort : 80 ,
212
+ Protocol : apicontainer .TransportProtocolTCP ,
213
+ },
214
+ },
215
+ VolumesUnsafe : []types.MountPoint {
216
+ {
217
+ Name : volName ,
218
+ Source : volSource ,
219
+ Destination : volDestination ,
220
+ },
221
+ },
222
+ RestartPolicy : restartPolicy ,
223
+ RestartTracker : restart .NewRestartTracker (* restartPolicy ),
224
+ }
225
+
226
+ container .SetCreatedAt (containerTime )
227
+ container .SetStartedAt (containerTime )
228
+ container .RestartTracker .RecordRestart ()
229
+
230
+ dockerContainer := & apicontainer.DockerContainer {
231
+ DockerID : containerID ,
232
+ DockerName : containerName ,
233
+ Container : container ,
234
+ }
235
+
236
+ eni := & ni.NetworkInterface {
237
+ IPV4Addresses : []* ni.IPV4Address {
238
+ {
239
+ Address : eniIPv4Address ,
240
+ },
241
+ },
242
+ }
243
+
244
+ containerResponse := NewContainerResponse (dockerContainer , eni )
245
+
246
+ _ , err := json .Marshal (containerResponse )
247
+ assert .NoError (t , err )
248
+
249
+ expectedContainerResponseWithRestartPolicy := expectedContainerResponse
250
+ rc := int (1 )
251
+ expectedContainerResponseWithRestartPolicy .RestartCount = & rc
252
+
253
+ assert .Equal (t , expectedContainerResponseWithRestartPolicy , containerResponse )
254
+ }
255
+
200
256
func TestPortBindingsResponse (t * testing.T ) {
201
257
container := & apicontainer.Container {
202
258
Name : containerName ,
0 commit comments