aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/lib/buildeventstream/LocalFilesArtifactUploaderTest.java56
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderTest.java16
3 files changed, 73 insertions, 0 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 46f5bbbef2..d001bbf85a 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/build/lib/vfs/inmemoryfs",
"//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
"//third_party:junit4",
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/LocalFilesArtifactUploaderTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/LocalFilesArtifactUploaderTest.java
new file mode 100644
index 0000000000..5d51abe9a5
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/LocalFilesArtifactUploaderTest.java
@@ -0,0 +1,56 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.buildeventstream;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile;
+import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType;
+import com.google.devtools.build.lib.vfs.FileSystem;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
+import java.nio.charset.StandardCharsets;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link LocalFilesArtifactUploader} */
+@RunWith(JUnit4.class)
+public class LocalFilesArtifactUploaderTest {
+ private final FileSystem fileSystem = new InMemoryFileSystem();
+ private final LocalFilesArtifactUploader artifactUploader = new LocalFilesArtifactUploader();
+
+ @Test
+ public void testUploadFiles() throws Exception {
+ Path file = fileSystem.getPath("/test");
+ FileSystemUtils.writeContent(file, StandardCharsets.UTF_8, "foo");
+ ListenableFuture<PathConverter> future =
+ artifactUploader.upload(ImmutableMap.of(file, new LocalFile(file, LocalFileType.OUTPUT)));
+ PathConverter pathConverter = future.get();
+ assertThat(pathConverter.apply(file)).isEqualTo("file:///test");
+ }
+
+ @Test
+ public void testUploadDirectoryDoesNotCrash() throws Exception {
+ Path dir = fileSystem.getPath("/test");
+ dir.createDirectoryAndParents();
+ ListenableFuture<PathConverter> future =
+ artifactUploader.upload(ImmutableMap.of(dir, new LocalFile(dir, LocalFileType.OUTPUT)));
+ PathConverter pathConverter = future.get();
+ assertThat(pathConverter.apply(dir)).isNull();
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderTest.java
index 75b46c461e..f45e3bca96 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderTest.java
@@ -15,6 +15,7 @@ package com.google.devtools.build.lib.remote;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import com.google.bytestream.ByteStreamProto.WriteRequest;
import com.google.bytestream.ByteStreamProto.WriteResponse;
@@ -162,6 +163,21 @@ public class ByteStreamBuildEventArtifactUploaderTest {
}
@Test
+ public void testUploadDirectoryDoesNotCrash() throws Exception {
+ Path dir = fs.getPath("/dir");
+ dir.createDirectoryAndParents();
+ Map<Path, LocalFile> filesToUpload = new HashMap<>();
+ filesToUpload.put(dir, new LocalFile(dir, LocalFileType.OUTPUT));
+ ByteStreamUploader uploader = mock(ByteStreamUploader.class);
+ ByteStreamBuildEventArtifactUploader artifactUploader =
+ new ByteStreamBuildEventArtifactUploader(
+ uploader, "localhost", withEmptyMetadata, "instance");
+ PathConverter pathConverter = artifactUploader.upload(filesToUpload).get();
+ assertThat(pathConverter.apply(dir)).isNull();
+ artifactUploader.shutdown();
+ }
+
+ @Test
public void someUploadsFail() throws Exception {
// Test that if one of multiple file uploads fails, the upload future fails and that the
// error is propagated correctly.