Skip to content

Commit

Permalink
refactor environment configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coe committed Nov 22, 2024
1 parent a693d56 commit e7ec53d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 62 deletions.
2 changes: 1 addition & 1 deletion csharp/test/Drivers/Interop/FlightSql/DriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void CanGetObjectsAll()
foreach (FlightSqlTestEnvironment environment in _environments)
{
string databaseName = environment.Metadata.Catalog;
string schemaName = environment.Metadata.Schema;
string? schemaName = environment.Metadata.Schema;
string tableName = environment.Metadata.Table;
string? columnName = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
{
internal class FlightSqlTestConfiguration
{
public FlightSqlTestConfiguration()
{
this.Environments = new Dictionary<string, FlightSqlTestEnvironment>();
}

/// <summary>
/// The file path location of the driver.
/// </summary>
Expand All @@ -43,13 +38,13 @@ public FlightSqlTestConfiguration()
/// A comma separated list of testable environments.
/// </summary>
[JsonPropertyName("testEnvironments")]
public string? TestableEnvironments { get; set; }
public List<string> TestableEnvironments { get; set; } = new List<string>();

/// <summary>
/// The active test environment.
/// </summary>
[JsonPropertyName("environments")]
public Dictionary<string, FlightSqlTestEnvironment> Environments { get; set; }
public Dictionary<string, FlightSqlTestEnvironment> Environments { get; set; } = new Dictionary<string, FlightSqlTestEnvironment>();
}

internal enum FlightSqlTestEnvironmentType
Expand All @@ -63,11 +58,7 @@ internal class FlightSqlTestEnvironment : TestConfiguration
{
public FlightSqlTestEnvironment()
{
this.RPCCallHeaders = new Dictionary<string, string>();
this.TableTypes = new List<string>();
this.SupportsWriteUpdate = false;
this.SupportsCatalogs = false;
this.CaseSensitive = false;

}

/// <summary>
Expand All @@ -89,7 +80,7 @@ public FlightSqlTestEnvironment()
/// Additional headers to add to the gRPC call.
/// </summary>
[JsonPropertyName("headers")]
public Dictionary<string, string> RPCCallHeaders { get; set; }
public Dictionary<string, string> RPCCallHeaders { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Additional headers to add to the gRPC call.
Expand Down Expand Up @@ -126,15 +117,15 @@ public FlightSqlTestEnvironment()
public string? Password { get; set; }

[JsonPropertyName("supportsWriteUpdate")]
public bool SupportsWriteUpdate { get; set; }
public bool SupportsWriteUpdate { get; set; } = false;

[JsonPropertyName("supportsCatalogs")]
public bool SupportsCatalogs { get; set; }
public bool SupportsCatalogs { get; set; } = false;

[JsonPropertyName("tableTypes")]
public List<string> TableTypes { get; set; }
public List<string> TableTypes { get; set; } = new List<string>();

[JsonPropertyName("caseSensitive")]
public bool CaseSensitive { get; set; }
public bool CaseSensitive { get; set; } = false;
}
}
52 changes: 8 additions & 44 deletions csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
class FlightSqlTestingUtils
{
internal const string FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE = "FLIGHTSQL_INTEROP_TEST_CONFIG_FILE";
internal const string FLIGHTSQL_TEST_ENV_NAME = "FLIGHTSQL_TEST_ENV_NAMES";

public static FlightSqlTestConfiguration LoadFlightSqlTestConfiguration(string? environmentVariable = null)
{
Expand Down Expand Up @@ -69,49 +68,14 @@ internal static List<FlightSqlTestEnvironment> GetTestEnvironments(FlightSqlTest

List<FlightSqlTestEnvironment> environments = new List<FlightSqlTestEnvironment>();

// the user can specify a test environment:
// - in the config
// - in the environment variable
// - attempt to just use the first one from the config
if (string.IsNullOrEmpty(testConfiguration.TestableEnvironments))
foreach (string environmentName in GetEnvironmentNames(testConfiguration.TestableEnvironments!))
{
string? testEnvNameFromEnvVariable = Environment.GetEnvironmentVariable(FlightSqlTestingUtils.FLIGHTSQL_TEST_ENV_NAME);

if (string.IsNullOrEmpty(testEnvNameFromEnvVariable))
{
if (testConfiguration.Environments.Count > 0)
{
FlightSqlTestEnvironment firstEnvironment = testConfiguration.Environments.Values.First();
firstEnvironment.Name = testConfiguration.Environments.Keys.First();
environments.Add(firstEnvironment);
}
}
else
{
foreach (string environmentName in GetEnvironmentNames(testEnvNameFromEnvVariable))
{
if (testConfiguration.Environments.TryGetValue(environmentName, out FlightSqlTestEnvironment? flightSqlTestEnvironment))
{
if (flightSqlTestEnvironment != null)
{
flightSqlTestEnvironment.Name = environmentName;
environments.Add(flightSqlTestEnvironment);
}
}
}
}
}
else
{
foreach (string environmentName in GetEnvironmentNames(testConfiguration.TestableEnvironments!))
if (testConfiguration.Environments.TryGetValue(environmentName, out FlightSqlTestEnvironment? flightSqlTestEnvironment))
{
if (testConfiguration.Environments.TryGetValue(environmentName, out FlightSqlTestEnvironment? flightSqlTestEnvironment))
if (flightSqlTestEnvironment != null)
{
if (flightSqlTestEnvironment != null)
{
flightSqlTestEnvironment.Name = environmentName;
environments.Add(flightSqlTestEnvironment);
}
flightSqlTestEnvironment.Name = environmentName;
environments.Add(flightSqlTestEnvironment);
}
}
}
Expand All @@ -122,12 +86,12 @@ internal static List<FlightSqlTestEnvironment> GetTestEnvironments(FlightSqlTest
return environments;
}

private static List<string> GetEnvironmentNames(string names)
private static List<string> GetEnvironmentNames(List<string> names)
{
if (string.IsNullOrEmpty(names))
if (names == null)
return new List<string>();

return names.Split(',').Select(x => x.Trim()).ToList();
return names;
}

/// <summary>
Expand Down

0 comments on commit e7ec53d

Please sign in to comment.