Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ jobs:
dotnet-version: 10.0.x
- name: Start MySQL
run: windows/ci/live-servers.ps1 -Server MySql
- name: Start PostgreSQL
run: windows/ci/live-servers.ps1 -Server Postgres
- name: Start MongoDB
run: windows/ci/live-servers.ps1 -Server MongoDb
- name: Start Redis
Expand Down
27 changes: 26 additions & 1 deletion windows/ci/live-servers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# TABLEPRO_TEST_LIVE_<ENGINE>_PORT, _USER and _PASSWORD. How each one runs: docs/decisions/0016-live-server-tests.md.
param(
[Parameter(Mandatory)]
[ValidateSet('MySql', 'SqlServer', 'MongoDb', 'Redis', 'Cassandra', 'Wsl', 'ClickHouse')]
[ValidateSet('MySql', 'SqlServer', 'MongoDb', 'Redis', 'Cassandra', 'Wsl', 'ClickHouse', 'Postgres')]
[string]$Server
)

Expand Down Expand Up @@ -72,6 +72,31 @@ switch ($Server) {
if ($LASTEXITCODE -ne 0) { throw 'Creating the MySQL test user failed.' }
Set-Live MYSQL 3306 tablepro $password
}
# The image ships PostgreSQL in PGBIN as a stopped service, with superuser postgres and password root.
'Postgres' {
if (-not $env:PGBIN -or -not (Test-Path (Join-Path $env:PGBIN 'psql.exe'))) {
throw 'The runner must provide PostgreSQL in PGBIN.'
}
$service = Get-Service 'postgresql-x64-*' | Select-Object -First 1
Set-Service $service.Name -StartupType Manual
Start-Service $service.Name
$psql = Join-Path $env:PGBIN 'psql.exe'
$password = New-Password
$env:PGPASSWORD = 'root'
# template0 with UTF8: the cluster's own encoding on this image is not UTF8, and the value corpus is.
# lc_monetary C: the image's locale prints a negative money value in accounting parentheses, the corpus with a sign.
& $psql -h 127.0.0.1 -U postgres -d postgres -v ON_ERROR_STOP=1 `
-c "CREATE ROLE tablepro LOGIN PASSWORD '$password'" `
-c 'CREATE DATABASE tablepro OWNER tablepro TEMPLATE template0 ENCODING ''UTF8'' LC_COLLATE ''C'' LC_CTYPE ''C''' `
-c "ALTER DATABASE tablepro SET timezone TO 'UTC'" `
-c "ALTER DATABASE tablepro SET lc_monetary TO 'C'"
if ($LASTEXITCODE -ne 0) { throw 'Creating the PostgreSQL test database failed.' }
# The public schema's CREATE is not the database owner's on PostgreSQL 15 and later.
& $psql -h 127.0.0.1 -U postgres -d tablepro -v ON_ERROR_STOP=1 -c 'GRANT ALL ON SCHEMA public TO tablepro'
if ($LASTEXITCODE -ne 0) { throw 'Granting the PostgreSQL test schema failed.' }
Remove-Item Env:PGPASSWORD
Set-Live POSTGRES 5432 tablepro $password
}
'SqlServer' {
$password = New-Password
& (Join-Path $PSScriptRoot '../../core/crates/drivers/mssql/tests/windows/sql-server.ps1') -Install -SaPassword $password
Expand Down
28 changes: 28 additions & 0 deletions windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace TablePro.Interop.Tests.Live;

public sealed class PostgresTests : SqlEngineTests
{
private const string Database = "tablepro";
private const string Schema = "public";

protected override string CorpusFile => "postgres";

protected override Task<DatabaseSession> OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken)
{
var server = LiveServer.Require("POSTGRES");
return ConnectAsync(
core,
new SavedConnection(null, "PostgreSQL", "postgres", LiveServer.Host, server.Port, Database, server.UserName, new TlsSettings(TlsMode.Prefer)),
server.Secrets,
cancellationToken);
}

protected override TableName Table(string name) => new(Schema, name);

protected override string Qualified(string name) => $"\"{Schema}\".\"{name}\"";

protected override string CorpusTableSql(string table) => $"CREATE TABLE {table} (id integer PRIMARY KEY, label text NOT NULL)";

protected override string PeopleTableSql(string table) =>
$"CREATE TABLE {table} (id integer PRIMARY KEY, name varchar(100) NOT NULL, note text)";
}
Loading