@Test public void testBuildImageFromDockerfile() throws IOException, InterruptedException, URISyntaxException { removeImageIfExists(IMAGE_TEST_TAG); BuildOptions options = BuildOptions.Builder.tag(IMAGE_TEST_TAG).verbose(false).nocache(true); InputStream buildImageStream = api().build(tarredDockerfile(), options); String buildStream = consumeStream(buildImageStream); try { Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim()); String lastStreamedLine = Iterables.getLast(splitted).trim(); String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine)); imageId = rawImageId.substring(0, 11); assertNotNull(imageId); } finally { removeImageIfExists(IMAGE_TEST_TAG); } }
@Test public void testInfo() { assertNotNull(api().getInfo()); }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("miscApiTest", containerConfig); assertNotNull(container); api.getContainerApi().startContainer(container.id()); assertTrue(api.getContainerApi().inspectContainer(container.id()).state().running()); }
@Test public void testVersion() { assertNotNull(api().getVersion().apiVersion()); assertNotNull(api().getVersion().version()); assertNotNull(api().getVersion().gitCommit()); assertNotNull(api().getVersion().goVersion()); assertNotNull(api().getVersion().kernelVersion()); assertNotNull(api().getVersion().arch()); assertNotNull(api().getVersion().os()); }
@Test(dependsOnMethods = "testExecStart") public void testExecInspect() throws IOException { ExecInspect execInspect = api().execInspect(exec.id()); assertNotNull(execInspect); assertEquals(execInspect.id(), exec.id()); assertEquals(execInspect.running(), false); assertEquals(execInspect.exitCode(), 2); }
@Test public void testExecCreate() { exec = api().execCreate(container.id(), ExecCreateParams.builder() .cmd(ImmutableList.<String> of("/bin/sh", "-c", "echo -n Standard >&1 && echo -n Error >&2 && exit 2")) .attachStderr(true).attachStdout(true).build()); assertNotNull(exec); assertNotNull(exec.id()); }
DockerInputStream inputStream = null; try { inputStream = new DockerInputStream(api().execStart(exec.id(), startParams)); assertNotNull(inputStream); ByteArrayOutputStream baosOut = new ByteArrayOutputStream();