|
| 1 | +package fr.frogdevelopment.docker; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import java.io.IOException; |
| 6 | +import java.nio.file.Files; |
| 7 | +import java.nio.file.Paths; |
| 8 | +import org.junit.jupiter.api.BeforeAll; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.boot.test.context.SpringBootTest; |
| 12 | +import org.springframework.core.env.Environment; |
| 13 | +import org.springframework.test.context.ActiveProfiles; |
| 14 | + |
| 15 | +@ActiveProfiles("test") |
| 16 | +@SpringBootTest(classes = DockerSecretProcessor.class) |
| 17 | +public class DockerSecretProcessorTest { |
| 18 | + |
| 19 | + @Autowired |
| 20 | + private Environment environment; |
| 21 | + |
| 22 | + @BeforeAll |
| 23 | + static void createSecrets() throws IOException { |
| 24 | + var secretsPath = Paths.get(System.getProperty("java.io.tmpdir"), "secrets"); |
| 25 | + if (Files.exists(secretsPath)) { |
| 26 | + Files.list(secretsPath).forEach(p -> { |
| 27 | + try { |
| 28 | + Files.delete(p); |
| 29 | + } catch (IOException e) { |
| 30 | + e.printStackTrace(); |
| 31 | + } |
| 32 | + }); |
| 33 | + Files.delete(secretsPath); |
| 34 | + } |
| 35 | + |
| 36 | + Files.createDirectory(secretsPath); |
| 37 | + var absolutePath = secretsPath.toFile().getAbsolutePath(); |
| 38 | + System.out.println(absolutePath); |
| 39 | + |
| 40 | + var myTest = Files.createFile(Paths.get(absolutePath, "my-test")); |
| 41 | + Files.writeString(myTest, "my value"); |
| 42 | + |
| 43 | + var otherTest = Files.createFile(Paths.get(absolutePath, "other_test")); |
| 44 | + Files.writeString(otherTest, "other_value"); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void contextLoads() { |
| 49 | + |
| 50 | + assertThat(environment.containsProperty("docker-secrets.my-test")).isTrue(); |
| 51 | + assertThat(environment.getProperty("docker-secrets.my-test")).isEqualTo("my value"); |
| 52 | + |
| 53 | + assertThat(environment.containsProperty("docker-secrets.other_test")).isTrue(); |
| 54 | + assertThat(environment.getProperty("docker-secrets.other_test")).isEqualTo("other_value"); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments