From 891649d13b41fe2b1524ee7c4f3185828d11ac50 Mon Sep 17 00:00:00 2001 From: Ryan Syed Date: Mon, 18 Mar 2024 14:08:36 -0700 Subject: [PATCH] refactor(csharp/test): added error handling for reading resource file --- .../Interop/Snowflake/ConstraintTests.cs | 4 ++- .../Snowflake/SnowflakeTestingUtils.cs | 25 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/csharp/test/Drivers/Interop/Snowflake/ConstraintTests.cs b/csharp/test/Drivers/Interop/Snowflake/ConstraintTests.cs index 00bc70ee59..c722aae6c3 100644 --- a/csharp/test/Drivers/Interop/Snowflake/ConstraintTests.cs +++ b/csharp/test/Drivers/Interop/Snowflake/ConstraintTests.cs @@ -148,6 +148,8 @@ public class ConstraintTestsFixutre : IDisposable public readonly string _tableName2; private bool _disposed = false; + private const string SNOWFLAKE_CONSTRAINTS_DATA_RESOURCE = "Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake.Resources.SnowflakeConstraints.sql"; + public ConstraintTestsFixutre() { @@ -167,7 +169,7 @@ public ConstraintTestsFixutre() private void CreateTables() { - string[] queries = SnowflakeTestingUtils.GetQueries(_snowflakeTestConfiguration, "Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake.Resources.SnowflakeConstraints.sql"); + string[] queries = SnowflakeTestingUtils.GetQueries(_snowflakeTestConfiguration, SNOWFLAKE_CONSTRAINTS_DATA_RESOURCE); Dictionary placeholderValues = new Dictionary() { {"{ADBC_CONSTRANT_TABLE_1}", _tableName1 }, diff --git a/csharp/test/Drivers/Interop/Snowflake/SnowflakeTestingUtils.cs b/csharp/test/Drivers/Interop/Snowflake/SnowflakeTestingUtils.cs index c04883641b..1bf23ee5aa 100644 --- a/csharp/test/Drivers/Interop/Snowflake/SnowflakeTestingUtils.cs +++ b/csharp/test/Drivers/Interop/Snowflake/SnowflakeTestingUtils.cs @@ -47,6 +47,7 @@ internal class SnowflakeTestingUtils private static readonly Assembly CurrentAssembly; internal const string SNOWFLAKE_TEST_CONFIG_VARIABLE = "SNOWFLAKE_TEST_CONFIG_FILE"; + private const string SNOWFLAKE_DATA_RESOURCE = "Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake.Resources.SnowflakeData.sql"; static SnowflakeTestingUtils() { @@ -137,22 +138,36 @@ SnowflakeTestConfiguration testConfiguration /// Parses the queries from resources/SnowflakeData.sql /// /// - internal static string[] GetQueries(SnowflakeTestConfiguration testConfiguration, string resourceName = "Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake.Resources.SnowflakeData.sql") + internal static string[] GetQueries(SnowflakeTestConfiguration testConfiguration, string resourceName = SNOWFLAKE_DATA_RESOURCE) { StringBuilder content = new StringBuilder(); string[] sql = null; - using (Stream stream = CurrentAssembly.GetManifestResourceStream(resourceName)) + try { - if (stream != null) + using (Stream stream = CurrentAssembly.GetManifestResourceStream(resourceName)) { - using (StreamReader sr = new StreamReader(stream)) + if (stream != null) + { + using (StreamReader sr = new StreamReader(stream)) + { + sql = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.None); + } + } + else { - sql = sr.ReadToEnd().Split(new[] {Environment.NewLine }, StringSplitOptions.None); + throw new FileNotFoundException("Embedded resource not found", resourceName); } } } + catch (Exception ex) + { + Console.WriteLine($"An error occured while reading the resouce: {resourceName}"); + Console.WriteLine(ex.Message); + throw; + } + if (sql == null) {