aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/buildeventstream/transports
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-07-11 10:55:10 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-11 10:57:11 -0700
commite0a68ab35294b0acff1226d74744957780967ae4 (patch)
tree75ace4ba8b4a03db2d0a216b2dd4898f1a099a83 /src/test/java/com/google/devtools/build/lib/buildeventstream/transports
parentf4a3dd9b8124dc7b2795f89e6700881b66371e4f (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/devtools/build/lib/buildeventstream/transports')
-rw-r--r--src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java42
1 files changed, 15 insertions, 27 deletions
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();
}