You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kh...@apache.org on 2018/09/17 17:02:31 UTC
[geode] branch develop updated: GEODE-5741: Modified tests to be
independant of environment (#2483)
This is an automated email from the ASF dual-hosted git repository.
khowe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new c1311bf GEODE-5741: Modified tests to be independant of environment (#2483)
c1311bf is described below
commit c1311bfc70f2a68ac1add9e29a9e0d09de1bd732
Author: Kenneth Howe <kh...@pivotal.io>
AuthorDate: Mon Sep 17 10:02:23 2018 -0700
GEODE-5741: Modified tests to be independant of environment (#2483)
Tests using relative paths had depended on running as a user other root.
The tests expceted that file or directpory creation would fail because the user
would not have permission to write to '/'.
A further problem was the several tests had hardcoded '/' in pathnames,
which is incompatible with running on Windows.
---
.../cli/commands/StartLocatorCommandDUnitTest.java | 46 +++++++++++++++-------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandDUnitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandDUnitTest.java
index c9f22ad..de802e8 100644
--- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandDUnitTest.java
+++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandDUnitTest.java
@@ -33,6 +33,7 @@ import java.net.Socket;
import java.nio.file.Paths;
import java.text.MessageFormat;
+import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -231,28 +232,43 @@ public class StartLocatorCommandDUnitTest {
@Test
public void testInMissingRelativeDirectoryWithoutCreatePermissions() {
// path to a missing dir that cannot be created due to insufficient permissions
- final String missingDirPath = "/missing/path/to/start/in";
- final String expectedMessage = "Could not create directory " + missingDirPath
+ String readOnlyPathname = "readOnlyDir";
+ File readOnlyDir = new File(readOnlyPathname);
+ final String missingDirPath =
+ Paths.get(readOnlyPathname, "missing", "path", "to", "start", "in").toString();
+
+ final String expectedMessage = "Could not create directory .*" + missingDirPath
+ ". Please verify directory path or user permissions.";
final String memberName = "testInMissingRelativeDirectoryWithoutCreatePermissions-locator";
- CommandStringBuilder command = new CommandStringBuilder(START_LOCATOR)
- .addOption(START_LOCATOR__MEMBER_NAME, memberName)
- .addOption(START_LOCATOR__LOCATORS, locatorConnectionString)
- .addOption(START_LOCATOR__DIR, missingDirPath);
+ try {
+ assertThat(readOnlyDir.mkdir()).isTrue();
+ assertThat(readOnlyDir.setReadOnly()).isTrue();
- CommandResult result = gfsh.executeCommand(command.getCommandString());
+ CommandStringBuilder command = new CommandStringBuilder(START_LOCATOR)
+ .addOption(START_LOCATOR__MEMBER_NAME, memberName)
+ .addOption(START_LOCATOR__LOCATORS, locatorConnectionString)
+ .addOption(START_LOCATOR__DIR, missingDirPath);
- assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
- assertThat(result.getMessageFromContent()).contains(expectedMessage);
+ CommandResult result = gfsh.executeCommand(command.getCommandString());
+
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.getMessageFromContent()).containsPattern(expectedMessage);
+ } finally {
+ FileUtils.deleteQuietly(readOnlyDir);
+ }
}
@Test
public void testInMissingRelativeDirectoryThatCanBeCreated() {
// path to a missing dir that can be created
- final String missingDirPath = System.getProperty("user.dir") + "/missing/path/to/start/in";
+ String readWritePathname = "readWriteDir";
+ File readWriteDir = new File(readWritePathname);
+ final String missingDirPath =
+ Paths.get(readWritePathname, "missing", "path", "to", "start", "in").toString();
+
final String memberName = "testInMissingRelativeDirectoryThatCanBeCreated-locator";
- final String expectedMessage = "Locator in " + missingDirPath;
+ final String expectedMessage = "Locator in .*" + missingDirPath;
CommandStringBuilder command = new CommandStringBuilder(START_LOCATOR)
.addOption(START_LOCATOR__MEMBER_NAME, memberName)
@@ -262,11 +278,11 @@ public class StartLocatorCommandDUnitTest {
try {
CommandResult result = gfsh.executeCommand(command.getCommandString());
+
assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
- assertThat(result.getMessageFromContent()).contains(expectedMessage);
+ assertThat(result.getMessageFromContent()).containsPattern(expectedMessage);
} finally {
- File toDelete = new File(missingDirPath);
- deleteLocatorFiles(toDelete);
+ FileUtils.deleteQuietly(readWriteDir);
}
}
@@ -313,7 +329,7 @@ public class StartLocatorCommandDUnitTest {
.doesNotContain("GemFire");
assertThat(result.getMessageFromContent()).containsPattern(expectedVersionPattern);
} finally {
- String pathToFile = System.getProperty("user.dir") + "/" + memberName;
+ String pathToFile = Paths.get(System.getProperty("user.dir"), memberName).toString();
File toDelete = new File(pathToFile);
deleteLocatorFiles(toDelete);
}