Skip to content

Commit

Permalink
Fix error message, remove unnecessary catch in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-nl committed May 28, 2024
1 parent 8f1a3d9 commit 701bf67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private String constructLogPattern(String logPathFromConfig) throws SnowflakeSQL
sfSession,
ErrorCode.INTERNAL_ERROR,
String.format(
"Un-able to create log path mentioned in configfile %s ,%s",
"Unable to create log path mentioned in configfile %s ,%s",
logPathFromConfig, ex.getMessage()));
}
}
Expand Down
34 changes: 9 additions & 25 deletions src/test/java/net/snowflake/client/config/SFPermissionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,23 @@ public SFPermissionsTest(Map.Entry<String, Boolean> permission) {
}

@Before
public void createConfigFile() {
try {
Files.write(configFilePath, configJson.getBytes());
} catch (IOException e) {
fail("testLogDirectoryPermissions failed setup");
}
public void createConfigFile() throws IOException {
Files.write(configFilePath, configJson.getBytes());
}

@After
public void cleanupConfigFile() {
try {
Files.deleteIfExists(configFilePath);
} catch (IOException e) {
fail("testLogDirectoryPermissions failed cleanup");
}
public void cleanupConfigFile() throws IOException {
Files.deleteIfExists(configFilePath);
}

@Test
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnWin.class)
public void testLogDirectoryPermissions() {
public void testLogDirectoryPermissions() throws IOException {
// Don't run on Windows
try {
Files.setPosixFilePermissions(configFilePath, PosixFilePermissions.fromString(permission));
SFClientConfigParser.loadSFClientConfig(configFilePath.toString());
if (!isSucceed) {
fail("testLogDirectoryPermissions failed. Expected exception.");
}
} catch (IOException e) {
if (isSucceed) {
fail("testLogDirectoryPermissions failed. Expected pass.");
}
} catch (Exception e) {
fail("testLogDirectoryPermissions failed. Unknown exception.");
Files.setPosixFilePermissions(configFilePath, PosixFilePermissions.fromString(permission));
SFClientConfigParser.loadSFClientConfig(configFilePath.toString());
if (!isSucceed) {
fail("testLogDirectoryPermissions failed. Expected exception.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Properties;
import java.util.logging.Level;
import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.jdbc.SnowflakeSQLLoggedException;
import org.apache.commons.io.FileUtils;
import org.junit.Test;

Expand Down Expand Up @@ -98,7 +99,7 @@ public void testJDK14LoggerWithQuotesInMessage() {
}

@Test
public void testJDK14LoggingWithMissingLogPathClientConfig() {
public void testJDK14LoggingWithMissingLogPathClientConfig() throws IOException {
Path configFilePath = Paths.get("config.json");
String configJson = "{\"common\":{\"log_level\":\"debug\"}}";

Expand All @@ -119,17 +120,13 @@ public void testJDK14LoggingWithMissingLogPathClientConfig() {
} catch (Exception e) {
fail("testJDK14LoggingWithMissingLogPathClientConfig failed");
} finally {
try {
Files.deleteIfExists(configFilePath);
FileUtils.deleteDirectory(new File(homeLogPath.toString()));
} catch (IOException e) {
fail("testJDK14LoggingWithMissingLogPathClientConfig failed");
}
Files.deleteIfExists(configFilePath);
FileUtils.deleteDirectory(new File(homeLogPath.toString()));
}
}

@Test
public void testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig() {
public void testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig() throws Exception {
System.clearProperty("user.home");

Path configFilePath = Paths.get("config.json");
Expand All @@ -141,17 +138,11 @@ public void testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig() {
Connection connection = getConnection(properties);

fail("testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig failed");
} catch (IOException e) {
fail("testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig failed");
} catch (SQLException e) {
} catch (SnowflakeSQLLoggedException e) {
// Succeed
} finally {
try {
System.setProperty("user.home", homePath);
Files.deleteIfExists(configFilePath);
} catch (IOException e) {
fail("testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig failed");
}
System.setProperty("user.home", homePath);
Files.deleteIfExists(configFilePath);
}
}
}

0 comments on commit 701bf67

Please sign in to comment.