use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.
the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileUnderMount.
@Test
public void computeSha1ForOrdinaryFileUnderMount() throws IOException, EdenError, TException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
EdenMount mount = createMock(EdenMount.class);
Path path = fs.getPath("foo/bar");
expect(mount.getBindMounts()).andReturn(ImmutableList.of());
expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path));
expect(mount.getSha1(path)).andReturn(DUMMY_SHA1);
replay(mount);
EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(path));
verify(mount);
}
use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.
the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileUnderMountButBehindBindMount.
@Test
public void computeSha1ForOrdinaryFileUnderMountButBehindBindMount() throws IOException, EdenError, TException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
EdenMount mount = createMock(EdenMount.class);
Path path = fs.getPath("buck-out/gen/some-output");
Files.createDirectories(path.getParent());
Files.createFile(path);
byte[] bytes = new byte[] { 66, 85, 67, 75 };
Files.write(path, bytes);
expect(mount.getBindMounts()).andReturn(ImmutableList.of(fs.getPath("buck-out")));
expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path));
replay(mount);
EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
assertEquals("EdenProjectFilesystemDelegate.computeSha1() should compute the SHA-1 directly via " + "DefaultProjectFilesystemDelegate because the path is behind a bind mount.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(path));
verify(mount);
}
use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.
the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileOutsideMount.
@Test
public void computeSha1ForOrdinaryFileOutsideMount() throws IOException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
Path target = fs.getPath("/example");
Files.createFile(target);
byte[] bytes = new byte[] { 66, 85, 67, 75 };
Files.write(target, bytes);
EdenMount mount = createMock(EdenMount.class);
expect(mount.getBindMounts()).andReturn(ImmutableList.of());
expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.empty());
replay(mount);
EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
assertEquals("EdenProjectFilesystemDelegate.computeSha1() should return the SHA-1 of a file that is " + "outside of the EdenFS root.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(target));
verify(mount);
}
use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.
the class AutoSparseIntegrationTest method testExists.
@Test
public void testExists() {
ProjectFilesystemDelegate delegate = createDelegate();
Assume.assumeTrue(delegate.exists(repoPath.resolve("file1")));
}
use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.
the class AutoSparseIntegrationTest method testMaterialize.
@Test
public void testMaterialize() throws IOException {
ProjectFilesystemDelegate delegate = createDelegate(repoPath, true, ImmutableList.of("subdir"));
// Touch various files, these should be part of the profile
delegate.exists(repoPath.resolve("file1"));
delegate.exists(repoPath.resolve("file2"));
// Only directly include the file, not the parent dir
delegate.exists(repoPath.resolve("subdir/file_in_subdir"));
// Only include the parent directory, not the file
delegate.exists(repoPath.resolve("not_hidden_subdir/file_in_subdir_not_hidden"));
delegate.ensureConcreteFilesExist(BuckEventBusFactory.newInstance(new FakeClock(0)));
List<String> lines = Files.readAllLines(repoPath.resolve(".hg/sparse"), Charset.forName(System.getProperty("file.encoding", "UTF-8")));
List<String> expected = ImmutableList.of("%include sparse_profile", "[include]", "file1", "file2", "not_hidden_subdir", "subdir/file_in_subdir", "[exclude]", // sparse always writes a newline at the end
"");
Assert.assertEquals(expected, lines);
}
Aggregations