|
14 | 14 |
|
15 | 15 | import static org.junit.Assert.*;
|
16 | 16 |
|
| 17 | +import io.kubernetes.client.util.ClientBuilder; |
17 | 18 | import java.io.ByteArrayInputStream;
|
| 19 | +import java.io.IOException; |
18 | 20 | import java.io.InputStream;
|
19 | 21 | import java.nio.charset.StandardCharsets;
|
| 22 | +import org.junit.Before; |
20 | 23 | import org.junit.Test;
|
21 | 24 |
|
22 | 25 | /** Tests for the Exec helper class */
|
23 | 26 | public class ExecTest {
|
| 27 | + |
| 28 | + private static final String OUTPUT_EXIT0 = "{\"metadata\":{},\"status\":\"Success\"}"; |
24 | 29 | private static final String OUTPUT_EXIT1 =
|
25 |
| - "command terminated with non-zero exit code: Error executing in Docker Container: 1"; |
| 30 | + "{\"metadata\":{},\"status\":\"Failure\",\"message\":\"command terminated with non-zero exit code: Error executing in Docker Container: 1\",\"reason\":\"NonZeroExitCode\",\"details\":{\"causes\":[{\"reason\":\"ExitCode\",\"message\":\"1\"}]}}"; |
26 | 31 | private static final String OUTPUT_EXIT126 =
|
27 |
| - "command terminated with non-zero exit code: Error executing in Docker Container: 126"; |
| 32 | + "{\"metadata\":{},\"status\":\"Failure\",\"message\":\"command terminated with non-zero exit code: Error executing in Docker Container: 126\",\"reason\":\"NonZeroExitCode\",\"details\":{\"causes\":[{\"reason\":\"ExitCode\",\"message\":\"126\"}]}}"; |
28 | 33 | private static final String BAD_OUTPUT_INCOMPLETE_MSG1 =
|
29 |
| - "command terminated with non-zero exit code: Error "; |
30 |
| - private static final String BAD_OUTPUT_INCOMPLETE_MSG2 = "command terminated with non-zero"; |
| 34 | + "{\"metadata\":{},\"status\":\"Failure\",\"message\":\"command terminated with non-zero exit code: Error executing in Docker Container: 1\",\"reas"; |
| 35 | + |
| 36 | + private ApiClient client; |
| 37 | + |
| 38 | + @Before |
| 39 | + public void setup() throws IOException { |
| 40 | + client = ClientBuilder.defaultClient(); |
| 41 | + } |
31 | 42 |
|
32 | 43 | @Test
|
33 |
| - public void testExit0() { |
| 44 | + public void testExit0NoMessage() { |
34 | 45 | InputStream inputStream = new ByteArrayInputStream(new byte[0]);
|
35 |
| - int exitCode = Exec.parseExitCode(inputStream); |
| 46 | + int exitCode = Exec.parseExitCode(client, inputStream); |
| 47 | + assertEquals(0, exitCode); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testExit0() { |
| 52 | + InputStream inputStream = |
| 53 | + new ByteArrayInputStream(OUTPUT_EXIT0.getBytes(StandardCharsets.UTF_8)); |
| 54 | + int exitCode = Exec.parseExitCode(client, inputStream); |
36 | 55 | assertEquals(0, exitCode);
|
37 | 56 | }
|
38 | 57 |
|
39 | 58 | @Test
|
40 | 59 | public void testExit1() {
|
41 | 60 | InputStream inputStream =
|
42 | 61 | new ByteArrayInputStream(OUTPUT_EXIT1.getBytes(StandardCharsets.UTF_8));
|
43 |
| - int exitCode = Exec.parseExitCode(inputStream); |
| 62 | + int exitCode = Exec.parseExitCode(client, inputStream); |
44 | 63 | assertEquals(1, exitCode);
|
45 | 64 | }
|
46 | 65 |
|
47 | 66 | @Test
|
48 | 67 | public void testExit126() {
|
49 | 68 | InputStream inputStream =
|
50 | 69 | new ByteArrayInputStream(OUTPUT_EXIT126.getBytes(StandardCharsets.UTF_8));
|
51 |
| - int exitCode = Exec.parseExitCode(inputStream); |
| 70 | + int exitCode = Exec.parseExitCode(client, inputStream); |
52 | 71 | assertEquals(126, exitCode);
|
53 | 72 | }
|
54 | 73 |
|
55 | 74 | @Test
|
56 | 75 | public void testIncompleteData1() {
|
57 | 76 | InputStream inputStream =
|
58 | 77 | new ByteArrayInputStream(BAD_OUTPUT_INCOMPLETE_MSG1.getBytes(StandardCharsets.UTF_8));
|
59 |
| - int exitCode = Exec.parseExitCode(inputStream); |
60 |
| - assertEquals(-1, exitCode); |
61 |
| - } |
62 |
| - |
63 |
| - @Test |
64 |
| - public void testIncompleteData2() { |
65 |
| - InputStream inputStream = |
66 |
| - new ByteArrayInputStream(BAD_OUTPUT_INCOMPLETE_MSG2.getBytes(StandardCharsets.UTF_8)); |
67 |
| - int exitCode = Exec.parseExitCode(inputStream); |
| 78 | + int exitCode = Exec.parseExitCode(client, inputStream); |
68 | 79 | assertEquals(-1, exitCode);
|
69 | 80 | }
|
70 | 81 | }
|
0 commit comments