From 48d5dfc4b7c57c48194d40b1dcceafd07dff0f76 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Mon, 3 Jun 2024 08:40:11 -0600 Subject: [PATCH] Remove TestUtil.systemGetEnv, replace all uses by SnowflakeUtil function --- .../snowflake/client/AbstractDriverIT.java | 32 ++++++++++--------- .../client/RunningOnGithubActions.java | 4 ++- .../java/net/snowflake/client/TestUtil.java | 27 ---------------- .../snowflake/client/AbstractDriverIT.java | 3 +- .../client/RunningNotOnTestaccount.java | 4 ++- .../client/RunningOnGithubAction.java | 6 ++-- .../client/RunningOnTestaccount.java | 4 ++- .../net/snowflake/client/SkipOnThinJar.java | 4 ++- .../java/net/snowflake/client/TestUtil.java | 27 ---------------- .../SFTrustManagerMockitoMockLatestIT.java | 3 +- .../client/core/SessionUtilLatestIT.java | 10 +++--- .../snowflake/client/jdbc/ConnectionIT.java | 5 ++- .../client/jdbc/ConnectionManual.java | 27 ++++++++-------- .../client/jdbc/DatabaseMetaDataIT.java | 2 +- .../client/jdbc/OpenGroupCLIFuncIT.java | 3 +- .../jdbc/PutFileWithSpaceIncludedIT.java | 9 +++--- .../client/jdbc/SnowflakeDriverLatestIT.java | 23 ++++++------- 17 files changed, 74 insertions(+), 119 deletions(-) diff --git a/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java b/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java index 05c389208..609894a0a 100644 --- a/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java +++ b/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java @@ -21,6 +21,8 @@ import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.Logger; + +import net.snowflake.client.jdbc.SnowflakeUtil; import org.junit.Rule; /** Base test class with common constants, data structures and methods */ @@ -49,13 +51,13 @@ public static Map getConnectionParameters(String accountName) { String account; String host; if (accountName == null) { - account = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); - host = TestUtil.systemGetEnv("SNOWFLAKE_TEST_HOST"); + account = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); + host = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_HOST"); } else { account = accountName; // By default, the test will run against reg deployment. // If developer needs to run in IntelliJ, you can set this env as ".dev.local" - String deployment = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DEPLOYMENT"); + String deployment = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DEPLOYMENT"); if (Strings.isNullOrEmpty(deployment)) { deployment = ".reg.local"; } @@ -75,7 +77,7 @@ public static Map getConnectionParameters(String accountName) { !Strings.isNullOrEmpty(host)); params.put("host", host); - String protocol = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PROTOCOL"); + String protocol = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PROTOCOL"); String ssl; if ("http".equals(protocol)) { ssl = "off"; @@ -84,16 +86,16 @@ public static Map getConnectionParameters(String accountName) { } params.put("ssl", ssl); - String user = TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER"); + String user = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER"); assertThat("set SNOWFLAKE_TEST_USER environment variable.", !Strings.isNullOrEmpty(user)); params.put("user", user); - String password = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PASSWORD"); + String password = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PASSWORD"); assertThat( "set SNOWFLAKE_TEST_PASSWORD environment variable.", !Strings.isNullOrEmpty(password)); params.put("password", password); - String port = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); + String port = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); if (Strings.isNullOrEmpty(port)) { if ("on".equals(ssl)) { port = "443"; @@ -104,36 +106,36 @@ public static Map getConnectionParameters(String accountName) { assertThat("set SNOWFLAKE_TEST_PORT environment variable.", !Strings.isNullOrEmpty(port)); params.put("port", port); - String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); + String database = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); assertThat( "set SNOWFLAKE_TEST_DATABASE environment variable.", !Strings.isNullOrEmpty(database)); params.put("database", database); - String schema = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); + String schema = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); assertThat("set SNOWFLAKE_TEST_SCHEMA environment variable.", !Strings.isNullOrEmpty(schema)); params.put("schema", schema); - String role = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ROLE"); + String role = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ROLE"); assertThat("set SNOWFLAKE_TEST_ROLE environment variable.", !Strings.isNullOrEmpty(role)); params.put("role", role); - String warehouse = TestUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE"); + String warehouse = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE"); assertThat( "set SNOWFLAKE_TEST_WAREHOUSE environment variable.", !Strings.isNullOrEmpty(warehouse)); params.put("warehouse", warehouse); params.put("uri", String.format("jdbc:snowflake://%s:%s", host, port)); - String adminUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); + String adminUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); params.put("adminUser", adminUser); - String adminPassword = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); + String adminPassword = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); params.put("adminPassword", adminPassword); - String ssoUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); + String ssoUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); params.put("ssoUser", ssoUser); - String ssoPassword = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_PASSWORD"); + String ssoPassword = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_PASSWORD"); params.put("ssoPassword", ssoPassword); return params; diff --git a/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java b/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java index d717b65dc..fa768f4e4 100644 --- a/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java +++ b/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java @@ -3,9 +3,11 @@ */ package net.snowflake.client; +import net.snowflake.client.jdbc.SnowflakeUtil; + /** Run tests on CI */ public class RunningOnGithubActions implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; + return SnowflakeUtil.systemGetEnv("GITHUB_ACTIONS") != null; } } diff --git a/FIPS/src/test/java/net/snowflake/client/TestUtil.java b/FIPS/src/test/java/net/snowflake/client/TestUtil.java index 2db8b7b2d..872cbaa38 100644 --- a/FIPS/src/test/java/net/snowflake/client/TestUtil.java +++ b/FIPS/src/test/java/net/snowflake/client/TestUtil.java @@ -33,31 +33,4 @@ public static void assertSFException(int errorCode, TestRunInterface testCode) { public interface TestRunInterface { void run() throws SFException; } - - /** - * System.getenv wrapper. If System.getenv raises an SecurityException, it is ignored and returns - * null. - * - *

