Move tests off of the obsolete parseFilesetManifest method. RELNOTES: None. PiperOrigin-RevId: 216555805
diff --git a/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java b/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java index 5b59a16..b2f3384 100644 --- a/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java +++ b/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java
@@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ActionInputHelper; import com.google.devtools.build.lib.actions.Artifact; @@ -48,12 +47,10 @@ import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -66,26 +63,13 @@ private static final ArtifactExpander NO_ARTIFACT_EXPANDER = (a, b) -> fail("expected no interactions"); - private FileSystem fs; - private Path execRoot; - private ArtifactRoot rootDir; - private SpawnInputExpander expander; - private Map<PathFragment, ActionInput> inputMappings; + private final FileSystem fs = new InMemoryFileSystem(); + private final Path execRoot = fs.getPath("/root"); + private final ArtifactRoot rootDir = + ArtifactRoot.asDerivedRoot(execRoot, fs.getPath("/root/out")); - @Before - public final void createSpawnInputExpander() { - fs = new InMemoryFileSystem(); - execRoot = fs.getPath("/root"); - rootDir = ArtifactRoot.asDerivedRoot(execRoot, fs.getPath("/root/out")); - expander = new SpawnInputExpander(execRoot, /*strict=*/ true); - inputMappings = Maps.newHashMap(); - } - - private void scratchFile(String file, String... lines) throws Exception { - Path path = fs.getPath(file); - path.getParentDirectory().createDirectoryAndParents(); - FileSystemUtils.writeLinesAs(path, StandardCharsets.UTF_8, lines); - } + private SpawnInputExpander expander = new SpawnInputExpander(execRoot, /*strict=*/ true); + private Map<PathFragment, ActionInput> inputMappings = new HashMap<>(); @Test public void testEmptyRunfiles() throws Exception { @@ -329,63 +313,52 @@ @Test public void testEmptyManifest() throws Exception { - // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST". - scratchFile("/root/out/_foo/MANIFEST"); + Map<Artifact, ImmutableList<FilesetOutputSymlink>> filesetMappings = + ImmutableMap.of(createFileset("out"), ImmutableList.of()); - ArtifactRoot outputRoot = - ArtifactRoot.asDerivedRoot(fs.getPath("/root"), fs.getPath("/root/out")); - Artifact artifact = new Artifact(fs.getPath("/root/out/foo"), outputRoot); - expander.parseFilesetManifest(inputMappings, artifact, "workspace"); + expander.addFilesetManifests(filesetMappings, inputMappings); + assertThat(inputMappings).isEmpty(); } @Test public void testManifestWithSingleFile() throws Exception { - // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST". - scratchFile("/root/out/_foo/MANIFEST", "workspace/bar /dir/file", "<some digest>"); + Map<Artifact, ImmutableList<FilesetOutputSymlink>> filesetMappings = + ImmutableMap.of( + createFileset("out"), ImmutableList.of(filesetSymlink("foo/bar", "/dir/file"))); - ArtifactRoot outputRoot = - ArtifactRoot.asDerivedRoot(fs.getPath("/root"), fs.getPath("/root/out")); - Artifact artifact = new Artifact(fs.getPath("/root/out/foo"), outputRoot); - expander.parseFilesetManifest(inputMappings, artifact, "workspace"); - assertThat(inputMappings).hasSize(1); + expander.addFilesetManifests(filesetMappings, inputMappings); + assertThat(inputMappings) - .containsEntry(PathFragment.create("out/foo/bar"), ActionInputHelper.fromPath("/dir/file")); + .containsExactly( + PathFragment.create("out/foo/bar"), ActionInputHelper.fromPath("/dir/file")); } @Test public void testManifestWithTwoFiles() throws Exception { - // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST". - scratchFile( - "/root/out/_foo/MANIFEST", - "workspace/bar /dir/file", - "<some digest>", - "workspace/baz /dir/file", - "<some digest>"); + Map<Artifact, ImmutableList<FilesetOutputSymlink>> filesetMappings = + ImmutableMap.of( + createFileset("out"), + ImmutableList.of( + filesetSymlink("foo/bar", "/dir/file"), filesetSymlink("foo/baz", "/dir/file"))); - ArtifactRoot outputRoot = - ArtifactRoot.asDerivedRoot(fs.getPath("/root"), fs.getPath("/root/out")); - Artifact artifact = new Artifact(fs.getPath("/root/out/foo"), outputRoot); - expander.parseFilesetManifest(inputMappings, artifact, "workspace"); - assertThat(inputMappings).hasSize(2); + expander.addFilesetManifests(filesetMappings, inputMappings); + assertThat(inputMappings) - .containsEntry(PathFragment.create("out/foo/bar"), ActionInputHelper.fromPath("/dir/file")); - assertThat(inputMappings) - .containsEntry(PathFragment.create("out/foo/baz"), ActionInputHelper.fromPath("/dir/file")); + .containsExactly( + PathFragment.create("out/foo/bar"), ActionInputHelper.fromPath("/dir/file"), + PathFragment.create("out/foo/baz"), ActionInputHelper.fromPath("/dir/file")); } @Test public void testManifestWithDirectory() throws Exception { - // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST". - scratchFile("/root/out/_foo/MANIFEST", "workspace/bar /some", "<some digest>"); + Map<Artifact, ImmutableList<FilesetOutputSymlink>> filesetMappings = + ImmutableMap.of(createFileset("out"), ImmutableList.of(filesetSymlink("foo/bar", "/some"))); - ArtifactRoot outputRoot = - ArtifactRoot.asDerivedRoot(fs.getPath("/root"), fs.getPath("/root/out")); - Artifact artifact = new Artifact(fs.getPath("/root/out/foo"), outputRoot); - expander.parseFilesetManifest(inputMappings, artifact, "workspace"); - assertThat(inputMappings).hasSize(1); + expander.addFilesetManifests(filesetMappings, inputMappings); + assertThat(inputMappings) - .containsEntry(PathFragment.create("out/foo/bar"), ActionInputHelper.fromPath("/some")); + .containsExactly(PathFragment.create("out/foo/bar"), ActionInputHelper.fromPath("/some")); } private static FilesetOutputSymlink filesetSymlink(String from, String to) { @@ -412,7 +385,7 @@ public void testManifestWithErrorOnRelativeSymlink() throws Exception { expander = new SpawnInputExpander(execRoot, /*strict=*/ true, ERROR); try { - expander.addFilesetManifests(simpleFilesetManifest(), new HashMap<>()); + expander.addFilesetManifests(simpleFilesetManifest(), inputMappings); fail(); } catch (IOException e) { assertThat(e).hasMessageThat().contains("runfiles target is not absolute: foo"); @@ -422,9 +395,8 @@ @Test public void testManifestWithIgnoredRelativeSymlink() throws Exception { expander = new SpawnInputExpander(execRoot, /*strict=*/ true, IGNORE); - Map<PathFragment, ActionInput> entries = new HashMap<>(); - expander.addFilesetManifests(simpleFilesetManifest(), entries); - assertThat(entries) + expander.addFilesetManifests(simpleFilesetManifest(), inputMappings); + assertThat(inputMappings) .containsExactly( PathFragment.create("out/workspace/foo"), ActionInputHelper.fromPath("/root/bar")); } @@ -432,9 +404,8 @@ @Test public void testManifestWithResolvedRelativeSymlink() throws Exception { expander = new SpawnInputExpander(execRoot, /*strict=*/ true, RESOLVE); - Map<PathFragment, ActionInput> entries = new HashMap<>(); - expander.addFilesetManifests(simpleFilesetManifest(), entries); - assertThat(entries) + expander.addFilesetManifests(simpleFilesetManifest(), inputMappings); + assertThat(inputMappings) .containsExactly( PathFragment.create("out/workspace/bar"), ActionInputHelper.fromPath("/root/bar"), PathFragment.create("out/workspace/foo"), ActionInputHelper.fromPath("/root/bar"));