88using System . Runtime . InteropServices ;
99using NUnit . Framework ;
1010using Snowflake . Data . Client ;
11+ using Snowflake . Data . Core . Tools ;
1112using Snowflake . Data . Log ;
1213using Snowflake . Data . Tests . Util ;
1314
@@ -47,9 +48,9 @@ public static void TearDownContext()
4748 */
4849 [ TestFixture ]
4950 [ FixtureLifeCycle ( LifeCycle . InstancePerTestCase ) ]
50- [ SetCulture ( "en-US" ) ]
51+ [ SetCulture ( "en-US" ) ]
5152#if ! SEQUENTIAL_TEST_RUN
52- [ Parallelizable ( ParallelScope . All ) ]
53+ [ Parallelizable ( ParallelScope . All ) ]
5354#endif
5455 public class SFBaseTestAsync
5556 {
@@ -193,11 +194,67 @@ public void Setup()
193194 var cloud = Environment . GetEnvironmentVariable ( "snowflake_cloud_env" ) ;
194195 Assert . IsTrue ( cloud == null || cloud == "AWS" || cloud == "AZURE" || cloud == "GCP" , "{0} is not supported. Specify AWS, AZURE or GCP as cloud environment" , cloud ) ;
195196
196- TestConfig = ReadTestConfig ( "parameters.json" ) ;
197+ TestConfig = ReadTestConfig ( ) ;
197198 ModifySchema ( TestConfig . schema , SchemaAction . CREATE ) ;
198199 }
199200
200- internal static TestConfig ReadTestConfig ( string fileName )
201+ private static TestConfig ReadTestConfig ( )
202+ {
203+ var fileName = "parameters.json" ;
204+ var testConfig = File . Exists ( fileName ) ? ReadTestConfigFile ( fileName ) : ReadTestConfigEnvVariables ( ) ;
205+ testConfig . schema = testConfig . schema + "_" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "_" ) ;
206+ return testConfig ;
207+ }
208+
209+ private static TestConfig ReadTestConfigEnvVariables ( )
210+ {
211+ var config = new TestConfig ( ) ;
212+ config . user = ReadEnvVariableIfSet ( config . user , "SNOWFLAKE_TEST_USER" ) ;
213+ config . password = ReadEnvVariableIfSet ( config . password , "SNOWFLAKE_TEST_PASSWORD" ) ;
214+ config . account = ReadEnvVariableIfSet ( config . account , "SNOWFLAKE_TEST_ACCOUNT" ) ;
215+ config . host = ReadEnvVariableIfSet ( config . host , "SNOWFLAKE_TEST_HOST" ) ;
216+ config . port = ReadEnvVariableIfSet ( config . port , "SNOWFLAKE_TEST_PORT" ) ;
217+ config . warehouse = ReadEnvVariableIfSet ( config . warehouse , "SNOWFLAKE_TEST_WAREHOUSE" ) ;
218+ config . database = ReadEnvVariableIfSet ( config . database , "SNOWFLAKE_TEST_DATABASE" ) ;
219+ config . schema = ReadEnvVariableIfSet ( config . schema , "SNOWFLAKE_TEST_SCHEMA" ) ;
220+ config . role = ReadEnvVariableIfSet ( config . role , "SNOWFLAKE_TEST_ROLE" ) ;
221+ config . protocol = ReadEnvVariableIfSet ( config . protocol , "SNOWFLAKE_TEST_PROTOCOL" ) ;
222+ config . oktaUser = ReadEnvVariableIfSet ( config . oktaUser , "SNOWFLAKE_TEST_OKTA_USER" ) ;
223+ config . oktaPassword = ReadEnvVariableIfSet ( config . oktaPassword , "SNOWFLAKE_TEST_OKTA_PASSWORD" ) ;
224+ config . oktaUrl = ReadEnvVariableIfSet ( config . oktaUrl , "SNOWFLAKE_TEST_OKTA_URL" ) ;
225+ config . jwtAuthUser = ReadEnvVariableIfSet ( config . jwtAuthUser , "SNOWFLAKE_TEST_JWT_USER" ) ;
226+ config . pemFilePath = ReadEnvVariableIfSet ( config . pemFilePath , "SNOWFLAKE_TEST_PEM_FILE" ) ;
227+ config . p8FilePath = ReadEnvVariableIfSet ( config . p8FilePath , "SNOWFLAKE_TEST_P8_FILE" ) ;
228+ config . pwdProtectedPrivateKeyFilePath = ReadEnvVariableIfSet ( config . pwdProtectedPrivateKeyFilePath , "SNOWFLAKE_TEST_PWD_PROTECTED_PK_FILE" ) ;
229+ config . privateKey = ReadEnvVariableIfSet ( config . privateKey , "SNOWFLAKE_TEST_PK_CONTENT" ) ;
230+ config . pwdProtectedPrivateKey = ReadEnvVariableIfSet ( config . pwdProtectedPrivateKey , "SNOWFLAKE_TEST_PROTECTED_PK_CONTENT" ) ;
231+ config . privateKeyFilePwd = ReadEnvVariableIfSet ( config . privateKeyFilePwd , "SNOWFLAKE_TEST_PK_PWD" ) ;
232+ config . oauthToken = ReadEnvVariableIfSet ( config . oauthToken , "SNOWFLAKE_TEST_OAUTH_TOKEN" ) ;
233+ config . expOauthToken = ReadEnvVariableIfSet ( config . expOauthToken , "SNOWFLAKE_TEST_EXP_OAUTH_TOKEN" ) ;
234+ config . proxyHost = ReadEnvVariableIfSet ( config . proxyHost , "SNOWFLAKE_TEST_PROXY_HOST" ) ;
235+ config . proxyPort = ReadEnvVariableIfSet ( config . proxyPort , "SNOWFLAKE_TEST_PROXY_PORT" ) ;
236+ config . authProxyHost = ReadEnvVariableIfSet ( config . authProxyHost , "SNOWFLAKE_TEST_AUTH_PROXY_HOST" ) ;
237+ config . authProxyPort = ReadEnvVariableIfSet ( config . authProxyPort , "SNOWFLAKE_TEST_AUTH_PROXY_PORT" ) ;
238+ config . authProxyUser = ReadEnvVariableIfSet ( config . authProxyUser , "SNOWFLAKE_TEST_AUTH_PROXY_USER" ) ;
239+ config . authProxyPwd = ReadEnvVariableIfSet ( config . authProxyPwd , "SNOWFLAKE_TEST_AUTH_PROXY_PWD" ) ;
240+ config . nonProxyHosts = ReadEnvVariableIfSet ( config . nonProxyHosts , "SNOWFLAKE_TEST_NON_PROXY_HOSTS" ) ;
241+ config . oauthClientId = ReadEnvVariableIfSet ( config . oauthClientId , "SNOWFLAKE_TEST_OAUTH_CLIENT_ID" ) ;
242+ config . oauthClientSecret = ReadEnvVariableIfSet ( config . oauthClientSecret , "SNOWFLAKE_TEST_OAUTH_CLIENT_SECRET" ) ;
243+ config . oauthScope = ReadEnvVariableIfSet ( config . oauthScope , "SNOWFLAKE_TEST_OAUTH_SCOPE" ) ;
244+ config . oauthRedirectUri = ReadEnvVariableIfSet ( config . oauthRedirectUri , "SNOWFLAKE_TEST_OAUTH_REDIRECT_URI" ) ;
245+ config . oauthAuthorizationUrl = ReadEnvVariableIfSet ( config . oauthAuthorizationUrl , "SNOWFLAKE_TEST_OAUTH_AUTHORIZATION_URL" ) ;
246+ config . oauthTokenRequestUrl = ReadEnvVariableIfSet ( config . oauthTokenRequestUrl , "SNOWFLAKE_TEST_OAUTH_TOKEN_REQUEST_URL" ) ;
247+ config . programmaticAccessToken = ReadEnvVariableIfSet ( config . programmaticAccessToken , "SNOWFLAKE_TEST_PROGRAMMATIC_ACCESS_TOKEN" ) ;
248+ return config ;
249+ }
250+
251+ private static string ReadEnvVariableIfSet ( string defaultValue , string variableName )
252+ {
253+ var variableValue = Environment . GetEnvironmentVariable ( variableName ) ;
254+ return string . IsNullOrEmpty ( variableValue ) ? defaultValue : variableValue ;
255+ }
256+
257+ internal static TestConfig ReadTestConfigFile ( string fileName )
201258 {
202259 var reader = new StreamReader ( fileName ) ;
203260 var testConfigString = reader . ReadToEnd ( ) ;
@@ -213,9 +270,7 @@ internal static TestConfig ReadTestConfig(string fileName)
213270 var testConfigs = JsonConvert . DeserializeObject < Dictionary < string , TestConfig > > ( testConfigString , jsonSettings ) ;
214271 if ( testConfigs . TryGetValue ( "testconnection" , out var testConnectionConfig ) )
215272 {
216- var testConfig = testConnectionConfig ;
217- testConfig . schema = testConfig . schema + "_" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "_" ) ;
218- return testConfig ;
273+ return testConnectionConfig ;
219274 }
220275 else
221276 {
0 commit comments