Java Code Examples for org.testcontainers.utility.MountableFile#forHostPath()
The following examples show how to use
org.testcontainers.utility.MountableFile#forHostPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReusabilityUnitTests.java From testcontainers-java with MIT License | 6 votes |
@Test public void changesInFolder() throws Exception { Path tempDirectory = Files.createTempDirectory("reusable_test"); MountableFile mountableFile = MountableFile.forHostPath(tempDirectory); assertThat(new File(mountableFile.getResolvedPath())).isDirectory(); container.withCopyFileToContainer(mountableFile, "/foo/bar/"); long hash1 = container.hashCopiedFiles().getValue(); Path fileInFolder = Files.createFile( // Create file in the sub-folder Files.createDirectory(tempDirectory.resolve("sub")).resolve("test.txt") ); assertThat(fileInFolder).exists(); Files.write(fileInFolder, UUID.randomUUID().toString().getBytes()); assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1); }
Example 2
Source File: ReusabilityUnitTests.java From testcontainers-java with MIT License | 6 votes |
@Test public void folderAndFile() throws Exception { Path tempDirectory = Files.createTempDirectory("reusable_test"); MountableFile mountableFile = MountableFile.forHostPath(tempDirectory); assertThat(new File(mountableFile.getResolvedPath())).isDirectory(); container.withCopyFileToContainer(mountableFile, "/foo/bar/"); long hash1 = container.hashCopiedFiles().getValue(); container.withCopyFileToContainer( MountableFile.forClasspathResource("test_copy_to_container.txt"), "/foo/baz" ); assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1); }
Example 3
Source File: ReusabilityUnitTests.java From testcontainers-java with MIT License | 6 votes |
@Test public void folderPermissions() throws Exception { Path tempDirectory = Files.createTempDirectory("reusable_test"); MountableFile mountableFile = MountableFile.forHostPath(tempDirectory); assertThat(new File(mountableFile.getResolvedPath())).isDirectory(); Path subDir = Files.createDirectory(tempDirectory.resolve("sub")); subDir.toFile().setWritable(false); assumeThat(subDir.toFile().canWrite()).isFalse(); container.withCopyFileToContainer(mountableFile, "/foo/bar/"); long hash1 = container.hashCopiedFiles().getValue(); subDir.toFile().setWritable(true); assumeThat(subDir.toFile()).canWrite(); assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1); }
Example 4
Source File: GenericContainer.java From testcontainers-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) { final MountableFile mountableFile = MountableFile.forHostPath(hostPath); binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext)); }
Example 5
Source File: ReusabilityUnitTests.java From testcontainers-java with MIT License | 5 votes |
@Test public void detectsChangesInFile() throws Exception { Path path = File.createTempFile("reusable_test", ".txt").toPath(); MountableFile mountableFile = MountableFile.forHostPath(path); container.withCopyFileToContainer(mountableFile, "/foo/bar"); long hash1 = container.hashCopiedFiles().getValue(); Files.write(path, UUID.randomUUID().toString().getBytes()); assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1); }
Example 6
Source File: ReusabilityUnitTests.java From testcontainers-java with MIT License | 5 votes |
@Test public void folder() throws Exception { long emptyHash = container.hashCopiedFiles().getValue(); Path tempDirectory = Files.createTempDirectory("reusable_test"); MountableFile mountableFile = MountableFile.forHostPath(tempDirectory); container.withCopyFileToContainer(mountableFile, "/foo/bar/"); assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(emptyHash); }
Example 7
Source File: ReusabilityUnitTests.java From testcontainers-java with MIT License | 5 votes |
@Test public void filePermissions() throws Exception { Path path = File.createTempFile("reusable_test", ".txt").toPath(); path.toFile().setExecutable(false); MountableFile mountableFile = MountableFile.forHostPath(path); container.withCopyFileToContainer(mountableFile, "/foo/bar"); long hash1 = container.hashCopiedFiles().getValue(); assumeThat(path.toFile().canExecute()).isFalse(); path.toFile().setExecutable(true); assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1); }
Example 8
Source File: FilesTrait.java From testcontainers-java with MIT License | 2 votes |
/** * Adds file with given mode to tarball copied into container. * @param path in tarball * @param filePath in host filesystem * @param mode octal value of posix file mode (000..777) * @return self */ default SELF withFileFromPath(String path, Path filePath, Integer mode) { final MountableFile mountableFile = MountableFile.forHostPath(filePath, mode); return ((SELF) this).withFileFromTransferable(path, mountableFile); }