Skip to content

Commit

Permalink
Fix containerAction: use query params
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakesh Sahadevan authored and davidxia committed Jan 13, 2018
1 parent bc9f2ac commit 815fd63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ private void containerAction(final String containerId, final String action,
final MultivaluedMap<String, String> queryParameters)
throws DockerException, InterruptedException {
try {
final WebTarget resource = resource()
WebTarget resource = resource()
.path("containers").path(containerId).path(action);

for (Map.Entry<String, List<String>> queryParameter : queryParameters.entrySet()) {
for (String parameterValue : queryParameter.getValue()) {
resource.queryParam(queryParameter.getKey(), parameterValue);
resource = resource.queryParam(queryParameter.getKey(), parameterValue);
}
}
request(POST, resource, resource.request());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -47,6 +46,7 @@
import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;
import com.google.common.io.Resources;
import com.spotify.docker.client.DockerClient.Signal;
import com.spotify.docker.client.auth.RegistryAuthSupplier;
import com.spotify.docker.client.exceptions.ConflictException;
import com.spotify.docker.client.exceptions.DockerCertificateException;
Expand All @@ -71,7 +71,6 @@
import com.spotify.docker.client.messages.swarm.NodeDescription;
import com.spotify.docker.client.messages.swarm.NodeInfo;
import com.spotify.docker.client.messages.swarm.NodeSpec;
import com.spotify.docker.client.messages.swarm.SecretSpec;
import com.spotify.docker.client.messages.swarm.ServiceSpec;
import com.spotify.docker.client.messages.swarm.SwarmJoin;
import com.spotify.docker.client.messages.swarm.TaskSpec;
Expand All @@ -83,6 +82,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
Expand Down Expand Up @@ -1012,6 +1012,21 @@ public void testBindBuilderSelinuxLabeling() throws Exception {
assertThat(bindSet, hasItem(allOf(containsString("private"), containsString("Z"))));
}

@Test
public void testKillContainer() throws Exception {
final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);

server.enqueue(new MockResponse());

final Signal signal = Signal.SIGHUP;
dockerClient.killContainer("1234", signal);

final RecordedRequest recordedRequest = takeRequestImmediately();

final HttpUrl requestUrl = recordedRequest.getRequestUrl();
assertThat(requestUrl.queryParameter("signal"), equalTo(signal.toString()));
}

private void enqueueServerApiResponse(final int statusCode, final String fileName)
throws IOException {
server.enqueue(new MockResponse()
Expand Down

0 comments on commit 815fd63

Please sign in to comment.