Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 10 additions & 3 deletions Sources/GoogleCloudBase/GCPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ public struct GCPClient: Sendable {
(httpClient, httpClientCompressionEnabled) = httpClientProvider.build(logger: clientLogger)
self.clientLogger = clientLogger
self.options = options
self.credential = try await credentialFactory.makeCredential(
context: .init(httpClient: httpClient, logger: clientLogger)
)
do {
self.credential = try await credentialFactory.makeCredential(
context: .init(httpClient: httpClient, logger: clientLogger)
)
} catch {
Task { [httpClient, httpClientProvider] in
try await Self.shutdownHTTPClient(client: httpClient, provider: httpClientProvider)
}
throw error
}
}

@available(*, noasync, message: "syncShutdown() can block indefinitely, prefer shutdown()", renamed: "shutdown()")
Expand Down
23 changes: 23 additions & 0 deletions Tests/SharedTests/Core/GCPClientTest.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import GoogleCloudBase
import Testing

@Suite struct GCPClientTest {
enum MyError: Error {
case failure
}

@Test func makeCredentialFailed() async {
// sync
#expect(throws: MyError.self) {
_ = try GCPClient(credentialFactory: SyncCredentialFactory.custom { _ in
throw MyError.failure
})
}

// async
await #expect(throws: MyError.self) {
_ = try await GCPClient(credentialFactory: AsyncCredentialFactory.custom { _ in
throw MyError.failure
})
}
}
}

func gcpClientOverload() throws {
_ = try GCPClient(credentialFactory: .selector(.environment, .configFile))
Expand Down