|
2 | 2 |
|
3 | 3 | import com.squareup.moshi.Moshi; |
4 | 4 | import de.gesellix.docker.builder.BuildContextBuilder; |
| 5 | +import de.gesellix.docker.remote.api.BuildInfo; |
5 | 6 | import de.gesellix.docker.remote.api.BuildPruneResponse; |
6 | 7 | import de.gesellix.docker.remote.api.ContainerCreateRequest; |
7 | 8 | import de.gesellix.docker.remote.api.ContainerCreateResponse; |
|
10 | 11 | import de.gesellix.docker.remote.api.IdResponse; |
11 | 12 | import de.gesellix.docker.remote.api.Image; |
12 | 13 | import de.gesellix.docker.remote.api.ImageDeleteResponseItem; |
| 14 | +import de.gesellix.docker.remote.api.ImageID; |
13 | 15 | import de.gesellix.docker.remote.api.ImageSearchResponseItem; |
14 | 16 | import de.gesellix.docker.remote.api.ImageSummary; |
| 17 | +import de.gesellix.docker.remote.api.core.StreamCallback; |
15 | 18 | import de.gesellix.docker.remote.api.testutil.DockerEngineAvailable; |
16 | 19 | import de.gesellix.docker.remote.api.testutil.DockerRegistry; |
17 | 20 | import de.gesellix.docker.remote.api.testutil.HttpTestServer; |
|
23 | 26 | import de.gesellix.testutil.ResourceReader; |
24 | 27 | import org.junit.jupiter.api.BeforeEach; |
25 | 28 | import org.junit.jupiter.api.Test; |
| 29 | +import org.slf4j.Logger; |
| 30 | +import org.slf4j.LoggerFactory; |
26 | 31 |
|
27 | 32 | import java.io.ByteArrayInputStream; |
28 | 33 | import java.io.ByteArrayOutputStream; |
|
33 | 38 | import java.net.InetSocketAddress; |
34 | 39 | import java.net.URL; |
35 | 40 | import java.nio.file.Paths; |
| 41 | +import java.time.Duration; |
| 42 | +import java.time.temporal.ChronoUnit; |
| 43 | +import java.util.ArrayList; |
36 | 44 | import java.util.HashMap; |
37 | 45 | import java.util.List; |
38 | 46 | import java.util.Map; |
39 | 47 | import java.util.Optional; |
| 48 | +import java.util.concurrent.CountDownLatch; |
| 49 | +import java.util.concurrent.TimeUnit; |
40 | 50 |
|
41 | 51 | import static de.gesellix.docker.remote.api.testutil.Constants.LABEL_KEY; |
42 | 52 | import static de.gesellix.docker.remote.api.testutil.Constants.LABEL_VALUE; |
|
48 | 58 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
49 | 59 | import static org.junit.jupiter.api.Assertions.assertEquals; |
50 | 60 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 61 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
51 | 62 | import static org.junit.jupiter.api.Assertions.assertTrue; |
52 | 63 |
|
53 | 64 | @DockerEngineAvailable |
54 | 65 | class ImageApiIntegrationTest { |
55 | 66 |
|
| 67 | + private static Logger log = LoggerFactory.getLogger(ImageApiIntegrationTest.class); |
| 68 | + |
56 | 69 | @InjectDockerClient |
57 | 70 | private EngineApiClient engineApiClient; |
58 | 71 |
|
@@ -81,10 +94,43 @@ public void imageBuildAndPrune() throws IOException { |
81 | 94 | File inputDirectory = ResourceReader.getClasspathResourceAsFile(dockerfile, ImageApi.class).getParentFile(); |
82 | 95 | InputStream buildContext = newBuildContext(inputDirectory); |
83 | 96 |
|
| 97 | + List<BuildInfo> infos = new ArrayList<>(); |
| 98 | + Duration timeout = Duration.of(1, ChronoUnit.MINUTES); |
| 99 | + CountDownLatch latch = new CountDownLatch(1); |
| 100 | + StreamCallback<BuildInfo> callback = new StreamCallback<BuildInfo>() { |
| 101 | + @Override |
| 102 | + public void onNext(BuildInfo element) { |
| 103 | + log.info(element.toString()); |
| 104 | + infos.add(element); |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public void onFailed(Exception e) { |
| 109 | + log.error("Build failed", e); |
| 110 | + latch.countDown(); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public void onFinished() { |
| 115 | + latch.countDown(); |
| 116 | + } |
| 117 | + }; |
84 | 118 | assertDoesNotThrow(() -> imageApi.imageBuild(Paths.get(dockerfile).getFileName().toString(), "test:build", null, null, null, null, null, null, |
85 | 119 | null, null, null, null, null, null, null, |
86 | 120 | null, null, null, null, null, null, null, |
87 | | - null, null, null, null, buildContext)); |
| 121 | + null, null, null, null, buildContext, |
| 122 | + callback, timeout.toMillis())); |
| 123 | + try { |
| 124 | + latch.await(2, TimeUnit.MINUTES); |
| 125 | + } |
| 126 | + catch (InterruptedException e) { |
| 127 | + log.error("Wait interrupted", e); |
| 128 | + } |
| 129 | + |
| 130 | + ImageID imageId = imageApi.getImageId(infos); |
| 131 | + assertNotNull(imageId); |
| 132 | + assertNotNull(imageId.getID()); |
| 133 | + assertTrue(imageId.getID().matches(".+")); |
88 | 134 |
|
89 | 135 | Map<String, List<String>> filter = new HashMap<>(); |
90 | 136 | filter.put("label", singletonList(LABEL_KEY)); |
|
0 commit comments