Skip to content

Actually use additional parameters #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/PostgresNIO/New/PostgresChannelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ final class PostgresChannelHandler: ChannelDuplexHandler {
let authContext = AuthContext(
username: username,
password: self.configuration.password,
database: self.configuration.database
database: self.configuration.database,
additionalParameters: self.configuration.options.additionalStartupParameters
)
let action = self.state.provideAuthenticationContext(authContext)
return self.run(action, with: context)
Expand Down
15 changes: 15 additions & 0 deletions Tests/IntegrationTests/PostgresNIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ final class PostgresNIOTests: XCTestCase {
XCTAssertEqual(try rows?.first?.decode(String.self, context: .default).contains("PostgreSQL"), true)
}

func testSimpleQueryWithAdditionalParameters() throws {
var conn: PostgresConnection?
let applicationName = "postgres-nio-test"
var options = PostgresConnection.Configuration.Options()
options.additionalStartupParameters = [
("application_name", applicationName)
]
XCTAssertNoThrow(conn = try PostgresConnection.test(on: eventLoop, options: options).wait())
defer { XCTAssertNoThrow( try conn?.close().wait() ) }
var rows: [PostgresRow]?
XCTAssertNoThrow(rows = try conn?.simpleQuery("SELECT current_setting('application_name')").wait())
XCTAssertEqual(rows?.count, 1)
XCTAssertEqual(try rows?.first?.decode(String.self, context: .default), applicationName)
}

func testSimpleQueryVersionUsingUDS() throws {
try XCTSkipUnless(env("POSTGRES_SOCKET") != nil)
var conn: PostgresConnection?
Expand Down
21 changes: 12 additions & 9 deletions Tests/IntegrationTests/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension PostgresConnection {
static func address() throws -> SocketAddress {
try .makeAddressResolvingHost(env("POSTGRES_HOSTNAME") ?? "localhost", port: env("POSTGRES_PORT").flatMap(Int.init(_:)) ?? 5432)
}

@available(*, deprecated, message: "Test deprecated functionality")
static func testUnauthenticated(on eventLoop: EventLoop, logLevel: Logger.Level = .info) -> EventLoopFuture<PostgresConnection> {
var logger = Logger(label: "postgres.connection.test")
Expand All @@ -24,20 +24,23 @@ extension PostgresConnection {
}
}

static func test(on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
static func test(on eventLoop: EventLoop, options: Configuration.Options? = nil) -> EventLoopFuture<PostgresConnection> {
let logger = Logger(label: "postgres.connection.test")
let config = PostgresConnection.Configuration(
var config = PostgresConnection.Configuration(
host: env("POSTGRES_HOSTNAME") ?? "localhost",
port: env("POSTGRES_PORT").flatMap(Int.init(_:)) ?? 5432,
username: env("POSTGRES_USER") ?? "test_username",
password: env("POSTGRES_PASSWORD") ?? "test_password",
database: env("POSTGRES_DB") ?? "test_database",
tls: .disable
)
if let options {
config.options = options
}

return PostgresConnection.connect(on: eventLoop, configuration: config, id: 0, logger: logger)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just my Xcode settings ... not sure what to do?

static func testUDS(on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
let logger = Logger(label: "postgres.connection.test")
let config = PostgresConnection.Configuration(
Expand All @@ -46,10 +49,10 @@ extension PostgresConnection {
password: env("POSTGRES_PASSWORD") ?? "test_password",
database: env("POSTGRES_DB") ?? "test_database"
)

return PostgresConnection.connect(on: eventLoop, configuration: config, id: 0, logger: logger)
}

static func testChannel(_ channel: Channel, on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
let logger = Logger(label: "postgres.connection.test")
let config = PostgresConnection.Configuration(
Expand All @@ -58,7 +61,7 @@ extension PostgresConnection {
password: env("POSTGRES_PASSWORD") ?? "test_password",
database: env("POSTGRES_DB") ?? "test_database"
)

return PostgresConnection.connect(on: eventLoop, configuration: config, id: 0, logger: logger)
}
}
Expand All @@ -74,7 +77,7 @@ func env(_ name: String) -> String? {
}

extension XCTestCase {

public static var shouldRunLongRunningTests: Bool {
// The env var must be set and have the value `"true"`, `"1"`, or `"yes"` (case-insensitive).
// For the sake of sheer annoying pedantry, values like `"2"` are treated as false.
Expand All @@ -83,7 +86,7 @@ extension XCTestCase {
if let intValue = Int(rawValue) { return intValue == 1 }
return rawValue.lowercased() == "yes"
}

public static var shouldRunPerformanceTests: Bool {
// Same semantics as above. Any present non-truthy value will explicitly disable performance
// tests even if they would've overwise run in the current configuration.
Expand Down
Loading