|
| 1 | +package com.github.dockerjava.cmd.swarm; |
| 2 | + |
| 3 | +import com.github.dockerjava.api.DockerClient; |
| 4 | +import com.github.dockerjava.api.model.SwarmNode; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.List; |
| 9 | + |
| 10 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 11 | +import static org.hamcrest.Matchers.is; |
| 12 | + |
| 13 | +public class ListSwarmNodesCmdExecIT extends SwarmCmdIT { |
| 14 | + @Test |
| 15 | + public void testListSwarmNodes() throws Exception { |
| 16 | + DockerClient dockerClient = startSwarm(); |
| 17 | + |
| 18 | + List<SwarmNode> nodes = dockerClient.listSwarmNodesCmd().exec(); |
| 19 | + assertThat(nodes.size(), is(1)); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testListSwarmNodesWithIdFilter() throws Exception { |
| 24 | + DockerClient dockerClient = startSwarm(); |
| 25 | + |
| 26 | + List<SwarmNode> nodes = dockerClient.listSwarmNodesCmd().exec(); |
| 27 | + assertThat(nodes.size(), is(1)); |
| 28 | + |
| 29 | + String nodeId = nodes.get(0).getId(); |
| 30 | + List<SwarmNode> nodesWithId = dockerClient.listSwarmNodesCmd() |
| 31 | + .withIdFilter(Collections.singletonList(nodeId)) |
| 32 | + .exec(); |
| 33 | + assertThat(nodesWithId.size(), is(1)); |
| 34 | + |
| 35 | + List<SwarmNode> nodesWithNonexistentId = dockerClient.listSwarmNodesCmd() |
| 36 | + .withIdFilter(Collections.singletonList("__nonexistent__")) |
| 37 | + .exec(); |
| 38 | + assertThat(nodesWithNonexistentId.size(), is(0)); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testListSwarmNodesWithNameFilter() throws Exception { |
| 43 | + DockerClient dockerClient = startSwarm(); |
| 44 | + |
| 45 | + List<SwarmNode> nodes = dockerClient.listSwarmNodesCmd().exec(); |
| 46 | + assertThat(nodes.size(), is(1)); |
| 47 | + |
| 48 | + String nodeName = nodes.get(0).getSpec().getName(); |
| 49 | + List<SwarmNode> nodesWithFirstNodesName = dockerClient.listSwarmNodesCmd() |
| 50 | + .withNameFilter(Collections.singletonList(nodeName)) |
| 51 | + .exec(); |
| 52 | + assertThat(nodesWithFirstNodesName.size(), is(1)); |
| 53 | + |
| 54 | + List<SwarmNode> nodesWithNonexistentName = dockerClient.listSwarmNodesCmd() |
| 55 | + .withNameFilter(Collections.singletonList("__nonexistent__")) |
| 56 | + .exec(); |
| 57 | + assertThat(nodesWithNonexistentName.size(), is(0)); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testListSwarmNodesWithMembershipFilter() throws Exception { |
| 62 | + DockerClient dockerClient = startSwarm(); |
| 63 | + |
| 64 | + List<SwarmNode> nodesWithAcceptedMembership = dockerClient.listSwarmNodesCmd() |
| 65 | + .withMembershipFilter(Collections.singletonList("accepted")) |
| 66 | + .exec(); |
| 67 | + assertThat(nodesWithAcceptedMembership.size(), is(1)); |
| 68 | + |
| 69 | + List<SwarmNode> nodesWithPendingMembership = dockerClient.listSwarmNodesCmd() |
| 70 | + .withMembershipFilter(Collections.singletonList("pending")) |
| 71 | + .exec(); |
| 72 | + assertThat(nodesWithPendingMembership.size(), is(0)); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testListSwarmNodesWithRoleFilter() throws Exception { |
| 77 | + DockerClient dockerClient = startSwarm(); |
| 78 | + |
| 79 | + List<SwarmNode> nodesWithManagerRole = dockerClient.listSwarmNodesCmd() |
| 80 | + .withRoleFilter(Collections.singletonList("manager")) |
| 81 | + .exec(); |
| 82 | + assertThat(nodesWithManagerRole.size(), is(1)); |
| 83 | + |
| 84 | + List<SwarmNode> nodesWithWorkerRole = dockerClient.listSwarmNodesCmd() |
| 85 | + .withRoleFilter(Collections.singletonList("worker")) |
| 86 | + .exec(); |
| 87 | + assertThat(nodesWithWorkerRole.size(), is(0)); |
| 88 | + } |
| 89 | +} |
0 commit comments