Skip to content

Commit

Permalink
refactor(csharp/test): added error handling for reading resource file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-syed committed Mar 18, 2024
1 parent fe127bf commit 891649d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion csharp/test/Drivers/Interop/Snowflake/ConstraintTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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<string, string> placeholderValues = new Dictionary<string, string>() {
{"{ADBC_CONSTRANT_TABLE_1}", _tableName1 },
Expand Down
25 changes: 20 additions & 5 deletions csharp/test/Drivers/Interop/Snowflake/SnowflakeTestingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -137,22 +138,36 @@ SnowflakeTestConfiguration testConfiguration
/// Parses the queries from resources/SnowflakeData.sql
/// </summary>
/// <param name="testConfiguration"><see cref="SnowflakeTestConfiguration"/></param>
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)
{
Expand Down

0 comments on commit 891649d

Please sign in to comment.