Skip to content

Commit

Permalink
Support running PG integration tests on emulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
skuruppu authored and amanda-tarafa committed Jun 14, 2024
1 parent 5c4607f commit 5911fc8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,33 @@ public static SpannerTestDatabasePostgreSql Create(string projectId)
/// Initializes a new instance of the <see cref="SpannerTestDatabasePostgreSql"/> class.
/// </summary>
/// <param name="projectId">The project ID to be used for test database.</param>
private SpannerTestDatabasePostgreSql(string projectId) : base(projectId, EmulatorDetection.None)
private SpannerTestDatabasePostgreSql(string projectId) : base(projectId, EmulatorDetection.EmulatorOrProduction)
{
}

protected override bool TryCreateDatabase()
{
DatabaseAdminClient databaseAdminClient;
if (SpannerClientCreationOptions.UsesEmulator)
{
#if NETSTANDARD2_1
// On .NET Core 3.1 (but not .NET 6) Grpc.Net.Client needs an additional switch
// to allow an insecure channel in HTTP/2.
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
#endif
// Try to create a database on the emulator and ignore any AlreadyExists error.
var adminClientBuilder = new DatabaseAdminClientBuilder
{
EmulatorDetection = EmulatorDetection.EmulatorOnly
};
databaseAdminClient = adminClientBuilder.Build();
}
else
{
databaseAdminClient = DatabaseAdminClient.Create();
}

const DatabaseDialect dialect = DatabaseDialect.Postgresql;
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.Create();
CreateDatabaseRequest createDatabaseRequest = new CreateDatabaseRequest
{
CreateStatement = $"CREATE DATABASE {SpannerDatabase}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace Google.Cloud.Spanner.Data.IntegrationTests;

[Collection(nameof(AllTypesTableFixturePostgreSql))]
[CommonTestDiagnostics]
[Trait(Constants.SupportedOnEmulator, Constants.No)]
public class PgTests
{
private readonly AllTypesTableFixturePostgreSql _fixture;
Expand Down

0 comments on commit 5911fc8

Please sign in to comment.