Adjust .DS_Store test assertions on Windows

Windows handles trying to read a file that does not exist because a
component of the path is not a directory differently than other OS
handle this situation. This commit adjusts these assertions for Windows.
This commit is contained in:
Jason Tedor 2017-10-25 22:36:53 -04:00
parent 17d6820a4b
commit 77f87732ef
2 changed files with 13 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import org.elasticsearch.test.ESTestCase;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystemException; import java.nio.file.FileSystemException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -145,9 +146,13 @@ public class PluginsServiceTests extends ESTestCase {
assertThat(e, hasToString(containsString("Could not load plugin descriptor for existing plugin [.DS_Store]"))); assertThat(e, hasToString(containsString("Could not load plugin descriptor for existing plugin [.DS_Store]")));
assertNotNull(e.getCause()); assertNotNull(e.getCause());
assertThat(e.getCause(), instanceOf(FileSystemException.class)); assertThat(e.getCause(), instanceOf(FileSystemException.class));
if (Constants.WINDOWS) {
assertThat(e.getCause(), instanceOf(NoSuchFileException.class));
} else {
assertThat(e.getCause(), hasToString(containsString("Not a directory"))); assertThat(e.getCause(), hasToString(containsString("Not a directory")));
} }
} }
}
public void testStartupWithRemovingMarker() throws IOException { public void testStartupWithRemovingMarker() throws IOException {
final Path home = createTempDir(); final Path home = createTempDir();

View File

@ -33,6 +33,7 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystemException; import java.nio.file.FileSystemException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
@ -45,6 +46,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.instanceOf;
/** /**
* Create a simple "daemon controller", put it in the right place and check that it runs. * Create a simple "daemon controller", put it in the right place and check that it runs.
@ -211,9 +213,13 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
// we do not ignore these files on non-macOS systems // we do not ignore these files on non-macOS systems
final FileSystemException e = final FileSystemException e =
expectThrows(FileSystemException.class, () -> spawner.spawnNativePluginControllers(environment)); expectThrows(FileSystemException.class, () -> spawner.spawnNativePluginControllers(environment));
if (Constants.WINDOWS) {
assertThat(e, instanceOf(NoSuchFileException.class));
} else {
assertThat(e, hasToString(containsString("Not a directory"))); assertThat(e, hasToString(containsString("Not a directory")));
} }
} }
}
private void createControllerProgram(final Path outputFile) throws IOException { private void createControllerProgram(final Path outputFile) throws IOException {
final Path outputDir = outputFile.getParent(); final Path outputDir = outputFile.getParent();