diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2bd57d2cf0..688b69ac4f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -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 diff --git a/windows/ci/live-servers.ps1 b/windows/ci/live-servers.ps1 index 56856fe8f3..7552d81bce 100644 --- a/windows/ci/live-servers.ps1 +++ b/windows/ci/live-servers.ps1 @@ -2,7 +2,7 @@ # TABLEPRO_TEST_LIVE__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 ) @@ -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 diff --git a/windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs b/windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs new file mode 100644 index 0000000000..5668579c78 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/PostgresTests.cs @@ -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 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)"; +}