Skip to content

Commit 0ad1f6d

Browse files
committed
add task label filter test case
1 parent 389bcfa commit 0ad1f6d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/test/java/com/github/dockerjava/cmd/swarm/ListTasksCmdExecIT.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
1616

17+
import java.util.Collections;
1718
import java.util.List;
19+
import java.util.Map;
1820

1921
import static com.github.dockerjava.junit.DockerRule.DEFAULT_IMAGE;
2022
import static org.hamcrest.MatcherAssert.assertThat;
@@ -24,14 +26,16 @@
2426
public class ListTasksCmdExecIT extends SwarmCmdIT {
2527
public static final Logger LOG = LoggerFactory.getLogger(CreateServiceCmdExecIT.class);
2628
private static final String SERVICE_NAME = "inspect_task";
29+
private static final String TASK_LABEL_KEY = "com.github.dockerjava.usage";
30+
private static final String TASK_LABEL_VALUE = "test";
2731

2832
@Test
2933
public void testListTasks() throws DockerException {
3034
dockerRule.getClient().initializeSwarmCmd(new SwarmSpec())
3135
.withListenAddr("127.0.0.1")
3236
.withAdvertiseAddr("127.0.0.1")
3337
.exec();
34-
38+
Map<String, String> taskLabels = Collections.singletonMap(TASK_LABEL_KEY, TASK_LABEL_VALUE);
3539
CreateServiceResponse response = dockerRule.getClient().createServiceCmd(new ServiceSpec()
3640
.withName(SERVICE_NAME)
3741
.withMode(new ServiceModeConfig().withReplicated(
@@ -40,7 +44,7 @@ public void testListTasks() throws DockerException {
4044
))
4145
.withTaskTemplate(new TaskSpec()
4246
.withContainerSpec(new ContainerSpec()
43-
.withImage(DEFAULT_IMAGE))))
47+
.withImage(DEFAULT_IMAGE))).withLabels(taskLabels))
4448
.exec();
4549
String serviceId = response.getId();
4650
//filtering with service id
@@ -60,6 +64,11 @@ public void testListTasks() throws DockerException {
6064
//filtering with state
6165
tasks = dockerRule.getClient().listTasksCmd().withStateFilter(TaskState.RUNNING).exec();
6266
assertThat(tasks, hasSize(2));
67+
//filter labels
68+
tasks = dockerRule.getClient().listTasksCmd().withLabelFilter(taskLabels).exec();
69+
assertThat(tasks, hasSize(2));
70+
tasks = dockerRule.getClient().listTasksCmd().withLabelFilter(TASK_LABEL_KEY + "=" + TASK_LABEL_VALUE).exec();
71+
assertThat(tasks, hasSize(2));
6372
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
6473
}
6574
}

0 commit comments

Comments
 (0)