Skip to content

Commit bcbf90c

Browse files
authored
Merge pull request #48 from vapor/fix-gh-46
add test for #46
2 parents 0d3099f + af0e05e commit bcbf90c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,33 @@ class PostgreSQLConnectionTests: XCTestCase {
440440
XCTAssertEqual(config.database, "database")
441441
}
442442

443+
// https://github.com/vapor/postgresql/issues/46
444+
func testGH46() throws {
445+
struct Overview {
446+
var platform: String
447+
var identifier: String
448+
var count: Int
449+
}
450+
451+
let connection = try PostgreSQLConnection.makeTest()
452+
_ = try connection.simpleQuery("DROP TABLE IF EXISTS apps").wait()
453+
_ = try connection.simpleQuery("CREATE TABLE apps (id INT, platform TEXT, identifier TEXT)").wait()
454+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (1, 'a', 'b')").wait()
455+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (2, 'c', 'd')").wait()
456+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (3, 'a', 'd')").wait()
457+
_ = try connection.simpleQuery("INSERT INTO apps VALUES (4, 'a', 'b')").wait()
458+
let overviews = try connection.query("SELECT platform, identifier, COUNT(id) as count FROM apps GROUP BY platform, identifier").map(to: [Overview].self) { data in
459+
return try data.map { row in
460+
return try Overview(
461+
platform: row.firstValue(forColumn: "platform")!.decode(String.self),
462+
identifier: row.firstValue(forColumn: "identifier")!.decode(String.self),
463+
count: row.firstValue(forColumn: "count")!.decode(Int.self)
464+
)
465+
}
466+
}.wait()
467+
XCTAssertEqual(overviews.count, 3)
468+
}
469+
443470
static var allTests = [
444471
("testUnverifiedSSLConnection", testUnverifiedSSLConnection),
445472
("testVersion", testVersion),
@@ -454,6 +481,7 @@ class PostgreSQLConnectionTests: XCTestCase {
454481
// ("testNotifyAndListenOnMultipleChannels", testNotifyAndListenOnMultipleChannels),
455482
// ("testUnlisten", testUnlisten),
456483
("testURLParsing", testURLParsing),
484+
("testGH46", testGH46),
457485
]
458486
}
459487

0 commit comments

Comments
 (0)