aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar buchgr <buchgr@google.com>2018-03-13 07:55:05 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-13 07:57:22 -0700
commit9df3b45a739d7d7181b8d1fdeccc7c2276138f48 (patch)
treedcaecace7cb493db66d8f7a578ed6de33d186128 /src/test/java
parent0f3f788e37e9e9892f7f1f929eca92f4d9a0d07d (diff)
Remove assumption from test that /a and /b don't exist.
The updated test cases in the InMemoryFileSystemTest make the assumption that /a and /b are not prefixes of the InMemoryFilesystemTest.workingDir field. This is not safe and thus use a randomly generated directory name instead of a hardcoded one. PiperOrigin-RevId: 188872604
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java
index 2ebe0a5dd3..30f4064b60 100644
--- a/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java
+++ b/src/test/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystemTest.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.vfs.inmemoryfs;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.clock.BlazeClock;
@@ -28,6 +29,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Collection;
+import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -384,25 +386,34 @@ public class InMemoryFileSystemTest extends SymlinkAwareFileSystemTest {
@Test
public void testEloop() throws Exception {
- Path a = testFS.getPath("/a");
- Path b = testFS.getPath("/b");
- a.createSymbolicLink(PathFragment.create("b"));
- b.createSymbolicLink(PathFragment.create("a"));
+ // The test assumes that aName and bName is not a prefix of the workingDir.
+ String aName = "/" + UUID.randomUUID();
+ String bName = "/" + UUID.randomUUID();
+
+ Path a = testFS.getPath(aName);
+ Path b = testFS.getPath(bName);
+ a.createSymbolicLink(PathFragment.create(bName));
+ b.createSymbolicLink(PathFragment.create(aName));
try {
a.stat();
+ fail("Expected IOException");
} catch (IOException e) {
- assertThat(e).hasMessage("/a (Too many levels of symbolic links)");
+ assertThat(e).hasMessage(aName + " (Too many levels of symbolic links)");
}
}
@Test
public void testEloopSelf() throws Exception {
- Path a = testFS.getPath("/a");
- a.createSymbolicLink(PathFragment.create("a"));
+ // The test assumes that aName is not a prefix of the workingDir.
+ String aName = "/" + UUID.randomUUID();
+
+ Path a = testFS.getPath(aName);
+ a.createSymbolicLink(PathFragment.create(aName));
try {
a.stat();
+ fail("Expected IOException");
} catch (IOException e) {
- assertThat(e).hasMessage("/a (Too many levels of symbolic links)");
+ assertThat(e).hasMessage(aName + " (Too many levels of symbolic links)");
}
}
}