How to use MountableFileTest class of org.testcontainers.utility package

Best Testcontainers-java code snippet using org.testcontainers.utility.MountableFileTest

Source:MountableFileTest.java Github

copy

Full Screen

...5import org.apache.commons.compress.archivers.ArchiveEntry;6import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;7import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;8import org.junit.Test;9public class MountableFileTest {10 private static final int TEST_FILE_MODE = 346;11 private static final int BASE_FILE_MODE = 32768;12 private static final int BASE_DIR_MODE = 16384;13 @Test14 public void forClasspathResource() throws Exception {15 final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt");16 performChecks(mountableFile);17 }18 @Test19 public void forClasspathResourceWithAbsolutePath() throws Exception {20 final MountableFile mountableFile = MountableFile.forClasspathResource("/mappable-resource/test-resource.txt");21 performChecks(mountableFile);22 }23 @Test24 public void forClasspathResourceFromJar() throws Exception {25 final MountableFile mountableFile = MountableFile.forClasspathResource("META-INF/dummy_unique_name.txt");26 performChecks(mountableFile);27 }28 @Test29 public void forClasspathResourceFromJarWithAbsolutePath() throws Exception {30 final MountableFile mountableFile = MountableFile.forClasspathResource("/META-INF/dummy_unique_name.txt");31 performChecks(mountableFile);32 }33 @Test34 public void forHostPath() throws Exception {35 final Path file = createTempFile("somepath");36 final MountableFile mountableFile = MountableFile.forHostPath(file.toString());37 performChecks(mountableFile);38 }39 @Test40 public void forHostPathWithSpaces() throws Exception {41 final Path file = createTempFile("some path");42 final MountableFile mountableFile = MountableFile.forHostPath(file.toString());43 performChecks(mountableFile);44 assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains(" "));45 assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains("\\ "));46 }47 @Test48 public void forHostPathWithPlus() throws Exception {49 final Path file = createTempFile("some+path");50 final MountableFile mountableFile = MountableFile.forHostPath(file.toString());51 performChecks(mountableFile);52 assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains("+"));53 assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains(" "));54 }55 @Test56 public void forClasspathResourceWithPermission() throws Exception {57 final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt", MountableFileTest.TEST_FILE_MODE);58 performChecks(mountableFile);59 assertEquals("Valid file mode.", ((MountableFileTest.BASE_FILE_MODE) | (MountableFileTest.TEST_FILE_MODE)), mountableFile.getFileMode());60 }61 @Test62 public void forHostFilePathWithPermission() throws Exception {63 final Path file = createTempFile("somepath");64 final MountableFile mountableFile = MountableFile.forHostPath(file.toString(), MountableFileTest.TEST_FILE_MODE);65 performChecks(mountableFile);66 assertEquals("Valid file mode.", ((MountableFileTest.BASE_FILE_MODE) | (MountableFileTest.TEST_FILE_MODE)), mountableFile.getFileMode());67 }68 @Test69 public void forHostDirPathWithPermission() throws Exception {70 final Path dir = createTempDir();71 final MountableFile mountableFile = MountableFile.forHostPath(dir.toString(), MountableFileTest.TEST_FILE_MODE);72 performChecks(mountableFile);73 assertEquals("Valid dir mode.", ((MountableFileTest.BASE_DIR_MODE) | (MountableFileTest.TEST_FILE_MODE)), mountableFile.getFileMode());74 }75 @Test76 public void noTrailingSlashesInTarEntryNames() throws Exception {77 final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt");78 @Cleanup79 final TarArchiveInputStream tais = intoTarArchive(( taos) -> {80 mountableFile.transferTo(taos, "/some/path.txt");81 mountableFile.transferTo(taos, "/path.txt");82 mountableFile.transferTo(taos, "path.txt");83 });84 ArchiveEntry entry;85 while ((entry = tais.getNextEntry()) != null) {86 assertFalse("no entries should have a trailing slash", entry.getName().endsWith("/"));87 } ...

Full Screen

Full Screen

MountableFileTest

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.GenericContainer;2import org.testcontainers.containers.output.OutputFrame;3import org.testcontainers.containers.output.ToStringConsumer;4import org.testcontainers.containers.wait.strategy.Wait;5import org.testcontainers.utility.MountableFileTest;6import java.io.IOException;7import java.nio.file.Files;8import java.nio.file.Path;9import java.nio.file.Paths;10import java.util.stream.Stream;11public class DockerTest {12 public static void main(String[] args) throws IOException, InterruptedException {13 Path path = Paths.get("E:\\test.txt");14 Files.write(path, "Hello".getBytes());15 MountableFileTest mountableFileTest = new MountableFileTest(path.toFile(), "/home/test.txt");16 GenericContainer container = new GenericContainer("alpine:3.8")17 .withCommand("tail", "-f", "/dev/null")18 .withFileSystemBind(path.toString(), "/home/test.txt")19 .waitingFor(Wait.forLogMessage(".*", 1));20 container.start();21 container.followOutput(new ToStringConsumer() {22 public void accept(OutputFrame frame) {23 super.accept(frame);24 System.out.println("Output is " + frame.getUtf8String());25 }26 });27 Thread.sleep(10000);28 container.stop();29 }30}31import org.testcontainers.containers.GenericContainer;32import org.testcontainers.containers.output.OutputFrame;33import org.testcontainers.containers.output.ToStringConsumer;34import org.testcontainers.utility.MountableFile;35import java.io.IOException;36import java.nio.file.Files;37import java.nio.file.Path;38import java.nio.file.Paths;39import java.util.stream.Stream;40public class DockerTest {41 public static void main(String[] args) throws IOException, InterruptedException {42 Path path = Paths.get("E:\\test.txt");43 Files.write(path, "Hello".getBytes());44 MountableFile mountableFile = MountableFile.forHostPath(path);45 GenericContainer container = new GenericContainer("alpine:3.8")46 .withCommand("tail", "-f", "/dev/null")47 .withFileSystemBind(path.toString(), "/home/test.txt")48 .waitingFor(Wait.forLogMessage(".*", 1));49 container.start();50 container.followOutput(new ToStringConsumer() {

Full Screen

Full Screen

MountableFileTest

Using AI Code Generation

copy

Full Screen

1MountableFileTest mf = new MountableFileTest();2mf.createTempFile();3MountableFile mountableFile = mf.createMountableFile();4try (GenericContainer container = new GenericContainer("alpine:3.9.3")5 .withFileSystemBind(mountableFile.getResolvedPath(), "/tmp/test.txt", BindMode.READ_WRITE)) {6 container.start();7 String result = container.execInContainer("cat", "/tmp/test.txt").getStdout();8 System.out.println(result);9}10mf.deleteTempFile();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful