1
1
import Logging
2
+ import FluentKit
2
3
import FluentBenchmark
3
4
import FluentPostgresDriver
4
5
import XCTest
6
+ import PostgresKit
5
7
6
8
final class FluentPostgresDriverTests : XCTestCase {
7
9
func testAll( ) throws { try self . benchmarker. testAll ( ) }
@@ -133,15 +135,7 @@ final class FluentPostgresDriverTests: XCTestCase {
133
135
let jsonDecoder = JSONDecoder ( )
134
136
jsonDecoder. dateDecodingStrategy = . iso8601
135
137
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 " ,
145
139
encoder: PostgresDataEncoder ( json: jsonEncoder) ,
146
140
decoder: PostgresDataDecoder ( json: jsonDecoder)
147
141
) , as: . iso8601)
@@ -179,27 +173,13 @@ final class FluentPostgresDriverTests: XCTestCase {
179
173
override func setUpWithError( ) throws {
180
174
try super. setUpWithError ( )
181
175
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
- )
196
176
XCTAssert ( isLoggingConfigured)
197
177
self . eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: System . coreCount)
198
178
self . threadPool = NIOThreadPool ( numberOfThreads: System . coreCount)
199
179
self . dbs = Databases ( threadPool: threadPool, on: self . eventLoopGroup)
200
180
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)
203
183
204
184
let a = self . dbs. database ( . a, logger: Logger ( label: " test.fluent.a " ) , on: self . eventLoopGroup. next ( ) )
205
185
_ = try ( a as! PostgresDatabase ) . query ( " drop schema public cascade " ) . wait ( )
@@ -218,6 +198,23 @@ final class FluentPostgresDriverTests: XCTestCase {
218
198
}
219
199
}
220
200
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
+
221
218
extension DatabaseID {
222
219
static let iso8601 = DatabaseID ( string: " iso8601 " )
223
220
static let a = DatabaseID ( string: " a " )
0 commit comments