spotify/docker-client — pull request #109 by JWGmeligMeyling (2014-12-19 13:53:31+00:00)
Title: Docker JUnit test rule to make testing commands fun

This is a JUnit `Rule` I made to make adding tests for commands more fun to do. I'd like to hear what you think about this way of testing client commands and maybe see it merged into the master :smile:

See for example this test code:

```java
package com.spotify.docker.client;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.IOException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import com.spotify.docker.client.DockerClient.LogsParameter;
import com.spotify.docker.test.CreateContainer;
import com.spotify.docker.test.DockerContainer;

public class DockerAttachTest {

private static DockerClient dockerClient;

@Rule
public DockerContainer dockerContainer = new DockerContainer(dockerClient);

@BeforeClass
public static void setUp() throws DockerCertificateException {
dockerClient = DefaultDockerClient.fromEnv().readTimeoutMillis(120000).build();
}

@Test
@CreateContainer(image = "busybox", command = {"sh", "-c", "echo \"test\""}, start = true)
public void testIt() throws IOException,
DockerException, InterruptedException {

String containerId = dockerContainer.getContainerId();
dockerClient.waitContainer(containerId);
LogStream logStream = dockerClient.logs(containerId, LogsParameter.STDOUT);
assertThat(logStream.readFully(), equalTo("test\n"));
}

@AfterClass
public static void cleanUp() {
dockerClient.close();
}

}
```