Skip to content
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

fix: add a default endpoint to the provider #68

Merged
merged 3 commits into from
Jan 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public struct ConfidenceClientOptions {
) {
self.credentials = credentials
self.timeout = timeout ?? 10.0
self.region = region ?? .europe
self.region = region ?? .global
}
}

Expand All @@ -186,9 +186,10 @@ public enum ConfidenceClientCredentials {
}
}

public enum ConfidenceRegion: String {
case europe = "eu"
case usa = "us"
public enum ConfidenceRegion {
case global
case europe
case usa
}

struct Sdk: Codable {
Expand Down
13 changes: 8 additions & 5 deletions Sources/ConfidenceProvider/Http/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ final class NetworkClient: HttpClient {
private let region: ConfidenceRegion

private var baseUrl: String {
let region = region.rawValue
let domain = "confidence.dev"
let resolveRoute = "/v1/flags"

return "https://resolver.\(region).\(domain)\(resolveRoute)"
switch region {
case .global:
return "https://resolver.confidence.dev/v1/flags"
case .europe:
return "https://resolver.eu.confidence.dev/v1/flags"
case .usa:
return "https://resolver.us.confidence.dev/v1/flags"
}
}

init(
Expand Down
16 changes: 8 additions & 8 deletions Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swiftlint:disable type_body_length

Check warning on line 1 in Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
// swiftlint:disable file_length
import Foundation
import OpenFeature
Expand Down Expand Up @@ -197,7 +197,7 @@

func testApply_multipleApplyCalls_batchTriggered() async throws {
// Given flag applier with http client that is offline
let httpClient = HttpClientMock(testMode: .error)
let httpClient = HttpClientMock(testMode: .offline)
let networkExpectation = self.expectation(description: "Waiting for batch trigger")
networkExpectation.expectedFulfillmentCount = 2
httpClient.expectation = networkExpectation
Expand Down Expand Up @@ -237,7 +237,7 @@
func testApply_multipleApplyCalls_sentSet() async throws {
// Given flag applier with http client that is offline
let cacheDataInteractor = CacheDataInteractor(cacheData: .empty())
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let networkExpectation = self.expectation(description: "Waiting for network call to complete")
networkExpectation.expectedFulfillmentCount = 2
offlineClient.expectation = networkExpectation
Expand Down Expand Up @@ -336,7 +336,7 @@
func testApply_previoslyStoredData_doesNotCleanAfterSendingFailure() throws {
// Given offline http client
// And storage that has previosly stored data (100 records, same token)
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let prefilledStorage = StorageMock()
let prefilledCache = try CacheDataUtility.prefilledCacheData(applyEventCount: 100)
try prefilledStorage.save(data: prefilledCache)
Expand All @@ -359,7 +359,7 @@

func testApplyOffline_storesOnDisk() async throws {
// Given offline http client and flag applier
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let applier = FlagApplierWithRetries(
httpClient: offlineClient, storage: storage, options: options, metadata: metadata, triggerBatch: false
)
Expand Down Expand Up @@ -388,7 +388,7 @@

func testApplyOffline_storesOnDisk_multipleTokens() async throws {
// Given offline http client and flag applier
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let applier = FlagApplierWithRetries(
httpClient: offlineClient, storage: storage, options: options, metadata: metadata, triggerBatch: false
)
Expand Down Expand Up @@ -416,7 +416,7 @@
func testApplyOffline_previoslyStoredData_storesOnDisk() async throws {
// Given flag applier set up with offline http client
// And storage that has previously stored 1 record
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let data = CacheData(resolveToken: "token0", flagName: "flag1", applyTime: Date(timeIntervalSince1970: 1000))
let prefilledStorage = try StorageMock(data: data)

Expand Down Expand Up @@ -453,7 +453,7 @@
func testApplyOffline_previoslyStoredData_100records() async throws {
// Given flag applier set up with offline http client
// And storage that has previously stored 100 records with different tokens
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let prefilledStorage = StorageMock()
let prefilledCache = try CacheDataUtility.prefilledCacheData(resolveEventCount: 100)
try prefilledStorage.save(data: prefilledCache)
Expand All @@ -477,7 +477,7 @@
func testApplyOffline_100applyCalls_sameToken() async throws {
// Given flag applier set up with offline http client
// And storage that has previously stored 100 records with same token
let offlineClient = HttpClientMock(testMode: .error)
let offlineClient = HttpClientMock(testMode: .offline)
let networkExpectation = self.expectation(description: "Waiting for networkRequest to be completed")

// Since we don't fail other requests when one request is failing
Expand Down
4 changes: 2 additions & 2 deletions Tests/ConfidenceProviderTests/Helpers/HttpClientMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class HttpClientMock: HttpClient {
enum TestMode {
case success
case failFirstChunk
case error
case offline
}

init(testMode: TestMode = .success) {
Expand Down Expand Up @@ -63,7 +63,7 @@ final class HttpClientMock: HttpClient {
} else {
return HttpClientResponse(response: HTTPURLResponse())
}
case .error:
case .offline:
throw HttpClientError.invalidResponse
}
}
Expand Down
Loading