@@ -8,7 +8,7 @@ import Core
8
8
class PostgreSQLConnectionTests : XCTestCase {
9
9
let defaultTimeout = 5.0
10
10
func testVersion( ) throws {
11
- let client = try PostgreSQLConnection . makeTest ( )
11
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
12
12
let results = try client. simpleQuery ( " SELECT version(); " ) . wait ( )
13
13
try XCTAssert ( results [ 0 ] . firstValue ( forColumn: " version " ) ? . decode ( String . self) . contains ( " 10. " ) == true )
14
14
}
@@ -20,7 +20,7 @@ class PostgreSQLConnectionTests: XCTestCase {
20
20
}
21
21
22
22
func testSelectTypes( ) throws {
23
- let client = try PostgreSQLConnection . makeTest ( )
23
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
24
24
let results = try client. query ( " select * from pg_type; " ) . wait ( )
25
25
if results. count > 350 {
26
26
let name = try results [ 128 ] . firstValue ( forColumn: " typname " ) ? . decode ( String . self)
@@ -31,7 +31,7 @@ class PostgreSQLConnectionTests: XCTestCase {
31
31
}
32
32
33
33
func testParse( ) throws {
34
- let client = try PostgreSQLConnection . makeTest ( )
34
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
35
35
let query = """
36
36
select * from " pg_type " where " typlen " = $1 or " typlen " = $2
37
37
"""
@@ -46,7 +46,7 @@ class PostgreSQLConnectionTests: XCTestCase {
46
46
}
47
47
48
48
func testTypes( ) throws {
49
- let client = try PostgreSQLConnection . makeTest ( )
49
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
50
50
let createQuery = """
51
51
create table kitchen_sink (
52
52
" smallint " smallint,
@@ -139,7 +139,7 @@ class PostgreSQLConnectionTests: XCTestCase {
139
139
}
140
140
141
141
func testParameterizedTypes( ) throws {
142
- let client = try PostgreSQLConnection . makeTest ( )
142
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
143
143
let createQuery = """
144
144
create table kitchen_sink (
145
145
" smallint " smallint,
@@ -262,7 +262,7 @@ class PostgreSQLConnectionTests: XCTestCase {
262
262
var message : String
263
263
}
264
264
265
- let client = try PostgreSQLConnection . makeTest ( )
265
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
266
266
_ = try client. query ( " drop table if exists foo; " ) . wait ( )
267
267
let createResult = try client. query ( " create table foo (id integer, dict jsonb); " ) . wait ( )
268
268
XCTAssertEqual ( createResult. count, 0 )
@@ -282,7 +282,7 @@ class PostgreSQLConnectionTests: XCTestCase {
282
282
}
283
283
284
284
func testNull( ) throws {
285
- let client = try PostgreSQLConnection . makeTest ( )
285
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
286
286
_ = try client. query ( " drop table if exists nulltest; " ) . wait ( )
287
287
let createResult = try client. query ( " create table nulltest (i integer not null, d timestamp); " ) . wait ( )
288
288
XCTAssertEqual ( createResult. count, 0 )
@@ -297,7 +297,7 @@ class PostgreSQLConnectionTests: XCTestCase {
297
297
298
298
func testGH24( ) throws {
299
299
/// PREPARE
300
- let client = try PostgreSQLConnection . makeTest ( )
300
+ let client = try PostgreSQLConnection . makeTest ( transport : . cleartext )
301
301
_ = try client. query ( """
302
302
DROP TABLE IF EXISTS " acronym+category "
303
303
""" ) . wait ( )
@@ -448,7 +448,7 @@ class PostgreSQLConnectionTests: XCTestCase {
448
448
var count : Int
449
449
}
450
450
451
- let connection = try PostgreSQLConnection . makeTest ( )
451
+ let connection = try PostgreSQLConnection . makeTest ( transport : . cleartext )
452
452
_ = try connection. simpleQuery ( " DROP TABLE IF EXISTS apps " ) . wait ( )
453
453
_ = try connection. simpleQuery ( " CREATE TABLE apps (id INT, platform TEXT, identifier TEXT) " ) . wait ( )
454
454
_ = try connection. simpleQuery ( " INSERT INTO apps VALUES (1, 'a', 'b') " ) . wait ( )
@@ -486,24 +486,16 @@ class PostgreSQLConnectionTests: XCTestCase {
486
486
}
487
487
488
488
extension 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
-
498
489
/// Creates a test event loop and psql client over ssl.
499
490
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)
502
493
#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)
504
495
#endif
505
496
}
506
-
497
+
498
+ /// Creates a test connection.
507
499
private static func _makeTest( hostname: String , password: String ? = nil , port: Int = 5432 , transport: PostgreSQLTransportConfig = . cleartext) throws -> PostgreSQLConnection {
508
500
let group = MultiThreadedEventLoopGroup ( numThreads: 1 )
509
501
let client = try PostgreSQLConnection . connect ( hostname: hostname, port: port, transport: transport, on: group) { error in
@@ -512,10 +504,6 @@ extension PostgreSQLConnection {
512
504
_ = try client. authenticate ( username: " vapor_username " , database: " vapor_database " , password: password) . wait ( )
513
505
return client
514
506
}
515
-
516
- private static var dockerMachineHostname : String {
517
- return ( try ? Process . execute ( " docker-machine " , " ip " ) ) ?? " 192.168.99.100 "
518
- }
519
507
}
520
508
521
509
func += < T> ( lhs: inout [ T ] , rhs: T ) {
0 commit comments