|
1 | 1 | package org.testcontainers.containers;
|
2 | 2 |
|
| 3 | +import java.lang.reflect.Field; |
3 | 4 | import java.util.List;
|
| 5 | +import java.util.Map; |
4 | 6 |
|
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
5 | 9 | import org.junit.jupiter.api.Test;
|
6 |
| -import static org.junit.Assert.assertEquals; |
7 | 10 |
|
8 | 11 | /**
|
9 | 12 | * @author Alexey Kuzin
|
10 | 13 | * @author Ivan Dneprov
|
11 | 14 | */
|
12 | 15 | class TarantoolContainerTest {
|
13 | 16 |
|
| 17 | + private static final String ENV_TARANTOOL_VERSION = "TARANTOOL_VERSION"; |
| 18 | + |
| 19 | + private void addEnv(String key, String value) throws NoSuchFieldException, IllegalAccessException { |
| 20 | + Class<?> classOfMap = System.getenv().getClass(); |
| 21 | + Field field = classOfMap.getDeclaredField("m"); |
| 22 | + field.setAccessible(true); |
| 23 | + Map<String, String> writeableEnvironmentVariables = (Map<String, String>) field.get(System.getenv()); |
| 24 | + writeableEnvironmentVariables.put(key, value); |
| 25 | + field.setAccessible(false); |
| 26 | + } |
| 27 | + |
| 28 | + private void removeEnv(String key, String value) throws NoSuchFieldException, IllegalAccessException { |
| 29 | + Class<?> classOfMap = System.getenv().getClass(); |
| 30 | + Field field = classOfMap.getDeclaredField("m"); |
| 31 | + field.setAccessible(true); |
| 32 | + Map<String, String> writeableEnvironmentVariables = (Map<String, String>) field.get(System.getenv()); |
| 33 | + writeableEnvironmentVariables.remove(key); |
| 34 | + field.setAccessible(false); |
| 35 | + } |
| 36 | + |
14 | 37 | @Test
|
15 | 38 | public void testExecuteScript() throws Exception {
|
16 | 39 | try (TarantoolContainer container = new TarantoolContainer()) {
|
@@ -47,4 +70,55 @@ public void testContainerWithParameters() throws Exception {
|
47 | 70 | assertEquals(result.get(0), 5);
|
48 | 71 | }
|
49 | 72 | }
|
| 73 | + |
| 74 | + @Test |
| 75 | + public void testContainerWithTrueVersion() throws Exception { |
| 76 | + final String version = "2.11.0"; |
| 77 | + addEnv(ENV_TARANTOOL_VERSION, version); |
| 78 | + |
| 79 | + List<String> result; |
| 80 | + try (TarantoolContainer container = new TarantoolContainer()) { |
| 81 | + container.start(); |
| 82 | + result = container.executeCommandDecoded("return _TARANTOOL"); |
| 83 | + } |
| 84 | + |
| 85 | + removeEnv(ENV_TARANTOOL_VERSION, version); |
| 86 | + assertEquals(1, result.size()); |
| 87 | + assertTrue(result.get(0).startsWith(version)); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testContainerWithDefaultVersionVersion() throws Exception { |
| 92 | + |
| 93 | + List<String> result; |
| 94 | + try (TarantoolContainer container = new TarantoolContainer()) { |
| 95 | + container.start(); |
| 96 | + result = container.executeCommandDecoded("return _TARANTOOL"); |
| 97 | + } |
| 98 | + |
| 99 | + assertEquals(1, result.size()); |
| 100 | + assertTrue(result.get(0).startsWith(TarantoolContainer.DEFAULT_IMAGE_VERSION)); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testContainerWithEmptyVersion() throws Exception { |
| 105 | + final String version = " "; |
| 106 | + addEnv(ENV_TARANTOOL_VERSION, version); |
| 107 | + try (TarantoolContainer container = new TarantoolContainer()) { |
| 108 | + container.start(); |
| 109 | + } |
| 110 | + removeEnv(ENV_TARANTOOL_VERSION, version); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + public void testContainerWithWrongVersion() throws Exception { |
| 115 | + final String version = "wrong_version"; |
| 116 | + addEnv(ENV_TARANTOOL_VERSION, version); |
| 117 | + try (TarantoolContainer container = new TarantoolContainer()) { |
| 118 | + container.start(); |
| 119 | + }catch (Exception exc) { |
| 120 | + assertEquals(ContainerFetchException.class, exc.getClass()); |
| 121 | + } |
| 122 | + removeEnv(ENV_TARANTOOL_VERSION, version); |
| 123 | + } |
50 | 124 | }
|
0 commit comments