This is replicated from SnowflakeUtil.systemGetEnv, because the old driver doesn't have that - * function for the tests to use it. Replace this function call with SnowflakeUtil.systemGetEnv - * when it is available. - * - * @param env the environment variable name. - * @return the environment variable value if set, otherwise null. - */ - public static String systemGetEnv(String env) { - try { - String value = System.getenv(env); - if(value == null) { - value = System.getenv().getOrDefault(env, null); - } - return value; - } catch (SecurityException ex) { - logger.debug( - "Failed to get environment variable {}. Security exception raised: {}", - env, - ex.getMessage()); - } - return null; - } } diff --git a/src/test/java/net/snowflake/client/AbstractDriverIT.java b/src/test/java/net/snowflake/client/AbstractDriverIT.java index 4a3acea23..c9265c109 100644 --- a/src/test/java/net/snowflake/client/AbstractDriverIT.java +++ b/src/test/java/net/snowflake/client/AbstractDriverIT.java @@ -24,6 +24,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; +import net.snowflake.client.jdbc.SnowflakeUtil; import org.junit.Rule; /** Base test class with common constants, data structures and methods */ @@ -54,7 +55,7 @@ private static String getConnPropKeyFromEnv(String connectionType, String propKe private static String getConnPropValueFromEnv(String connectionType, String propKey) { String envKey = String.format("SNOWFLAKE_%s_%s", connectionType, propKey); - return TestUtil.systemGetEnv(envKey); + return SnowflakeUtil.systemGetEnv(envKey); } public static Map getConnectionParameters(String accountName) { diff --git a/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java b/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java index 596f5ca55..582c68510 100644 --- a/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java +++ b/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java @@ -2,9 +2,11 @@ import static net.snowflake.client.RunningOnGithubAction.isRunningOnGithubAction; +import net.snowflake.client.jdbc.SnowflakeUtil; + public class RunningNotOnTestaccount implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return (!("testaccount".equals(TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"))) + return (!("testaccount".equals(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"))) || isRunningOnGithubAction()); } } diff --git a/src/test/java/net/snowflake/client/RunningOnGithubAction.java b/src/test/java/net/snowflake/client/RunningOnGithubAction.java index 0326c4fca..87ebf1dbc 100644 --- a/src/test/java/net/snowflake/client/RunningOnGithubAction.java +++ b/src/test/java/net/snowflake/client/RunningOnGithubAction.java @@ -3,13 +3,15 @@ */ package net.snowflake.client; +import net.snowflake.client.jdbc.SnowflakeUtil; + /** Run tests on CI */ public class RunningOnGithubAction implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; + return SnowflakeUtil.systemGetEnv("GITHUB_ACTIONS") != null; } public static boolean isRunningOnGithubAction() { - return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; + return SnowflakeUtil.systemGetEnv("GITHUB_ACTIONS") != null; } } diff --git a/src/test/java/net/snowflake/client/RunningOnTestaccount.java b/src/test/java/net/snowflake/client/RunningOnTestaccount.java index 186496977..49e410ed9 100644 --- a/src/test/java/net/snowflake/client/RunningOnTestaccount.java +++ b/src/test/java/net/snowflake/client/RunningOnTestaccount.java @@ -1,7 +1,9 @@ package net.snowflake.client; +import net.snowflake.client.jdbc.SnowflakeUtil; + public class RunningOnTestaccount implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT").contains("testaccount"); + return SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT").contains("testaccount"); } } diff --git a/src/test/java/net/snowflake/client/SkipOnThinJar.java b/src/test/java/net/snowflake/client/SkipOnThinJar.java index d02d104dd..3b5d878a5 100644 --- a/src/test/java/net/snowflake/client/SkipOnThinJar.java +++ b/src/test/java/net/snowflake/client/SkipOnThinJar.java @@ -3,10 +3,12 @@ */ package net.snowflake.client; +import net.snowflake.client.jdbc.SnowflakeUtil; + /** Skip tests on CI when thin jar is tested */ public class SkipOnThinJar implements ConditionalIgnoreRule.IgnoreCondition { @Override public boolean isSatisfied() { - return "-Dthin-jar".equals(TestUtil.systemGetEnv("ADDITIONAL_MAVEN_PROFILE")); + return "-Dthin-jar".equals(SnowflakeUtil.systemGetEnv("ADDITIONAL_MAVEN_PROFILE")); } } diff --git a/src/test/java/net/snowflake/client/TestUtil.java b/src/test/java/net/snowflake/client/TestUtil.java index edbfb395b..de6833793 100644 --- a/src/test/java/net/snowflake/client/TestUtil.java +++ b/src/test/java/net/snowflake/client/TestUtil.java @@ -62,33 +62,6 @@ public interface TestRunInterface { void run() throws SFException; } - /** - * System.getenv wrapper. If System.getenv raises an SecurityException, it is ignored and returns - * null. - * - *

