package io.digdag.standards.command.ecs;

import com.amazonaws.services.ecs.AmazonECSClient;
import com.amazonaws.services.ecs.model.ListTagsForResourceRequest;
import com.amazonaws.services.ecs.model.ListTagsForResourceResult;
import com.amazonaws.services.ecs.model.Tag;
import com.amazonaws.services.logs.AWSLogs;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;

@RunWith(MockitoJUnitRunner.class)
public class DefaultEcsClientTest
{
    @Mock private EcsClientConfig ecsClientConfig;
    @Mock private AmazonECSClient rawEcsClient;
    @Mock private AWSLogs logs;

    private DefaultEcsClient ecsClient;

    @Before
    public void setUp()
    {
        ecsClient = spy(new DefaultEcsClient(ecsClientConfig, rawEcsClient, logs));
    }

    @Test
    public void testGetTaskDefinitionTags()
            throws Exception
    {
        final List<Tag> expected = ImmutableList.of(
                new Tag().withKey("k1").withValue("v1"),
                new Tag().withKey("k2").withValue("v2")
        );
        final ListTagsForResourceResult result = new ListTagsForResourceResult()
                .withTags(expected);
        doReturn(result).when(rawEcsClient).listTagsForResource(any(ListTagsForResourceRequest.class));

        List<Tag> tags = ecsClient.getTaskDefinitionTags("my_task_def_arn");
        assertEquals(expected.size(), tags.size());
        assertEquals(expected.get(0), tags.get(0));
        assertEquals(expected.get(1), tags.get(1));
    }
}

@@ -1348,16 +1348,153 @@
      );%0A
+        final ListTagsForResourceRequest request = new ListTagsForResourceRequest()%0A                .withResourceArn(%22my_task_def_arn%22);%0A
         
@@ -1671,45 +1671,15 @@
 rce(
-any(ListTagsForResourceRequest.class)
+request
 );%0A%0A
@@ -1735,33 +1735,40 @@
 ionTags(
-%22my_task_def_arn%22
+request.getResourceArn()
 );%0A     

fix ecs.DefaultEcsClientTest to check that getTaskDefinitionTags works with specific task definition arn