|
21 | 21 | import java.io.ByteArrayInputStream; |
22 | 22 | import java.io.ByteArrayOutputStream; |
23 | 23 | import java.io.IOException; |
| 24 | +import java.io.InputStream; |
| 25 | +import java.io.OutputStream; |
24 | 26 | import java.nio.charset.StandardCharsets; |
25 | 27 | import java.nio.file.Paths; |
26 | 28 | import org.junit.Assert; |
@@ -85,7 +87,65 @@ public void testLoad() throws IOException, InterruptedException { |
85 | 87 | } |
86 | 88 |
|
87 | 89 | @Test |
88 | | - public void testLoad_fail() throws InterruptedException { |
| 90 | + public void testLoad_stdinFail() throws InterruptedException { |
| 91 | + DockerClient testDockerClient = new DockerClient(ignored -> mockProcessBuilder); |
| 92 | + |
| 93 | + Mockito.when(mockProcess.getOutputStream()) |
| 94 | + .thenReturn( |
| 95 | + new OutputStream() { |
| 96 | + |
| 97 | + @Override |
| 98 | + public void write(int b) throws IOException { |
| 99 | + throw new IOException(); |
| 100 | + } |
| 101 | + }); |
| 102 | + Mockito.when(mockProcess.getErrorStream()) |
| 103 | + .thenReturn(new ByteArrayInputStream("error".getBytes(StandardCharsets.UTF_8))); |
| 104 | + |
| 105 | + try { |
| 106 | + testDockerClient.load(Blobs.from("jib")); |
| 107 | + Assert.fail("Write should have failed"); |
| 108 | + |
| 109 | + } catch (IOException ex) { |
| 110 | + Assert.assertEquals("'docker load' command failed with error: error", ex.getMessage()); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void testLoad_stdinFail_stderrFail() throws InterruptedException { |
| 116 | + DockerClient testDockerClient = new DockerClient(ignored -> mockProcessBuilder); |
| 117 | + IOException expectedIOException = new IOException(); |
| 118 | + |
| 119 | + Mockito.when(mockProcess.getOutputStream()) |
| 120 | + .thenReturn( |
| 121 | + new OutputStream() { |
| 122 | + |
| 123 | + @Override |
| 124 | + public void write(int b) throws IOException { |
| 125 | + throw expectedIOException; |
| 126 | + } |
| 127 | + }); |
| 128 | + Mockito.when(mockProcess.getErrorStream()) |
| 129 | + .thenReturn( |
| 130 | + new InputStream() { |
| 131 | + |
| 132 | + @Override |
| 133 | + public int read() throws IOException { |
| 134 | + throw new IOException(); |
| 135 | + } |
| 136 | + }); |
| 137 | + |
| 138 | + try { |
| 139 | + testDockerClient.load(Blobs.from("jib")); |
| 140 | + Assert.fail("Write should have failed"); |
| 141 | + |
| 142 | + } catch (IOException ex) { |
| 143 | + Assert.assertTrue(expectedIOException == ex); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + public void testLoad_stdoutFail() throws InterruptedException { |
89 | 149 | DockerClient testDockerClient = new DockerClient(ignored -> mockProcessBuilder); |
90 | 150 | Mockito.when(mockProcess.waitFor()).thenReturn(1); |
91 | 151 |
|
|
0 commit comments