Skip to content

Commit f527a7b

Browse files
committed
Update multiprovider name and FirstMatchStrategy to FirstFoundStrategy
Signed-off-by: jescriba <joshua.escribano@includedhealth.com>
1 parent a74e30f commit f527a7b

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

Sources/OpenFeature/Provider/MultiProvider/FirstMatchStrategy.swift renamed to Sources/OpenFeature/Provider/MultiProvider/FirstFoundStrategy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/// FirstMatchStrategy is a strategy that evaluates a feature flag across multiple providers
1+
/// FirstFoundStrategy (FirstMatchStrategy) is a strategy that evaluates a feature flag across multiple providers
22
/// and returns the first result. Skips providers that indicate they had no value due to flag not found.
33
/// If any provider returns an error result other than flag not found, the error is returned.
4-
final public class FirstMatchStrategy: Strategy {
4+
final public class FirstFoundStrategy: Strategy {
55
public init() {}
66

77
public func evaluate<T>(

Sources/OpenFeature/Provider/MultiProvider/FirstSuccessfulStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// FirstSuccessfulStrategy is a strategy that evaluates a feature flag across multiple providers
2-
/// and returns the first result. Similar to `FirstMatchStrategy` but does not bubble up individual provider errors.
2+
/// and returns the first result. Similar to `FirstFoundStrategy` but does not bubble up individual provider errors.
33
/// If no provider successfully responds, it will return an error.
44
final public class FirstSuccessfulStrategy: Strategy {
55
public func evaluate<T>(

Sources/OpenFeature/Provider/MultiProvider/MultiProvider.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ public class MultiProvider: FeatureProvider {
88
}
99

1010
public static let name = "MultiProvider"
11-
public var metadata: ProviderMetadata = MultiProvider.MultiProviderMetadata()
11+
public var metadata: ProviderMetadata
1212

1313
private let providers: [FeatureProvider]
1414
private let strategy: Strategy
1515

1616
/// Initialize a MultiProvider with a list of providers and a strategy.
1717
/// - Parameters:
1818
/// - providers: A list of providers to evaluate.
19-
/// - strategy: A strategy to evaluate the providers. Defaults to FirstMatchStrategy.
19+
/// - strategy: A strategy to evaluate the providers. Defaults to FirstFoundStrategy.
2020
public init(
2121
providers: [FeatureProvider],
22-
strategy: Strategy = FirstMatchStrategy()
22+
strategy: Strategy = FirstFoundStrategy()
2323
) {
2424
self.providers = providers
2525
self.strategy = strategy
26+
self.metadata = MultiProviderMetadata(providers: providers)
2627
}
2728

2829
public func initialize(initialContext: EvaluationContext?) async throws {
@@ -117,6 +118,12 @@ public class MultiProvider: FeatureProvider {
117118
}
118119

119120
public struct MultiProviderMetadata: ProviderMetadata {
120-
public var name: String? = MultiProvider.name
121+
public var name: String?
122+
123+
init(providers: [FeatureProvider]) {
124+
self.name = providers.map({
125+
$0.metadata.name ?? "MultiProvider"
126+
}).joined(separator: ", ")
127+
}
121128
}
122129
}

Tests/OpenFeatureTests/MultiProviderTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class MultiProviderTests: XCTestCase {
4545
XCTAssertEqual(objectResult.value, mockProviderObjectValue)
4646
}
4747

48-
func testEvaluationWithMultipleProvidersAndFirstMatchStrategy_FirstProviderHasFlag() throws {
48+
func testEvaluationWithMultipleProvidersAndFirstFoundStrategy_FirstProviderHasFlag() throws {
4949
let mockKey = "test-key"
5050
let mockProvider1Value = true
5151
let mockProvider1 = MockProvider(
@@ -58,15 +58,15 @@ final class MultiProviderTests: XCTestCase {
5858
)
5959
let multiProvider = MultiProvider(
6060
providers: [mockProvider1, mockProvider2],
61-
strategy: FirstMatchStrategy()
61+
strategy: FirstFoundStrategy()
6262
)
6363

6464
let boolResult = try multiProvider.getBooleanEvaluation(
6565
key: mockKey, defaultValue: false, context: MutableContext())
6666
XCTAssertEqual(boolResult.value, mockProvider1Value)
6767
}
6868

69-
func testEvaluationWithMultipleProvidersAndFirstMatchStrategy_FlagNotFound() throws {
69+
func testEvaluationWithMultipleProvidersAndFirstFoundStrategy_FlagNotFound() throws {
7070
let mockKey = "test-key"
7171
let mockProviderValue = true
7272
let mockProvider1 = MockProvider(
@@ -87,15 +87,15 @@ final class MultiProviderTests: XCTestCase {
8787
)
8888
let multiProvider = MultiProvider(
8989
providers: [mockProvider1, mockProvider2],
90-
strategy: FirstMatchStrategy()
90+
strategy: FirstFoundStrategy()
9191
)
9292

9393
let boolResult = try multiProvider.getBooleanEvaluation(
9494
key: mockKey, defaultValue: false, context: MutableContext())
9595
XCTAssertEqual(boolResult.value, mockProviderValue)
9696
}
9797

98-
func testEvaluationWithMultipleProvidersAndFirstMatchStrategy_AllProvidersMissingFlag() throws {
98+
func testEvaluationWithMultipleProvidersAndFirstFoundStrategy_AllProvidersMissingFlag() throws {
9999
let mockKey = "test-key"
100100
let mockProvider1 = MockProvider(
101101
initialize: { _ in },
@@ -109,7 +109,7 @@ final class MultiProviderTests: XCTestCase {
109109
)
110110
let multiProvider = MultiProvider(
111111
providers: [mockProvider1, mockProvider2],
112-
strategy: FirstMatchStrategy()
112+
strategy: FirstFoundStrategy()
113113
)
114114

115115
let result = try multiProvider.getBooleanEvaluation(
@@ -120,7 +120,7 @@ final class MultiProviderTests: XCTestCase {
120120
XCTAssertTrue(result.errorCode == .flagNotFound)
121121
}
122122

123-
func testEvaluationWithMultipleProvidersAndFirstMatchStrategy_HandlesOpenFeatureError() throws {
123+
func testEvaluationWithMultipleProvidersAndFirstFoundStrategy_HandlesOpenFeatureError() throws {
124124
let mockKey = "test-key"
125125
let mockProvider1 = MockProvider(
126126
initialize: { _ in },
@@ -136,7 +136,7 @@ final class MultiProviderTests: XCTestCase {
136136
)
137137
let multiProvider = MultiProvider(
138138
providers: [mockProvider1, mockProvider2],
139-
strategy: FirstMatchStrategy()
139+
strategy: FirstFoundStrategy()
140140
)
141141
let defaultValue = false
142142
let result = try multiProvider.getBooleanEvaluation(
@@ -145,7 +145,7 @@ final class MultiProviderTests: XCTestCase {
145145
XCTAssertNotNil(result.errorCode)
146146
}
147147

148-
func testEvaluationWithMultipleProvidersAndFirstMatchStrategy_Throws() throws {
148+
func testEvaluationWithMultipleProvidersAndFirstFoundStrategy_Throws() throws {
149149
let mockKey = "test-key"
150150
let mockError = MockProvider.MockProviderError.message("test non-open feature error")
151151
let mockProvider1 = MockProvider(
@@ -162,7 +162,7 @@ final class MultiProviderTests: XCTestCase {
162162
)
163163
let multiProvider = MultiProvider(
164164
providers: [mockProvider1, mockProvider2],
165-
strategy: FirstMatchStrategy()
165+
strategy: FirstFoundStrategy()
166166
)
167167
let defaultValue = false
168168
do {

0 commit comments

Comments
 (0)