This is replicated from SnowflakeUtil.systemGetEnv, because the old driver doesn't have that - * function for the tests to use it. Replace this function call with SnowflakeUtil.systemGetEnv - * when it is available. - * - * @param env the environment variable name. - * @return the environment variable value if set, otherwise null. - */ - public static String systemGetEnv(String env) { - try { - String value = System.getenv(env); - if (value == null) { - value = System.getenv().getOrDefault(env, null); - } - return value; - } catch (SecurityException ex) { - logger.debug( - "Failed to get environment variable {}. Security exception raised: {}", - env, - ex.getMessage()); - } - return null; - } - public static void assertValidQueryId(String queryId) { assertNotNull(queryId); assertTrue( diff --git a/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java b/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java index 862f4867e..c25b49942 100644 --- a/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java +++ b/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java @@ -13,7 +13,6 @@ import java.io.IOException; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; -import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryCore; import net.snowflake.client.jdbc.SnowflakeUtil; import org.junit.Ignore; @@ -41,7 +40,7 @@ public void testUnitOCSPWithCustomCacheDirectory() throws IOException { File cacheFolder = tmpFolder.newFolder(); mockedSnowflakeUtil - .when(() -> TestUtil.systemGetEnv("SF_OCSP_RESPONSE_CACHE_DIR")) + .when(() -> SnowflakeUtil.systemGetEnv("SF_OCSP_RESPONSE_CACHE_DIR")) .thenReturn(cacheFolder.getCanonicalPath()); TrustManagerFactory tested = mock(TrustManagerFactory.class); diff --git a/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java b/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java index f936ee616..f4d9a08fb 100644 --- a/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java +++ b/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java @@ -4,7 +4,6 @@ package net.snowflake.client.core; -import static net.snowflake.client.TestUtil.systemGetEnv; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; @@ -25,6 +24,7 @@ import net.snowflake.client.jdbc.BaseJDBCTest; import net.snowflake.client.jdbc.ErrorCode; import net.snowflake.client.jdbc.SnowflakeSQLException; +import net.snowflake.client.jdbc.SnowflakeUtil; import net.snowflake.common.core.ClientAuthnDTO; import net.snowflake.common.core.SqlState; import org.apache.commons.io.IOUtils; @@ -84,14 +84,14 @@ public void testJwtAuthTimeoutRetry() throws SFException, SnowflakeSQLException private SFLoginInput initMockLoginInput() { // mock SFLoginInput SFLoginInput loginInput = mock(SFLoginInput.class); - when(loginInput.getServerUrl()).thenReturn(systemGetEnv("SNOWFLAKE_TEST_HOST")); + when(loginInput.getServerUrl()).thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_HOST")); when(loginInput.getAuthenticator()) .thenReturn(ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT.name()); when(loginInput.getPrivateKeyFile()) - .thenReturn(systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE")); + .thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE")); when(loginInput.getPrivateKeyFilePwd()) - .thenReturn(systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE_PWD")); - when(loginInput.getUserName()).thenReturn(systemGetEnv("SNOWFLAKE_TEST_USER")); + .thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE_PWD")); + when(loginInput.getUserName()).thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER")); when(loginInput.getAccountName()).thenReturn("testaccount"); when(loginInput.getAppId()).thenReturn("testid"); when(loginInput.getOCSPMode()).thenReturn(OCSPMode.FAIL_OPEN); diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java index 2e0a9f13e..57c839bf1 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java @@ -42,7 +42,6 @@ import net.snowflake.client.ConditionalIgnoreRule.ConditionalIgnore; import net.snowflake.client.RunningNotOnTestaccount; import net.snowflake.client.RunningOnGithubAction; -import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryConnection; import net.snowflake.client.core.SFSession; import net.snowflake.common.core.SqlState; @@ -220,8 +219,8 @@ public void testConnectionGetAndSetDBAndSchema() throws SQLException { try (Connection con = getConnection(); Statement statement = con.createStatement()) { try { - final String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").toUpperCase(); - final String schema = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").toUpperCase(); + final String database = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").toUpperCase(); + final String schema = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").toUpperCase(); assertEquals(database, con.getCatalog()); assertEquals(schema, con.getSchema()); diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java b/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java index 91d5f7bc8..704835fb1 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java @@ -6,7 +6,6 @@ import java.sql.DriverManager; import java.sql.Statement; import java.util.Properties; -import net.snowflake.client.TestUtil; import net.snowflake.client.core.SessionUtil; /** @@ -51,9 +50,9 @@ public static void main(String args[]) throws Throwable { } private Properties getProperties() { - String account = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); - String ssoUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); - String ssl = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); + String account = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); + String ssoUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); + String ssl = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); Properties properties = new Properties(); properties.put("user", ssoUser); @@ -66,20 +65,20 @@ private Properties getProperties() { } private String getUrl() { - String account = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); - String port = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); + String account = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); + String port = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); return String.format("jdbc:snowflake://%s.reg.snowflakecomputing.com:%s", account, port); } private Connection getAdminConnection() throws Throwable { - String adminAccount = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_ACCOUNT"); + String adminAccount = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_ACCOUNT"); if (adminAccount == null) { adminAccount = "snowflake"; } - String adminUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); - String adminPassword = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); - String port = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); - String ssl = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); + String adminUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); + String adminPassword = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); + String port = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); + String ssl = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); if (ssl == null) { ssl = "on"; } @@ -125,9 +124,9 @@ private void resetTokenValidity() throws Throwable { } private void testSSO() throws Throwable { - String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); - String schema1 = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); - String schema2 = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA2"); + String database = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); + String schema1 = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); + String schema2 = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA2"); Properties properties = getProperties(); String url = getUrl(); diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java index 0a52b3df1..582973cd4 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java @@ -720,7 +720,7 @@ public void testDatabaseMetadata() throws SQLException { assertEquals(255, metaData.getMaxUserNameLength()); assertEquals(0, getSizeOfResultSet(metaData.getTablePrivileges(null, null, null))); // assertEquals("", metaData.getTimeDateFunctions()); - assertEquals(TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER"), metaData.getUserName()); + assertEquals(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER"), metaData.getUserName()); assertFalse(metaData.insertsAreDetected(1)); assertTrue(metaData.isCatalogAtStart()); assertFalse(metaData.isReadOnly()); diff --git a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java index d767456a2..2ea2a3d93 100644 --- a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java +++ b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java @@ -11,7 +11,6 @@ import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.AbstractDriverIT; -import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -137,7 +136,7 @@ public void testSystemFunctions() throws SQLException { testFunction( connection, "select {fn USER()}", - TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase()); + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase()); } } diff --git a/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java b/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java index 5cd03355c..7e319cefd 100644 --- a/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java @@ -12,7 +12,6 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; -import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -31,11 +30,11 @@ public class PutFileWithSpaceIncludedIT extends BaseJDBCTest { @Test @Ignore public void putFileWithSpaceIncluded() throws Exception { - String AWS_SECRET_KEY = TestUtil.systemGetEnv("AWS_SECRET_ACCESS_KEY"); - String AWS_KEY_ID = TestUtil.systemGetEnv("AWS_ACCESS_KEY_ID"); - String SF_AWS_USER_BUCKET = TestUtil.systemGetEnv("SF_AWS_USER_BUCKET"); + String AWS_SECRET_KEY = SnowflakeUtil.systemGetEnv("AWS_SECRET_ACCESS_KEY"); + String AWS_KEY_ID = SnowflakeUtil.systemGetEnv("AWS_ACCESS_KEY_ID"); + String SF_AWS_USER_BUCKET = SnowflakeUtil.systemGetEnv("SF_AWS_USER_BUCKET"); if (SF_AWS_USER_BUCKET == null) { - String userName = TestUtil.systemGetEnv("USERNAME"); + String userName = SnowflakeUtil.systemGetEnv("USERNAME"); assertNotNull(userName); SF_AWS_USER_BUCKET = "sfc-dev1-regression/" + userName + "/snow-13400"; } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java index da9847c9b..682c8805e 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java @@ -42,7 +42,6 @@ import net.snowflake.client.ConditionalIgnoreRule; import net.snowflake.client.RunningOnGithubAction; import net.snowflake.client.RunningOnTestaccount; -import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; import net.snowflake.client.core.Constants; import net.snowflake.client.core.OCSPMode; @@ -1606,7 +1605,7 @@ public void testHTAPOptimizations() throws SQLException { Statement statement = con.createStatement()) { statement.execute( "alter account " - + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " set ENABLE_SNOW_654741_FOR_TESTING=true"); } // Create a normal connection and assert that database, schema, and warehouse have expected @@ -1614,11 +1613,12 @@ public void testHTAPOptimizations() throws SQLException { try (Connection con = getConnection()) { SFSession session = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); assertTrue( - TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").equalsIgnoreCase(con.getSchema())); + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").equalsIgnoreCase(con.getSchema())); assertTrue( - TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").equalsIgnoreCase(con.getCatalog())); + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE") + .equalsIgnoreCase(con.getCatalog())); assertTrue( - TestUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") .equalsIgnoreCase(session.getWarehouse())); try (Statement statement = con.createStatement()) { // Set TIMESTAMP_OUTPUT_FORMAT (which is a session parameter) to check its value later @@ -1633,12 +1633,13 @@ public void testHTAPOptimizations() throws SQLException { // Assert database, schema, and warehouse have the same values as before even though // the select statement will return no parameters or metadata assertTrue( - TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").equalsIgnoreCase(con.getSchema())); + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA") + .equalsIgnoreCase(con.getSchema())); assertTrue( - TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE") + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE") .equalsIgnoreCase(con.getCatalog())); assertTrue( - TestUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") .equalsIgnoreCase(session.getWarehouse())); // Assert session parameter TIMESTAMP_OUTPUT_FORMAT has the same value as before the // select statement @@ -1657,7 +1658,7 @@ public void testHTAPOptimizations() throws SQLException { Statement statement = con.createStatement()) { statement.execute( "alter account " - + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " unset ENABLE_SNOW_654741_FOR_TESTING"); } } @@ -1677,7 +1678,7 @@ public void testHTAPStatementParameterCaching() throws SQLException { Statement statement = con.createStatement(); statement.execute( "alter account " - + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " set ENABLE_SNOW_654741_FOR_TESTING=true"); } try (Connection con = getConnection(); @@ -1723,7 +1724,7 @@ public void testHTAPStatementParameterCaching() throws SQLException { Statement statement = con2.createStatement()) { statement.execute( "alter account " - + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " unset ENABLE_SNOW_654741_FOR_TESTING"); } }