Skip to content

Commit

Permalink
Added integration tests for pg.oid.
Browse files Browse the repository at this point in the history
  • Loading branch information
skuruppu authored and amanda-tarafa committed Feb 22, 2024
1 parent 43818f3 commit 0803c0a
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public async Task BindPgJsonb() =>
public async Task BindPgJsonbArray() =>
await TestBindNonNull(SpannerDbType.ArrayOf(SpannerDbType.PgJsonb), new string[] { "{\"key\": \"value\"}", null, "{\"other-key\": \"other-value\"}" });

[Fact]
public async Task BindPgOid() =>
await TestBindNonNull(SpannerDbType.PgOid, 1234, r => r.GetInt64(0));

[Fact]
public Task BindPgOidArray() => TestBindNonNull(
SpannerDbType.ArrayOf(SpannerDbType.PgOid),
new long?[] { 1, null, 0 });

[Fact]
public Task BindPgOidEmptyArray() => TestBindNonNull(
SpannerDbType.ArrayOf(SpannerDbType.PgOid),
new long[] { });

private async Task TestBindNonNull<T>(SpannerDbType parameterType, T value, Func<SpannerDataReader, T> typeSpecificReader = null)
{
using var connection = GetConnection();
Expand All @@ -70,8 +84,10 @@ private async Task TestBindNonNull<T>(SpannerDbType parameterType, T value, Func
{
SpannerDbType.PgNumeric,
SpannerDbType.PgJsonb,
SpannerDbType.PgOid,
SpannerDbType.ArrayOf(SpannerDbType.PgNumeric),
SpannerDbType.ArrayOf(SpannerDbType.PgJsonb)
SpannerDbType.ArrayOf(SpannerDbType.PgJsonb),
SpannerDbType.ArrayOf(SpannerDbType.PgOid)
};

[Theory]
Expand All @@ -85,6 +101,24 @@ public async Task BindNull(SpannerDbType parameterType)
await BindingTests.AssertNull(reader);
}

[Fact]
public async Task ReadCastAsOid()
{
using var connection = GetConnection();
using var cmd = connection.CreateSelectCommand("SELECT 123::oid");
using var reader = await cmd.ExecuteReaderAsync();
await BindingTests.AssertNotNull<long>(reader, 123, r => r.GetInt64(0));
}

[Fact]
public async Task ReadCastAsNullOid()
{
using var connection = GetConnection();
using var cmd = connection.CreateSelectCommand("SELECT null::oid");
using var reader = await cmd.ExecuteReaderAsync();
await BindingTests.AssertNull(reader);
}

// Schema Table Tests for PostgreSQL specific types. GSQL and common types are tested in the GetSchemaTableTests.cs

[MemberData(nameof(SchemaTestData))]
Expand Down

0 comments on commit 0803c0a

Please sign in to comment.