Skip to content

Commit

Permalink
chore: use enums to namespace prebuilt configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Nov 14, 2023
1 parent 8a40df4 commit 0617ec0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
24 changes: 17 additions & 7 deletions Sources/momento/config/TopicConfigurations.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// Prebuilt configurations for Momento Topics clients

public class Default: TopicClientConfiguration {
static func latest() -> TopicClientConfiguration {
return TopicClientConfiguration(
loggerFactory: DefaultMomentoLoggerFactory(),
transportStrategy: StaticTransportStrategy(
grpcConfig: StaticGrpcConfiguration(deadline: 15.0)
enum TopicConfigurations {

enum Default {

static func latest() -> TopicClientConfiguration {
return TopicClientConfiguration(
loggerFactory: DefaultMomentoLoggerFactory(),
transportStrategy: StaticTransportStrategy(
grpcConfig: StaticGrpcConfiguration(deadline: 15.0)
)
)
)
}

static func v1() -> TopicClientConfiguration {
return latest()
}

}

}
9 changes: 6 additions & 3 deletions Tests/client-sdk-swiftTests/client_sdk_swiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ final class client_sdk_swiftTests: XCTestCase {

func testTopicClientPublishes() async throws {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
let client = TopicClient(configuration: Default.latest(), credentialProvider: creds)
let client = TopicClient(
configuration: TopicConfigurations.Default.latest(),
credentialProvider: creds
)
XCTAssertNotNil(client)

let invalidCacheNameResp = await client.publish(
Expand Down Expand Up @@ -58,7 +61,7 @@ final class client_sdk_swiftTests: XCTestCase {

func testTopicClientSubscribes() async throws {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
let client = TopicClient(configuration: Default.latest(), credentialProvider: creds)
let client = TopicClient(configuration: TopicConfigurations.Default.latest(), credentialProvider: creds)
XCTAssertNotNil(client)

let invalidCacheNameResp = await client.subscribe(
Expand Down Expand Up @@ -101,7 +104,7 @@ final class client_sdk_swiftTests: XCTestCase {

func testTopicClientPublishesAndSubscribes() async throws {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
let client = TopicClient(configuration: Default.latest(), credentialProvider: creds)
let client = TopicClient(configuration: TopicConfigurations.Default.latest(), credentialProvider: creds)
XCTAssertNotNil(client)

let subResp = await client.subscribe(
Expand Down
7 changes: 5 additions & 2 deletions Tests/client-sdk-swiftTests/configTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ final class configTests: XCTestCase {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
XCTAssertNotNil(creds)

let client = TopicClient(configuration: Default.latest(), credentialProvider: creds)
let client = TopicClient(
configuration: TopicConfigurations.Default.latest(),
credentialProvider: creds
)
XCTAssertNotNil(client)
}

Expand All @@ -22,7 +25,7 @@ final class configTests: XCTestCase {

func testTimeoutForImpossibleDeadline() async throws {
let creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
let configuration = Default.latest().withClientTimeout(timeout: 0.001)
let configuration = TopicConfigurations.Default.latest().withClientTimeout(timeout: 0.001)
let client = TopicClient(configuration: configuration, credentialProvider: creds)
// TODO: use test framework's setup and teardown methods to create and delete caches for use with tests
let pubResp = await client.publish(
Expand Down

0 comments on commit 0617ec0

Please sign in to comment.