@@ -8,7 +8,7 @@ import Core
88class PostgreSQLConnectionTests : XCTestCase {
99 let defaultTimeout = 5.0
1010 func testVersion( ) throws {
11- let client = try PostgreSQLConnection . makeTest ( )
11+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
1212 let results = try client. simpleQuery ( " SELECT version(); " ) . wait ( )
1313 try XCTAssert ( results [ 0 ] . firstValue ( forColumn: " version " ) ? . decode ( String . self) . contains ( " 10. " ) == true )
1414 }
@@ -20,7 +20,7 @@ class PostgreSQLConnectionTests: XCTestCase {
2020 }
2121
2222 func testSelectTypes( ) throws {
23- let client = try PostgreSQLConnection . makeTest ( )
23+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
2424 let results = try client. query ( " select * from pg_type; " ) . wait ( )
2525 if results. count > 350 {
2626 let name = try results [ 128 ] . firstValue ( forColumn: " typname " ) ? . decode ( String . self)
@@ -31,7 +31,7 @@ class PostgreSQLConnectionTests: XCTestCase {
3131 }
3232
3333 func testParse( ) throws {
34- let client = try PostgreSQLConnection . makeTest ( )
34+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
3535 let query = """
3636 select * from " pg_type " where " typlen " = $1 or " typlen " = $2
3737 """
@@ -46,7 +46,7 @@ class PostgreSQLConnectionTests: XCTestCase {
4646 }
4747
4848 func testTypes( ) throws {
49- let client = try PostgreSQLConnection . makeTest ( )
49+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
5050 let createQuery = """
5151 create table kitchen_sink (
5252 " smallint " smallint,
@@ -139,7 +139,7 @@ class PostgreSQLConnectionTests: XCTestCase {
139139 }
140140
141141 func testParameterizedTypes( ) throws {
142- let client = try PostgreSQLConnection . makeTest ( )
142+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
143143 let createQuery = """
144144 create table kitchen_sink (
145145 " smallint " smallint,
@@ -262,7 +262,7 @@ class PostgreSQLConnectionTests: XCTestCase {
262262 var message : String
263263 }
264264
265- let client = try PostgreSQLConnection . makeTest ( )
265+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
266266 _ = try client. query ( " drop table if exists foo; " ) . wait ( )
267267 let createResult = try client. query ( " create table foo (id integer, dict jsonb); " ) . wait ( )
268268 XCTAssertEqual ( createResult. count, 0 )
@@ -282,7 +282,7 @@ class PostgreSQLConnectionTests: XCTestCase {
282282 }
283283
284284 func testNull( ) throws {
285- let client = try PostgreSQLConnection . makeTest ( )
285+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
286286 _ = try client. query ( " drop table if exists nulltest; " ) . wait ( )
287287 let createResult = try client. query ( " create table nulltest (i integer not null, d timestamp); " ) . wait ( )
288288 XCTAssertEqual ( createResult. count, 0 )
@@ -297,7 +297,7 @@ class PostgreSQLConnectionTests: XCTestCase {
297297
298298 func testGH24( ) throws {
299299 /// PREPARE
300- let client = try PostgreSQLConnection . makeTest ( )
300+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
301301 _ = try client. query ( """
302302 DROP TABLE IF EXISTS " acronym+category "
303303 """ ) . wait ( )
@@ -448,7 +448,7 @@ class PostgreSQLConnectionTests: XCTestCase {
448448 var count : Int
449449 }
450450
451- let connection = try PostgreSQLConnection . makeTest ( )
451+ let connection = try PostgreSQLConnection . makeTest ( transport : . cleartext )
452452 _ = try connection. simpleQuery ( " DROP TABLE IF EXISTS apps " ) . wait ( )
453453 _ = try connection. simpleQuery ( " CREATE TABLE apps (id INT, platform TEXT, identifier TEXT) " ) . wait ( )
454454 _ = try connection. simpleQuery ( " INSERT INTO apps VALUES (1, 'a', 'b') " ) . wait ( )
@@ -486,24 +486,16 @@ class PostgreSQLConnectionTests: XCTestCase {
486486}
487487
488488extension PostgreSQLConnection {
489- /// Creates a test event loop and psql client.
490- static func makeTest( ) throws -> PostgreSQLConnection {
491- #if Xcode
492- return try _makeTest ( hostname: self . dockerMachineHostname)
493- #else
494- return try _makeTest ( hostname: " localhost " )
495- #endif
496- }
497-
498489 /// Creates a test event loop and psql client over ssl.
499490 static func makeTest( transport: PostgreSQLTransportConfig ) throws -> PostgreSQLConnection {
500- #if Xcode
501- return try _makeTest ( hostname: self . dockerMachineHostname , port: 5433 , transport: transport)
491+ #if os(macOS)
492+ return try _makeTest ( hostname: " 192.168.99.100 " , password : " vapor_password " , port: transport . isTLS ? 5433 : 5432 , transport: transport)
502493 #else
503- return try _makeTest ( hostname: " localhost-ssl " , password: " vapor_password " , transport: transport)
494+ return try _makeTest ( hostname: transport . isTLS ? " tls " : " cleartext " , password: " vapor_password " , transport: transport)
504495 #endif
505496 }
506-
497+
498+ /// Creates a test connection.
507499 private static func _makeTest( hostname: String , password: String ? = nil , port: Int = 5432 , transport: PostgreSQLTransportConfig = . cleartext) throws -> PostgreSQLConnection {
508500 let group = MultiThreadedEventLoopGroup ( numThreads: 1 )
509501 let client = try PostgreSQLConnection . connect ( hostname: hostname, port: port, transport: transport, on: group) { error in
@@ -512,10 +504,6 @@ extension PostgreSQLConnection {
512504 _ = try client. authenticate ( username: " vapor_username " , database: " vapor_database " , password: password) . wait ( )
513505 return client
514506 }
515-
516- private static var dockerMachineHostname : String {
517- return ( try ? Process . execute ( " docker-machine " , " ip " ) ) ?? " 192.168.99.100 "
518- }
519507}
520508
521509func += < T> ( lhs: inout [ T ] , rhs: T ) {
0 commit comments