Search in sources :

Example 1 with FileHashEntryMatcher

use of com.facebook.buck.testutil.FileHashEntryMatcher in project buck by facebook.

the class RecordingFileHashLoaderTest method testRecordsDirectoryAndRecursivelyRecordsChildren.

@Test
public void testRecordsDirectoryAndRecursivelyRecordsChildren() throws IOException {
    // Scenario:
    // /a - folder
    // /a/b - folder
    // /a/b/c - file
    // /a/b/d - folder
    // /a/e - file
    // => entries for all files and folders.
    // => entries for dirs /a and /a/b list their direct children
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    ProjectFilesystem fs = new ProjectFilesystem(projectDir.getRoot().toPath());
    Path pathDirA = Files.createDirectories(fs.getRootPath().resolve("a"));
    Files.createDirectories(fs.getRootPath().resolve("a/b"));
    Files.createFile(fs.getRootPath().resolve("a/b/c"));
    Files.createDirectories(fs.getRootPath().resolve("a/b/d"));
    Files.createFile(fs.getRootPath().resolve("a/e"));
    RecordedFileHashes recordedFileHashes = new RecordedFileHashes(0);
    BuildJobStateFileHashes fileHashes = recordedFileHashes.getRemoteFileHashes();
    ProjectFileHashCache delegateCacheMock = EasyMock.createMock(ProjectFileHashCache.class);
    expect(delegateCacheMock.getFilesystem()).andReturn(fs);
    expect(delegateCacheMock.get(anyObject(Path.class))).andReturn(EXAMPLE_HASHCODE).anyTimes();
    replay(delegateCacheMock);
    RecordingProjectFileHashCache recordingLoader = RecordingProjectFileHashCache.createForCellRoot(delegateCacheMock, recordedFileHashes, new DistBuildConfig(FakeBuckConfig.builder().build()));
    recordingLoader.get(fs.relativize(pathDirA));
    assertThat(fileHashes.getEntries().size(), // all folders and files
    Matchers.equalTo(5));
    assertThat(fileHashes.getEntries(), IsCollectionContaining.hasItems(new FileHashEntryMatcher("a", true), new FileHashEntryMatcher("a/b", true), new FileHashEntryMatcher("a/b/c", false), new FileHashEntryMatcher("a/b/d", true), new FileHashEntryMatcher("a/e", false)));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) FakeProjectFileHashCache(com.facebook.buck.testutil.FakeProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FileHashEntryMatcher(com.facebook.buck.testutil.FileHashEntryMatcher) Test(org.junit.Test)

Aggregations

BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)1 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 FakeProjectFileHashCache (com.facebook.buck.testutil.FakeProjectFileHashCache)1 FileHashEntryMatcher (com.facebook.buck.testutil.FileHashEntryMatcher)1 ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1