diff options
author | 2018-07-11 10:55:10 -0700 | |
---|---|---|
committer | 2018-07-11 10:57:11 -0700 | |
commit | e0a68ab35294b0acff1226d74744957780967ae4 (patch) | |
tree | 75ace4ba8b4a03db2d0a216b2dd4898f1a099a83 /src/test/java/com/google | |
parent | f4a3dd9b8124dc7b2795f89e6700881b66371e4f (diff) |
Pass options to BuildEventArtifactUploaderFactory.
The artifact uploaders may need command-level options.
RELNOTES: None
PiperOrigin-RevId: 204151808
Diffstat (limited to 'src/test/java/com/google')
3 files changed, 23 insertions, 30 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD b/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD index a23d3dd3ff..46f5bbbef2 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD @@ -18,6 +18,7 @@ java_test( deps = [ "//src/main/java/com/google/devtools/build/lib/buildeventstream", "//src/main/java/com/google/devtools/build/lib/vfs", + "//src/main/java/com/google/devtools/common/options", "//third_party:guava", "//third_party:junit4", "//third_party:mockito", diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderFactoryMapTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderFactoryMapTest.java index 8bf867ae6a..39dc16b4b1 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderFactoryMapTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderFactoryMapTest.java @@ -15,10 +15,13 @@ package com.google.devtools.build.lib.buildeventstream; import static com.google.common.truth.Truth.assertThat; +import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.common.options.OptionsParser; +import com.google.devtools.common.options.OptionsProvider; import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -30,11 +33,12 @@ import org.junit.runners.JUnit4; public final class BuildEventArtifactUploaderFactoryMapTest { private BuildEventArtifactUploaderFactoryMap uploaderFactories; private BuildEventArtifactUploaderFactory noConversionUploaderFactory; + private final OptionsParser optionsParser = OptionsParser.newOptionsParser(ImmutableList.of()); @Before public void setUp() { noConversionUploaderFactory = - () -> + (OptionsProvider options) -> new BuildEventArtifactUploader() { @Override public ListenableFuture<PathConverter> upload(Map<Path, LocalFile> files) { @@ -57,13 +61,13 @@ public final class BuildEventArtifactUploaderFactoryMapTest { public void testEmptyUploaders() throws Exception { BuildEventArtifactUploaderFactoryMap emptyUploader = new BuildEventArtifactUploaderFactoryMap.Builder().build(); - assertThat(emptyUploader.select(null).create()) + assertThat(emptyUploader.select(null).create(optionsParser)) .isEqualTo(BuildEventArtifactUploader.LOCAL_FILES_UPLOADER); } @Test public void testAlphabeticalOrder() { - assertThat(uploaderFactories.select(null).create()) + assertThat(uploaderFactories.select(null).create(optionsParser)) .isEqualTo(BuildEventArtifactUploader.LOCAL_FILES_UPLOADER); } diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java index fe5f916206..eab4dca5a3 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java @@ -29,7 +29,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; import com.google.devtools.build.lib.buildeventstream.PathConverter; -import com.google.devtools.common.options.Options; +import com.google.devtools.common.options.OptionsParser; import java.io.File; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -49,26 +49,17 @@ import org.mockito.MockitoAnnotations; @RunWith(JUnit4.class) public class BuildEventTransportFactoryTest { - private static final Function<Object, Class<?>> GET_CLASS = - new Function<Object, Class<?>>() { - @Override - public Class<?> apply(Object o) { - return o.getClass(); - } - }; + private static final Function<Object, Class<?>> GET_CLASS = Object::getClass; private static final BuildEventStreamProtos.BuildEvent BUILD_EVENT_AS_PROTO = BuildEventStreamProtos.BuildEvent.newBuilder() .setStarted(BuildStarted.newBuilder().setCommand("build")) .build(); - private final BuildEventProtocolOptions protocolOpts = - Options.getDefaults(BuildEventProtocolOptions.class); + private OptionsParser optionsParser; @Rule public TemporaryFolder tmp = new TemporaryFolder(); - @Mock public BuildEventStreamOptions options; - @Mock public BuildEvent buildEvent; @Mock public PathConverter pathConverter; @@ -79,6 +70,9 @@ public class BuildEventTransportFactoryTest { MockitoAnnotations.initMocks(this); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())) .thenReturn(BUILD_EVENT_AS_PROTO); + optionsParser = + OptionsParser.newOptionsParser( + BuildEventStreamOptions.class, BuildEventProtocolOptions.class); } @After @@ -93,11 +87,9 @@ public class BuildEventTransportFactoryTest { @Test public void testCreatesTextFormatFileTransport() throws Exception { File textFile = tmp.newFile(); - when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath()); - when(options.getBuildEventBinaryFile()).thenReturn(""); + optionsParser.parse("--build_event_text_file=" + textFile.getAbsolutePath()); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions( - options, protocolOpts, localFilesOnly(), (e) -> {}); + BuildEventTransportFactory.createFromOptions(optionsParser, localFilesOnly(), (e) -> {}); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -107,11 +99,9 @@ public class BuildEventTransportFactoryTest { @Test public void testCreatesBinaryFormatFileTransport() throws Exception { File binaryFile = tmp.newFile(); - when(options.getBuildEventTextFile()).thenReturn(""); - when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); + optionsParser.parse("--build_event_binary_file=" + binaryFile.getAbsolutePath()); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions( - options, protocolOpts, localFilesOnly(), (e) -> {}); + BuildEventTransportFactory.createFromOptions(optionsParser, localFilesOnly(), (e) -> {}); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -122,11 +112,11 @@ public class BuildEventTransportFactoryTest { public void testCreatesAllTransports() throws Exception { File textFile = tmp.newFile(); File binaryFile = tmp.newFile(); - when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath()); - when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); + optionsParser.parse( + "--build_event_text_file=" + textFile.getAbsolutePath(), + "--build_event_binary_file=" + binaryFile.getAbsolutePath()); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions( - options, protocolOpts, localFilesOnly(), (e) -> {}); + BuildEventTransportFactory.createFromOptions(optionsParser, localFilesOnly(), (e) -> {}); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class, BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -136,10 +126,8 @@ public class BuildEventTransportFactoryTest { @Test public void testCreatesNoTransports() throws IOException { - when(options.getBuildEventTextFile()).thenReturn(""); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions( - options, protocolOpts, localFilesOnly(), (e) -> {}); + BuildEventTransportFactory.createFromOptions(optionsParser, localFilesOnly(), (e) -> {}); assertThat(transports).isEmpty(); } |