|
| 1 | +/** |
| 2 | + * Copyright (c) 2018-2019, Mihai Emil Andronache |
| 3 | + * All rights reserved. |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions are met: |
| 6 | + * 1)Redistributions of source code must retain the above copyright notice, |
| 7 | + * this list of conditions and the following disclaimer. |
| 8 | + * 2)Redistributions in binary form must reproduce the above copyright notice, |
| 9 | + * this list of conditions and the following disclaimer in the documentation |
| 10 | + * and/or other materials provided with the distribution. |
| 11 | + * 3)Neither the name of docker-java-api nor the names of its |
| 12 | + * contributors may be used to endorse or promote products derived from |
| 13 | + * this software without specific prior written permission. |
| 14 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 18 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 24 | + * POSSIBILITY OF SUCH DAMAGE. |
| 25 | + */ |
| 26 | +package com.amihaiemil.docker; |
| 27 | + |
| 28 | +import org.apache.commons.io.IOUtils; |
| 29 | +import org.hamcrest.MatcherAssert; |
| 30 | +import org.hamcrest.core.StringStartsWith; |
| 31 | +import org.junit.Ignore; |
| 32 | +import org.junit.Test; |
| 33 | + |
| 34 | +import java.io.File; |
| 35 | + |
| 36 | +/** |
| 37 | + * Integration tests for {@link RtLogs}. |
| 38 | + * @author Mihai Andronache (amihaiemil@gmail.com) |
| 39 | + * @version $Id$ |
| 40 | + * @since 0.0.7 |
| 41 | + * @todo #256:30min Fix the IT case for follow(), it is currently failing. |
| 42 | + * We might have to implement the stream decoding (in case TTY is disabled |
| 43 | + * when the Container is created), as explained here, in "Stream format" |
| 44 | + * paragraph: |
| 45 | + * https://docs.docker.com/engine/api/v1.37/#operation/ContainerAttach |
| 46 | + */ |
| 47 | +public final class RtLogsITCase { |
| 48 | + |
| 49 | + /** |
| 50 | + * RtLogs can fetch the Container's logs (return them as a String). |
| 51 | + * @throws Exception If something goes wrong. |
| 52 | + */ |
| 53 | + @Test |
| 54 | + public void fetchesLogs() throws Exception { |
| 55 | + final Container container = new LocalDocker( |
| 56 | + new File("/var/run/docker.sock") |
| 57 | + ).images().pull("hello-world", "latest").run(); |
| 58 | + final String logs = container.logs().fetch(); |
| 59 | + MatcherAssert.assertThat( |
| 60 | + logs.trim(), |
| 61 | + new StringStartsWith("Hello from Docker!") |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * RtLogs can follow the Container's logs (return them as a Reader). |
| 67 | + * @throws Exception If something goes wrong. |
| 68 | + */ |
| 69 | + @Test |
| 70 | + @Ignore |
| 71 | + public void followsLogs() throws Exception { |
| 72 | + final Container container = new LocalDocker( |
| 73 | + new File("/var/run/docker.sock") |
| 74 | + ).images().pull("hello-world", "latest").run(); |
| 75 | + final String logs = IOUtils.toString(container.logs().follow()); |
| 76 | + MatcherAssert.assertThat( |
| 77 | + logs.trim(), |
| 78 | + new StringStartsWith("Hello from Docker!") |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
0 commit comments