Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5b9b0b

Browse filesBrowse files
klmntothbsideup
andauthored
Fix ListSwarmNodesCmdImpl and Add basic tests (#1385)
* Fix ListSwarmNodesCmdImpl and Add basic tests - fixes withMembershipsFilter - fixes withRoleFilter - adds basic tests for the class. * Update docker-java/src/test/java/com/github/dockerjava/cmd/swarm/ListSwarmNodesCmdExecIT.java * Update ListSwarmNodesCmdExecIT.java * use `startSwarm()` Co-authored-by: Sergei Egorov <segorov@pivotal.io> Co-authored-by: Sergei Egorov <bsideup@gmail.com>
1 parent 175329f commit a5b9b0b
Copy full SHA for a5b9b0b

File tree

Expand file treeCollapse file tree

2 files changed

+91
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+91
-2
lines changed

‎docker-java-core/src/main/java/com/github/dockerjava/core/command/ListSwarmNodesCmdImpl.java

Copy file name to clipboardExpand all lines: docker-java-core/src/main/java/com/github/dockerjava/core/command/ListSwarmNodesCmdImpl.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public ListSwarmNodesCmd withNameFilter(List<String> names) {
4444
@Override
4545
public ListSwarmNodesCmd withMembershipFilter(List<String> memberships) {
4646
checkNotNull(memberships, "memberships was not specified");
47-
this.filters.withNames(memberships);
47+
this.filters.withMemberships(memberships);
4848
return this;
4949
}
5050

5151
@Override
5252
public ListSwarmNodesCmd withRoleFilter(List<String> roles) {
5353
checkNotNull(roles, "roles was not specified");
54-
this.filters.withNames(roles);
54+
this.filters.withRoles(roles);
5555
return this;
5656
}
5757
}
+89Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.