Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a0383f0

Browse files
authored
Normalize environment variable naming to match official PostgreSQL Docker image usage. Clean up CI workflow to match postgres-kit and postgres-nio where applicable, including fixes to Homebrew usage. (#186)
1 parent 6485aed commit a0383f0

File tree

2 files changed

+44
-52
lines changed

2 files changed

+44
-52
lines changed

β€Ž.github/workflows/test.yml

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: test
22
on: [ 'pull_request' ]
33

44
jobs:
5-
linux:
5+
linux-all:
66
strategy:
77
fail-fast: false
88
matrix:
@@ -25,15 +25,10 @@ jobs:
2525
runs-on: ubuntu-latest
2626
env:
2727
LOG_LEVEL: debug
28-
POSTGRES_DB: 'vapor_database'
29-
POSTGRES_DATABASE: 'vapor_database'
30-
POSTGRES_DATABASE_A: 'vapor_database'
31-
POSTGRES_DATABASE_B: 'vapor_database'
32-
POSTGRES_USER: 'vapor_username'
33-
POSTGRES_USERNAME: 'vapor_username'
34-
POSTGRES_USERNAME_A: 'vapor_username'
35-
POSTGRES_USERNAME_B: 'vapor_username'
36-
POSTGRES_PASSWORD: 'vapor_password'
28+
POSTGRES_DB_A: 'vapor_database'
29+
POSTGRES_DB_B: 'vapor_database'
30+
POSTGRES_USER_A: 'vapor_username'
31+
POSTGRES_USER_B: 'vapor_username'
3732
POSTGRES_PASSWORD_A: 'vapor_password'
3833
POSTGRES_PASSWORD_B: 'vapor_password'
3934
POSTGRES_HOSTNAME_A: 'psql-a'
@@ -59,17 +54,18 @@ jobs:
5954
steps:
6055
- name: Check out package
6156
uses: actions/checkout@v2
62-
- name: Run unit tests
63-
run: swift test --enable-test-discovery
57+
- name: Run all tests with Thread Sanitizer
58+
run: swift test --enable-test-discovery --sanitize=thread
6459

6560
macos-all:
6661
strategy:
6762
fail-fast: false
6863
matrix:
6964
dbimage:
65+
# Only test the lastest version on macOS, let Linux do the rest
7066
- postgresql@14
71-
- postgresql@13
7267
dbauth:
68+
# Only test one auth method on macOS, Linux tests will cover the others
7369
- scram-sha-256
7470
xcode:
7571
- latest-stable
@@ -79,13 +75,12 @@ jobs:
7975
LOG_LEVEL: debug
8076
POSTGRES_HOSTNAME_A: 127.0.0.1
8177
POSTGRES_HOSTNAME_B: 127.0.0.1
82-
POSTGRES_USERNAME_A: 'vapor_username'
83-
POSTGRES_USERNAME_B: 'vapor_username'
78+
POSTGRES_USER_A: 'vapor_username'
79+
POSTGRES_USER_B: 'vapor_username'
8480
POSTGRES_PASSWORD_A: 'vapor_password'
8581
POSTGRES_PASSWORD_B: 'vapor_password'
86-
POSTGRES_DATABASE_A: 'vapor_database_a'
87-
POSTGRES_DATABASE_B: 'vapor_database_b'
88-
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
82+
POSTGRES_DB_A: 'vapor_database_a'
83+
POSTGRES_DB_B: 'vapor_database_b'
8984
steps:
9085
- name: Select latest available Xcode
9186
uses: maxim-lobanov/setup-xcode@v1
@@ -94,19 +89,19 @@ jobs:
9489
- name: Install Postgres, setup DB and auth, and wait for server start
9590
run: |
9691
export PATH="$(brew --prefix)/opt/${{ matrix.dbimage }}/bin:$PATH" PGDATA=/tmp/vapor-postgres-test PGUSER=postgres
97-
brew install ${{ matrix.dbimage }}
92+
(brew unlink postgresql || true) && brew install ${{ matrix.dbimage }} && brew link --force ${{ matrix.dbimage }}
9893
initdb --locale=C --auth-host ${{ matrix.dbauth }} --username=postgres --pwfile=<(echo postgres)
9994
pg_ctl start --wait
100-
psql postgres <<<"CREATE ROLE $POSTGRES_USERNAME_A LOGIN PASSWORD '$POSTGRES_PASSWORD_A';"
101-
psql postgres <<<"CREATE ROLE $POSTGRES_USERNAME_B LOGIN PASSWORD '$POSTGRES_PASSWORD_B';"
102-
psql postgres <<<"CREATE DATABASE $POSTGRES_DATABASE_A OWNER = $POSTGRES_USERNAME_A;"
103-
psql postgres <<<"CREATE DATABASE $POSTGRES_DATABASE_B OWNER = $POSTGRES_USERNAME_B;"
104-
psql $POSTGRES_DATABASE_A <<<"ALTER SCHEMA public OWNER TO $POSTGRES_USERNAME_A;"
105-
psql $POSTGRES_DATABASE_B <<<"ALTER SCHEMA public OWNER TO $POSTGRES_USERNAME_B;"
95+
psql postgres <<<"CREATE ROLE $POSTGRES_USER_A LOGIN PASSWORD '$POSTGRES_PASSWORD_A';"
96+
psql postgres <<<"CREATE ROLE $POSTGRES_USER_B LOGIN PASSWORD '$POSTGRES_PASSWORD_B';"
97+
psql postgres <<<"CREATE DATABASE $POSTGRES_DB_A OWNER = $POSTGRES_USER_A;"
98+
psql postgres <<<"CREATE DATABASE $POSTGRES_DB_B OWNER = $POSTGRES_USER_B;"
99+
psql $POSTGRES_DB_A <<<"ALTER SCHEMA public OWNER TO $POSTGRES_USER_A;"
100+
psql $POSTGRES_DB_B <<<"ALTER SCHEMA public OWNER TO $POSTGRES_USER_B;"
106101
timeout-minutes: 2
107102
- name: Checkout code
108103
uses: actions/checkout@v2
109-
- name: Run all tests
104+
- name: Run all tests with Thread Sanitizer
110105
run: |
111-
swift test --enable-test-discovery -Xlinker -rpath \
106+
swift test --sanitize=thread -Xlinker -rpath \
112107
-Xlinker $(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx

β€ŽTests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Logging
2+
import FluentKit
23
import FluentBenchmark
34
import FluentPostgresDriver
45
import XCTest
6+
import PostgresKit
57

68
final class FluentPostgresDriverTests: XCTestCase {
79
func testAll() throws { try self.benchmarker.testAll() }
@@ -133,15 +135,7 @@ final class FluentPostgresDriverTests: XCTestCase {
133135
let jsonDecoder = JSONDecoder()
134136
jsonDecoder.dateDecodingStrategy = .iso8601
135137

136-
let configuration = PostgresConfiguration(
137-
hostname: env("POSTGRES_HOSTNAME_A") ?? "localhost",
138-
port: env("POSTGRES_PORT_A").flatMap(Int.init) ?? PostgresConfiguration.ianaPortNumber,
139-
username: env("POSTGRES_USERNAME_A") ?? "vapor_username",
140-
password: env("POSTGRES_PASSWORD_A") ?? "vapor_password",
141-
database: env("POSTGRES_DATABASE_A") ?? "vapor_database"
142-
)
143-
self.dbs.use(.postgres(
144-
configuration: configuration,
138+
self.dbs.use(.testPostgres(subconfig: "A",
145139
encoder: PostgresDataEncoder(json: jsonEncoder),
146140
decoder: PostgresDataDecoder(json: jsonDecoder)
147141
), as: .iso8601)
@@ -179,27 +173,13 @@ final class FluentPostgresDriverTests: XCTestCase {
179173
override func setUpWithError() throws {
180174
try super.setUpWithError()
181175

182-
let aConfig = PostgresConfiguration(
183-
hostname: env("POSTGRES_HOSTNAME_A") ?? "localhost",
184-
port: env("POSTGRES_PORT_A").flatMap(Int.init) ?? PostgresConfiguration.ianaPortNumber,
185-
username: env("POSTGRES_USERNAME_A") ?? "vapor_username",
186-
password: env("POSTGRES_PASSWORD_A") ?? "vapor_password",
187-
database: env("POSTGRES_DATABASE_A") ?? "vapor_database"
188-
)
189-
let bConfig = PostgresConfiguration(
190-
hostname: env("POSTGRES_HOSTNAME_B") ?? "localhost",
191-
port: env("POSTGRES_PORT_B").flatMap(Int.init) ?? PostgresConfiguration.ianaPortNumber,
192-
username: env("POSTGRES_USERNAME_B") ?? "vapor_username",
193-
password: env("POSTGRES_PASSWORD_B") ?? "vapor_password",
194-
database: env("POSTGRES_DATABASE_B") ?? "vapor_database"
195-
)
196176
XCTAssert(isLoggingConfigured)
197177
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
198178
self.threadPool = NIOThreadPool(numberOfThreads: System.coreCount)
199179
self.dbs = Databases(threadPool: threadPool, on: self.eventLoopGroup)
200180

201-
self.dbs.use(.postgres(configuration: aConfig, connectionPoolTimeout:.seconds(30)), as: .a)
202-
self.dbs.use(.postgres(configuration: bConfig, connectionPoolTimeout:.seconds(30)), as: .b)
181+
self.dbs.use(.testPostgres(subconfig:"A"), as: .a)
182+
self.dbs.use(.testPostgres(subconfig:"B"), as: .b)
203183

204184
let a = self.dbs.database(.a, logger: Logger(label: "test.fluent.a"), on: self.eventLoopGroup.next())
205185
_ = try (a as! PostgresDatabase).query("drop schema public cascade").wait()
@@ -218,6 +198,23 @@ final class FluentPostgresDriverTests: XCTestCase {
218198
}
219199
}
220200

201+
extension DatabaseConfigurationFactory {
202+
static func testPostgres(
203+
subconfig: String,
204+
encoder: PostgresDataEncoder = .init(), decoder: PostgresDataDecoder = .init()
205+
) -> DatabaseConfigurationFactory {
206+
let baseSubconfig = PostgresConfiguration(
207+
hostname: env("POSTGRES_HOSTNAME_\(subconfig)") ?? "localhost",
208+
port: env("POSTGRES_PORT_\(subconfig)").flatMap(Int.init) ?? PostgresConfiguration.ianaPortNumber,
209+
username: env("POSTGRES_USER_\(subconfig)") ?? "vapor_username",
210+
password: env("POSTGRES_PASSWORD_\(subconfig)") ?? "vapor_password",
211+
database: env("POSTGRES_DB_\(subconfig)") ?? "vapor_database"
212+
)
213+
214+
return .postgres(configuration: baseSubconfig, connectionPoolTimeout: .seconds(30), encoder: encoder, decoder: decoder)
215+
}
216+
}
217+
221218
extension DatabaseID {
222219
static let iso8601 = DatabaseID(string: "iso8601")
223220
static let a = DatabaseID(string: "a")

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /