diff --git a/Sources/YMFF/FeatureFlagResolver/FeatureFlagResolver.swift b/Sources/YMFF/FeatureFlagResolver/FeatureFlagResolver.swift index b812bd0..ad5f1d1 100644 --- a/Sources/YMFF/FeatureFlagResolver/FeatureFlagResolver.swift +++ b/Sources/YMFF/FeatureFlagResolver/FeatureFlagResolver.swift @@ -164,11 +164,16 @@ extension FeatureFlagResolver { } for store in matchingStores { - if await store.containsValue(forKey: key) { - do { - let value: Value = try await store.value(forKey: key) - return value - } catch { + switch await store.value(forKey: key) as Result { + case .success(let value): + return value + case .failure(let error): + switch error { + case .valueNotFound: + continue + case .typeMismatch: + throw Error.storeError(error) + case .otherError(let error): throw Error.storeError(error) } } @@ -184,11 +189,16 @@ extension FeatureFlagResolver { } for store in matchingStores { - if store.containsValueSync(forKey: key) { - do { - let value: Value = try store.valueSync(forKey: key) - return value - } catch { + switch store.valueSync(forKey: key) as Result { + case .success(let value): + return value + case .failure(let error): + switch error { + case .valueNotFound: + continue + case .typeMismatch: + throw Error.storeError(error) + case .otherError(let error): throw Error.storeError(error) } } diff --git a/Sources/YMFF/FeatureFlagResolver/Store/CommonFeatureFlagStoreError.swift b/Sources/YMFF/FeatureFlagResolver/Store/CommonFeatureFlagStoreError.swift deleted file mode 100644 index e38f625..0000000 --- a/Sources/YMFF/FeatureFlagResolver/Store/CommonFeatureFlagStoreError.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// CommonFeatureFlagStoreError.swift -// YMFF -// -// Created by Yakov Manshin on 5/7/24. -// Copyright © 2024 Yakov Manshin. See the LICENSE file for license info. -// - -enum CommonFeatureFlagStoreError: Error { - case valueNotFound(key: String) - case typeMismatch -} diff --git a/Sources/YMFF/FeatureFlagResolver/Store/RuntimeOverridesStore.swift b/Sources/YMFF/FeatureFlagResolver/Store/RuntimeOverridesStore.swift index 7d77847..67580e4 100644 --- a/Sources/YMFF/FeatureFlagResolver/Store/RuntimeOverridesStore.swift +++ b/Sources/YMFF/FeatureFlagResolver/Store/RuntimeOverridesStore.swift @@ -27,14 +27,10 @@ final public class RuntimeOverridesStore { extension RuntimeOverridesStore: SynchronousMutableFeatureFlagStore { - public func containsValueSync(forKey key: String) -> Bool { - store[key] != nil - } - - public func valueSync(forKey key: String) throws -> Value { - guard let anyValue = store[key] else { throw CommonFeatureFlagStoreError.valueNotFound(key: key) } - guard let value = anyValue as? Value else { throw CommonFeatureFlagStoreError.typeMismatch } - return value + public func valueSync(forKey key: String) -> Result { + guard let anyValue = store[key] else { return .failure(.valueNotFound) } + guard let value = anyValue as? Value else { return .failure(.typeMismatch) } + return .success(value) } public func setValueSync(_ value: Value, forKey key: String) { diff --git a/Sources/YMFF/FeatureFlagResolver/Store/TransparentFeatureFlagStore.swift b/Sources/YMFF/FeatureFlagResolver/Store/TransparentFeatureFlagStore.swift index a2b0cf9..e90cc86 100644 --- a/Sources/YMFF/FeatureFlagResolver/Store/TransparentFeatureFlagStore.swift +++ b/Sources/YMFF/FeatureFlagResolver/Store/TransparentFeatureFlagStore.swift @@ -19,14 +19,10 @@ public typealias TransparentFeatureFlagStore = [String: Any] extension TransparentFeatureFlagStore: SynchronousFeatureFlagStore, FeatureFlagStore { - public func containsValueSync(forKey key: String) -> Bool { - self[key] != nil - } - - public func valueSync(forKey key: String) throws -> V { - guard let anyValue = self[key] else { throw CommonFeatureFlagStoreError.valueNotFound(key: key) } - guard let value = anyValue as? V else { throw CommonFeatureFlagStoreError.typeMismatch } - return value + public func valueSync(forKey key: String) -> Result { + guard let anyValue = self[key] else { return .failure(.valueNotFound) } + guard let value = anyValue as? V else { return .failure(.typeMismatch) } + return .success(value) } } diff --git a/Sources/YMFF/FeatureFlagResolver/Store/UserDefaultsStore.swift b/Sources/YMFF/FeatureFlagResolver/Store/UserDefaultsStore.swift index ff54ee9..2fca995 100644 --- a/Sources/YMFF/FeatureFlagResolver/Store/UserDefaultsStore.swift +++ b/Sources/YMFF/FeatureFlagResolver/Store/UserDefaultsStore.swift @@ -34,16 +34,10 @@ final public class UserDefaultsStore { extension UserDefaultsStore: SynchronousMutableFeatureFlagStore { - public func containsValueSync(forKey key: String) -> Bool { - userDefaults.object(forKey: key) != nil - } - - public func valueSync(forKey key: String) throws -> Value { - guard let anyValue = userDefaults.object(forKey: key) else { - throw CommonFeatureFlagStoreError.valueNotFound(key: key) - } - guard let value = anyValue as? Value else { throw CommonFeatureFlagStoreError.typeMismatch } - return value + public func valueSync(forKey key: String) -> Result { + guard let anyValue = userDefaults.object(forKey: key) else { return .failure(.valueNotFound) } + guard let value = anyValue as? Value else { return .failure(.typeMismatch) } + return .success(value) } public func setValueSync(_ value: Value, forKey key: String) { diff --git a/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStore.swift b/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStore.swift index e24dc94..6d87ec6 100644 --- a/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStore.swift +++ b/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStore.swift @@ -9,14 +9,9 @@ /// An object that stores feature flag values, and provides them at the resolver's request. public protocol FeatureFlagStore { - /// Indicates whether the store contains a value that corresponds to the key. - /// - /// - Parameter key: *Required.* The key. - func containsValue(forKey key: String) async -> Bool - /// Retrieves a feature flag value by its key. /// /// - Parameter key: *Required.* The key that points to a feature flag value in the store. - func value(forKey key: String) async throws -> Value + func value(forKey key: String) async -> Result } diff --git a/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStoreError.swift b/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStoreError.swift new file mode 100644 index 0000000..1695e90 --- /dev/null +++ b/Sources/YMFFProtocols/FeatureFlagResolver/Store/FeatureFlagStoreError.swift @@ -0,0 +1,13 @@ +// +// FeatureFlagStore.swift +// YMFFProtocols +// +// Created by Yakov Manshin on 5/11/24. +// Copyright © 2024 Yakov Manshin. See the LICENSE file for license info. +// + +public enum FeatureFlagStoreError: Error { + case valueNotFound + case typeMismatch + case otherError(any Error) +} diff --git a/Sources/YMFFProtocols/FeatureFlagResolver/Store/SynchronousFeatureFlagStore.swift b/Sources/YMFFProtocols/FeatureFlagResolver/Store/SynchronousFeatureFlagStore.swift index 3fbd1e7..cf4dc4d 100644 --- a/Sources/YMFFProtocols/FeatureFlagResolver/Store/SynchronousFeatureFlagStore.swift +++ b/Sources/YMFFProtocols/FeatureFlagResolver/Store/SynchronousFeatureFlagStore.swift @@ -8,15 +8,10 @@ public protocol SynchronousFeatureFlagStore: FeatureFlagStore { - /// Indicates whether the store contains a value that corresponds to the key. - /// - /// - Parameter key: *Required.* The key. - func containsValueSync(forKey key: String) -> Bool - /// Retrieves a feature flag value by its key. /// /// - Parameter key: *Required.* The key that points to a feature flag value in the store. - func valueSync(forKey key: String) throws -> Value + func valueSync(forKey key: String) -> Result } @@ -24,12 +19,8 @@ public protocol SynchronousFeatureFlagStore: FeatureFlagStore { extension SynchronousFeatureFlagStore { - public func containsValue(forKey key: String) async -> Bool { - containsValueSync(forKey: key) - } - - public func value(forKey key: String) async throws -> Value { - try valueSync(forKey: key) + public func value(forKey key: String) async -> Result { + valueSync(forKey: key) } } diff --git a/Tests/YMFFTests/Cases/FeatureFlagResolverTests.swift b/Tests/YMFFTests/Cases/FeatureFlagResolverTests.swift index ab2f397..003df45 100644 --- a/Tests/YMFFTests/Cases/FeatureFlagResolverTests.swift +++ b/Tests/YMFFTests/Cases/FeatureFlagResolverTests.swift @@ -80,7 +80,6 @@ final class FeatureFlagResolverTests: XCTestCase { let _: String = try resolver.valueSync(for: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.noStoreAvailable { - XCTAssertEqual(store.containsValue_invocationCount, 0) XCTAssertEqual(store.value_invocationCount, 0) } catch { XCTFail("Unexpected error: \(error)") @@ -91,19 +90,17 @@ final class FeatureFlagResolverTests: XCTestCase { let store1 = FeatureFlagStoreMock() let store2 = FeatureFlagStoreMock() configuration.stores = [store1, store2] - store1.containsValue_returnValue = false - store2.containsValue_returnValue = false + store1.value_result = .failure(.valueNotFound) + store2.value_result = .failure(.valueNotFound) do { let _: String = try await resolver.value(for: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.valueNotFoundInStores { - XCTAssertEqual(store1.containsValue_invocationCount, 1) - XCTAssertEqual(store1.containsValue_keys, ["TEST_key1"]) - XCTAssertEqual(store1.value_invocationCount, 0) - XCTAssertEqual(store2.containsValue_invocationCount, 1) - XCTAssertEqual(store2.containsValue_keys, ["TEST_key1"]) - XCTAssertEqual(store2.value_invocationCount, 0) + XCTAssertEqual(store1.value_invocationCount, 1) + XCTAssertEqual(store1.value_keys, ["TEST_key1"]) + XCTAssertEqual(store2.value_invocationCount, 1) + XCTAssertEqual(store2.value_keys, ["TEST_key1"]) } catch { XCTFail("Unexpected error: \(error)") } @@ -113,19 +110,17 @@ final class FeatureFlagResolverTests: XCTestCase { let store1 = SynchronousFeatureFlagStoreMock() let store2 = SynchronousFeatureFlagStoreMock() configuration.stores = [store1, store2] - store1.containsValueSync_returnValue = false - store2.containsValueSync_returnValue = false + store1.valueSync_result = .failure(.valueNotFound) + store2.valueSync_result = .failure(.valueNotFound) do { let _: String = try resolver.valueSync(for: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.valueNotFoundInStores { - XCTAssertEqual(store1.containsValueSync_invocationCount, 1) - XCTAssertEqual(store1.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValueSync_invocationCount, 1) - XCTAssertEqual(store2.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store1.valueSync_invocationCount, 0) - XCTAssertEqual(store2.valueSync_invocationCount, 0) + XCTAssertEqual(store1.valueSync_invocationCount, 1) + XCTAssertEqual(store1.valueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store2.valueSync_invocationCount, 1) + XCTAssertEqual(store2.valueSync_keys, ["TEST_key1"]) } catch { XCTFail("Unexpected error: \(error)") } @@ -135,18 +130,14 @@ final class FeatureFlagResolverTests: XCTestCase { let store1 = FeatureFlagStoreMock() let store2 = FeatureFlagStoreMock() configuration.stores = [store1, store2] - store1.containsValue_returnValue = false - store2.containsValue_returnValue = true + store1.value_result = .failure(.valueNotFound) store2.value_result = .success("TEST_value2") do { let value: String = try await resolver.value(for: "TEST_key1") - XCTAssertEqual(store1.containsValue_invocationCount, 1) - XCTAssertEqual(store1.containsValue_keys, ["TEST_key1"]) - XCTAssertEqual(store1.value_invocationCount, 0) - XCTAssertEqual(store2.containsValue_invocationCount, 1) - XCTAssertEqual(store2.containsValue_keys, ["TEST_key1"]) + XCTAssertEqual(store1.value_invocationCount, 1) + XCTAssertEqual(store1.value_keys, ["TEST_key1"]) XCTAssertEqual(store2.value_invocationCount, 1) XCTAssertEqual(store2.value_keys, ["TEST_key1"]) XCTAssertEqual(value, "TEST_value2") @@ -159,18 +150,14 @@ final class FeatureFlagResolverTests: XCTestCase { let store1 = SynchronousFeatureFlagStoreMock() let store2 = SynchronousFeatureFlagStoreMock() configuration.stores = [store1, store2] - store1.containsValueSync_returnValue = false - store2.containsValueSync_returnValue = true + store1.valueSync_result = .failure(.valueNotFound) store2.valueSync_result = .success("TEST_value2") do { let value: String = try resolver.valueSync(for: "TEST_key1") - XCTAssertEqual(store1.containsValueSync_invocationCount, 1) - XCTAssertEqual(store1.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store1.valueSync_invocationCount, 0) - XCTAssertEqual(store2.containsValueSync_invocationCount, 1) - XCTAssertEqual(store2.containsValueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store1.valueSync_invocationCount, 1) + XCTAssertEqual(store1.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store2.valueSync_invocationCount, 1) XCTAssertEqual(store2.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(value, "TEST_value2") @@ -184,22 +171,18 @@ final class FeatureFlagResolverTests: XCTestCase { let store2 = FeatureFlagStoreMock() let store3 = FeatureFlagStoreMock() configuration.stores = [store1, store2, store3] - store1.containsValue_returnValue = false - store2.containsValue_returnValue = true + store1.value_result = .failure(.valueNotFound) store2.value_result = .success("TEST_value2") - store3.containsValue_returnValue = true store3.value_result = .success("TEST_value3") do { let value: String = try await resolver.value(for: "TEST_key1") - XCTAssertEqual(store1.containsValue_invocationCount, 1) - XCTAssertEqual(store1.containsValue_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValue_invocationCount, 1) - XCTAssertEqual(store2.containsValue_keys, ["TEST_key1"]) + XCTAssertEqual(store1.value_invocationCount, 1) + XCTAssertEqual(store1.value_keys, ["TEST_key1"]) XCTAssertEqual(store2.value_invocationCount, 1) XCTAssertEqual(store2.value_keys, ["TEST_key1"]) - XCTAssertEqual(store3.containsValue_invocationCount, 0) + XCTAssertEqual(store3.value_invocationCount, 0) XCTAssertEqual(value, "TEST_value2") } catch { XCTFail("Unexpected error: \(error)") @@ -211,22 +194,18 @@ final class FeatureFlagResolverTests: XCTestCase { let store2 = SynchronousFeatureFlagStoreMock() let store3 = SynchronousFeatureFlagStoreMock() configuration.stores = [store1, store2, store3] - store1.containsValueSync_returnValue = false - store2.containsValueSync_returnValue = true + store1.valueSync_result = .failure(.valueNotFound) store2.valueSync_result = .success("TEST_value2") - store3.containsValueSync_returnValue = true store3.valueSync_result = .success("TEST_value3") do { let value: String = try resolver.valueSync(for: "TEST_key1") - XCTAssertEqual(store1.containsValueSync_invocationCount, 1) - XCTAssertEqual(store1.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValueSync_invocationCount, 1) - XCTAssertEqual(store2.containsValueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store1.valueSync_invocationCount, 1) + XCTAssertEqual(store1.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store2.valueSync_invocationCount, 1) XCTAssertEqual(store2.valueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store3.containsValueSync_invocationCount, 0) + XCTAssertEqual(store3.valueSync_invocationCount, 0) XCTAssertEqual(value, "TEST_value2") } catch { XCTFail("Unexpected error: \(error)") @@ -236,16 +215,12 @@ final class FeatureFlagResolverTests: XCTestCase { func test_value_typeMismatch() async { let store = FeatureFlagStoreMock() configuration.stores = [store] - store.containsValue_returnValue = true store.value_result = .success(123) do { let _: String = try await resolver.value(for: "TEST_key1") XCTFail("Expected an error") - } catch FeatureFlagResolver.Error.storeError(let error) { - XCTAssertEqual(error as? TestFeatureFlagStoreError, .typeMismatch) - XCTAssertEqual(store.containsValue_invocationCount, 1) - XCTAssertEqual(store.containsValue_keys, ["TEST_key1"]) + } catch FeatureFlagResolver.Error.storeError(FeatureFlagStoreError.typeMismatch) { XCTAssertEqual(store.value_invocationCount, 1) XCTAssertEqual(store.value_keys, ["TEST_key1"]) } catch { @@ -256,16 +231,12 @@ final class FeatureFlagResolverTests: XCTestCase { func test_valueSync_typeMismatch() { let store = SynchronousFeatureFlagStoreMock() configuration.stores = [store] - store.containsValueSync_returnValue = true store.valueSync_result = .success(123) do { let _: String = try resolver.valueSync(for: "TEST_key1") XCTFail("Expected an error") - } catch FeatureFlagResolver.Error.storeError(let error) { - XCTAssertEqual(error as? TestFeatureFlagStoreError, .typeMismatch) - XCTAssertEqual(store.containsValueSync_invocationCount, 1) - XCTAssertEqual(store.containsValueSync_keys, ["TEST_key1"]) + } catch FeatureFlagResolver.Error.storeError(FeatureFlagStoreError.typeMismatch) { XCTAssertEqual(store.valueSync_invocationCount, 1) XCTAssertEqual(store.valueSync_keys, ["TEST_key1"]) } catch { @@ -276,15 +247,12 @@ final class FeatureFlagResolverTests: XCTestCase { func test_value_optionalValue() async { let store = FeatureFlagStoreMock() configuration.stores = [store] - store.containsValue_returnValue = true store.value_result = .success((123 as Int?)!) do { let _: Int? = try await resolver.value(for: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.optionalValuesNotAllowed { - XCTAssertEqual(store.containsValue_invocationCount, 1) - XCTAssertEqual(store.containsValue_keys, ["TEST_key1"]) XCTAssertEqual(store.value_invocationCount, 1) XCTAssertEqual(store.value_keys, ["TEST_key1"]) } catch { @@ -295,15 +263,12 @@ final class FeatureFlagResolverTests: XCTestCase { func test_valueSync_optionalValue() { let store = SynchronousFeatureFlagStoreMock() configuration.stores = [store] - store.containsValueSync_returnValue = true store.valueSync_result = .success((123 as Int?)!) do { let _: Int? = try resolver.valueSync(for: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.optionalValuesNotAllowed { - XCTAssertEqual(store.containsValueSync_invocationCount, 1) - XCTAssertEqual(store.containsValueSync_keys, ["TEST_key1"]) XCTAssertEqual(store.valueSync_invocationCount, 1) XCTAssertEqual(store.valueSync_keys, ["TEST_key1"]) } catch { @@ -311,6 +276,38 @@ final class FeatureFlagResolverTests: XCTestCase { } } + func test_value_otherStoreError() async { + let store = FeatureFlagStoreMock() + configuration.stores = [store] + let storeError = NSError(domain: "TEST_Error_Domain", code: 123) + store.value_result = .failure(.otherError(storeError)) + + do { + let _: String = try await resolver.value(for: "TEST_key1") + XCTFail("Expected an error") + } catch FeatureFlagResolver.Error.storeError(let error) { + XCTAssertIdentical(error as NSError, storeError) + } catch { + XCTFail("Unexpected error: \(error)") + } + } + + func test_valueSync_otherStoreError() { + let store = SynchronousFeatureFlagStoreMock() + configuration.stores = [store] + let storeError = NSError(domain: "TEST_Error_Domain", code: 123) + store.valueSync_result = .failure(.otherError(storeError)) + + do { + let _: String = try resolver.valueSync(for: "TEST_key1") + XCTFail("Expected an error") + } catch FeatureFlagResolver.Error.storeError(let error) { + XCTAssertIdentical(error as NSError, storeError) + } catch { + XCTFail("Unexpected error: \(error)") + } + } + func test_setValue_noStores() async { do { try await resolver.setValue(123, toMutableStoreUsing: "TEST_key1") @@ -368,13 +365,13 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValue_singleMutableStore_noValue() async { let store = MutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValue_returnValue = false + store.value_result = .failure(.valueNotFound) do { try await resolver.setValue("TEST_value1", toMutableStoreUsing: "TEST_key1") - XCTAssertEqual(store.containsValue_invocationCount, 1) - XCTAssertEqual(store.containsValue_keys, ["TEST_key1"]) + XCTAssertEqual(store.value_invocationCount, 1) + XCTAssertEqual(store.value_keys, ["TEST_key1"]) XCTAssertEqual(store.setValue_invocationCount, 1) XCTAssertEqual(store.setValue_keyValuePairs.count, 1) XCTAssertEqual(store.setValue_keyValuePairs[0].0, "TEST_key1") @@ -387,13 +384,13 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValueSync_singleSyncMutableStore_noValue() { let store = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValueSync_returnValue = false + store.valueSync_result = .failure(.valueNotFound) do { try resolver.setValueSync("TEST_value1", toMutableStoreUsing: "TEST_key1") - XCTAssertEqual(store.containsValueSync_invocationCount, 1) - XCTAssertEqual(store.containsValueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store.valueSync_invocationCount, 1) + XCTAssertEqual(store.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store.setValueSync_invocationCount, 1) XCTAssertEqual(store.setValueSync_keyValuePairs.count, 1) XCTAssertEqual(store.setValueSync_keyValuePairs[0].0, "TEST_key1") @@ -406,14 +403,13 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValue_singleMutableStore_existingValue() async { let store = MutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValue_returnValue = true store.value_result = .success("TEST_value1") do { try await resolver.setValue("TEST_value2", toMutableStoreUsing: "TEST_key1") - XCTAssertEqual(store.containsValue_invocationCount, 1) - XCTAssertEqual(store.containsValue_keys, ["TEST_key1"]) + XCTAssertEqual(store.value_invocationCount, 1) + XCTAssertEqual(store.value_keys, ["TEST_key1"]) XCTAssertEqual(store.setValue_invocationCount, 1) XCTAssertEqual(store.setValue_keyValuePairs.count, 1) XCTAssertEqual(store.setValue_keyValuePairs[0].0, "TEST_key1") @@ -426,14 +422,13 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValueSync_singleSyncMutableStore_existingValue() { let store = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValueSync_returnValue = true store.valueSync_result = .success("TEST_value1") do { try resolver.setValueSync("TEST_value2", toMutableStoreUsing: "TEST_key1") - XCTAssertEqual(store.containsValueSync_invocationCount, 1) - XCTAssertEqual(store.containsValueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store.valueSync_invocationCount, 1) + XCTAssertEqual(store.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store.setValueSync_invocationCount, 1) XCTAssertEqual(store.setValueSync_keyValuePairs.count, 1) XCTAssertEqual(store.setValueSync_keyValuePairs[0].0, "TEST_key1") @@ -446,15 +441,14 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValue_singleMutableStore_existingValue_optionalValue() async { let store = MutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValue_returnValue = true store.value_result = .success("TEST_value1") do { try await resolver.setValue(456 as Int?, toMutableStoreUsing: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.optionalValuesNotAllowed { - XCTAssertEqual(store.containsValue_invocationCount, 0) - XCTAssertTrue(store.containsValue_keys.isEmpty) + XCTAssertEqual(store.value_invocationCount, 0) + XCTAssertTrue(store.value_keys.isEmpty) XCTAssertEqual(store.setValue_invocationCount, 0) XCTAssertTrue(store.setValue_keyValuePairs.isEmpty) } catch { @@ -465,15 +459,14 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValueSync_singleSyncMutableStore_existingValue_optionalValue() { let store = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValueSync_returnValue = true store.valueSync_result = .success("TEST_value1") do { try resolver.setValueSync(456 as Int?, toMutableStoreUsing: "TEST_key1") XCTFail("Expected an error") } catch FeatureFlagResolver.Error.optionalValuesNotAllowed { - XCTAssertEqual(store.containsValueSync_invocationCount, 0) - XCTAssertTrue(store.containsValueSync_keys.isEmpty) + XCTAssertEqual(store.valueSync_invocationCount, 0) + XCTAssertTrue(store.valueSync_keys.isEmpty) XCTAssertEqual(store.setValueSync_invocationCount, 0) XCTAssertTrue(store.setValueSync_keyValuePairs.isEmpty) } catch { @@ -484,16 +477,14 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValue_singleMutableStore_existingValue_typeMismatch() async { let store = MutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValue_returnValue = true store.value_result = .success("TEST_value1") do { try await resolver.setValue(456, toMutableStoreUsing: "TEST_key1") XCTFail("Expected an error") - } catch FeatureFlagResolver.Error.storeError(let error) { - XCTAssertEqual(error as? TestFeatureFlagStoreError, .typeMismatch) - XCTAssertEqual(store.containsValue_invocationCount, 1) - XCTAssertEqual(store.containsValue_keys, ["TEST_key1"]) + } catch FeatureFlagResolver.Error.storeError(FeatureFlagStoreError.typeMismatch) { + XCTAssertEqual(store.value_invocationCount, 1) + XCTAssertEqual(store.value_keys, ["TEST_key1"]) XCTAssertEqual(store.setValue_invocationCount, 0) XCTAssertTrue(store.setValue_keyValuePairs.isEmpty) } catch { @@ -504,16 +495,14 @@ final class FeatureFlagResolverTests: XCTestCase { func test_setValueSync_singleSyncMutableStore_existingValue_typeMismatch() { let store = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store] - store.containsValueSync_returnValue = true store.valueSync_result = .success("TEST_value1") do { try resolver.setValueSync(456, toMutableStoreUsing: "TEST_key1") XCTFail("Expected an error") - } catch FeatureFlagResolver.Error.storeError(let error) { - XCTAssertEqual(error as? TestFeatureFlagStoreError, .typeMismatch) - XCTAssertEqual(store.containsValueSync_invocationCount, 1) - XCTAssertEqual(store.containsValueSync_keys, ["TEST_key1"]) + } catch FeatureFlagResolver.Error.storeError(FeatureFlagStoreError.typeMismatch) { + XCTAssertEqual(store.valueSync_invocationCount, 1) + XCTAssertEqual(store.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store.setValueSync_invocationCount, 0) XCTAssertTrue(store.setValueSync_keyValuePairs.isEmpty) } catch { @@ -526,9 +515,6 @@ final class FeatureFlagResolverTests: XCTestCase { let store2 = FeatureFlagStoreMock() let store3 = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store1, store2, store3] - store1.containsValue_returnValue = true - store2.containsValue_returnValue = true - store3.containsValueSync_returnValue = true store1.value_result = .success("TEST_value1") store2.value_result = .success("TEST_value2") store3.valueSync_result = .success("TEST_value3") @@ -536,12 +522,12 @@ final class FeatureFlagResolverTests: XCTestCase { do { try await resolver.setValue("TEST_value4", toMutableStoreUsing: "TEST_key1") - XCTAssertEqual(store1.containsValue_invocationCount, 1) - XCTAssertEqual(store1.containsValue_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValue_invocationCount, 0) - XCTAssertTrue(store2.containsValue_keys.isEmpty) - XCTAssertEqual(store3.containsValueSync_invocationCount, 0) - XCTAssertTrue(store3.containsValueSync_keys.isEmpty) + XCTAssertEqual(store1.value_invocationCount, 1) + XCTAssertEqual(store1.value_keys, ["TEST_key1"]) + XCTAssertEqual(store2.value_invocationCount, 0) + XCTAssertTrue(store2.value_keys.isEmpty) + XCTAssertEqual(store3.valueSync_invocationCount, 0) + XCTAssertTrue(store3.valueSync_keys.isEmpty) XCTAssertEqual(store1.setValue_invocationCount, 1) XCTAssertEqual(store1.setValue_keyValuePairs.count, 1) XCTAssertEqual(store1.setValue_keyValuePairs[0].0, "TEST_key1") @@ -558,9 +544,6 @@ final class FeatureFlagResolverTests: XCTestCase { let store2 = SynchronousFeatureFlagStoreMock() let store3 = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store1, store2, store3] - store1.containsValueSync_returnValue = true - store2.containsValueSync_returnValue = true - store3.containsValueSync_returnValue = true store1.valueSync_result = .success("TEST_value1") store2.valueSync_result = .success("TEST_value2") store3.valueSync_result = .success("TEST_value3") @@ -568,12 +551,12 @@ final class FeatureFlagResolverTests: XCTestCase { do { try resolver.setValueSync("TEST_value4", toMutableStoreUsing: "TEST_key1") - XCTAssertEqual(store1.containsValueSync_invocationCount, 1) - XCTAssertEqual(store1.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValueSync_invocationCount, 0) - XCTAssertTrue(store2.containsValueSync_keys.isEmpty) - XCTAssertEqual(store3.containsValueSync_invocationCount, 0) - XCTAssertTrue(store3.containsValueSync_keys.isEmpty) + XCTAssertEqual(store1.valueSync_invocationCount, 1) + XCTAssertEqual(store1.valueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store2.valueSync_invocationCount, 0) + XCTAssertTrue(store2.valueSync_keys.isEmpty) + XCTAssertEqual(store3.valueSync_invocationCount, 0) + XCTAssertTrue(store3.valueSync_keys.isEmpty) XCTAssertEqual(store1.setValueSync_invocationCount, 1) XCTAssertEqual(store1.setValueSync_keyValuePairs.count, 1) XCTAssertEqual(store1.setValueSync_keyValuePairs[0].0, "TEST_key1") @@ -589,9 +572,8 @@ final class FeatureFlagResolverTests: XCTestCase { let store1 = MutableFeatureFlagStoreMock() let store2 = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store1, store2] - store1.containsValue_returnValue = false + store1.value_result = .failure(.valueNotFound) store1.setValue_result = .failure(TestFeatureFlagStoreError.failedToSetValue) - store2.containsValueSync_returnValue = true store2.valueSync_result = .success("TEST_value1") store2.setValueSync_result = .success(()) @@ -600,11 +582,10 @@ final class FeatureFlagResolverTests: XCTestCase { XCTFail("Expected an error") } catch FeatureFlagResolver.Error.storeError(let error) { XCTAssertEqual(error as? TestFeatureFlagStoreError, .failedToSetValue) - XCTAssertEqual(store1.containsValue_invocationCount, 1) - XCTAssertEqual(store1.containsValue_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValueSync_invocationCount, 1) - XCTAssertEqual(store2.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store1.value_invocationCount, 0) + XCTAssertEqual(store1.value_invocationCount, 1) + XCTAssertEqual(store1.value_keys, ["TEST_key1"]) + XCTAssertEqual(store2.valueSync_invocationCount, 1) + XCTAssertEqual(store2.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store1.setValue_invocationCount, 1) XCTAssertEqual(store1.setValue_keyValuePairs.count, 1) XCTAssertEqual(store1.setValue_keyValuePairs[0].0, "TEST_key1") @@ -620,9 +601,8 @@ final class FeatureFlagResolverTests: XCTestCase { let store1 = SynchronousMutableFeatureFlagStoreMock() let store2 = SynchronousMutableFeatureFlagStoreMock() configuration.stores = [store1, store2] - store1.containsValueSync_returnValue = false + store1.valueSync_result = .failure(.valueNotFound) store1.setValueSync_result = .failure(TestFeatureFlagStoreError.failedToSetValue) - store2.containsValueSync_returnValue = true store2.valueSync_result = .success("TEST_value1") store2.setValueSync_result = .success(()) @@ -631,11 +611,10 @@ final class FeatureFlagResolverTests: XCTestCase { XCTFail("Expected an error") } catch FeatureFlagResolver.Error.storeError(let error) { XCTAssertEqual(error as? TestFeatureFlagStoreError, .failedToSetValue) - XCTAssertEqual(store1.containsValueSync_invocationCount, 1) - XCTAssertEqual(store1.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store2.containsValueSync_invocationCount, 1) - XCTAssertEqual(store2.containsValueSync_keys, ["TEST_key1"]) - XCTAssertEqual(store1.valueSync_invocationCount, 0) + XCTAssertEqual(store1.valueSync_invocationCount, 1) + XCTAssertEqual(store1.valueSync_keys, ["TEST_key1"]) + XCTAssertEqual(store2.valueSync_invocationCount, 1) + XCTAssertEqual(store2.valueSync_keys, ["TEST_key1"]) XCTAssertEqual(store1.setValueSync_invocationCount, 1) XCTAssertEqual(store1.setValueSync_keyValuePairs.count, 1) XCTAssertEqual(store1.setValueSync_keyValuePairs[0].0, "TEST_key1") diff --git a/Tests/YMFFTests/Cases/RuntimeOverridesStoreTests.swift b/Tests/YMFFTests/Cases/RuntimeOverridesStoreTests.swift index bfe0ba6..5310425 100644 --- a/Tests/YMFFTests/Cases/RuntimeOverridesStoreTests.swift +++ b/Tests/YMFFTests/Cases/RuntimeOverridesStoreTests.swift @@ -23,48 +23,26 @@ final class RuntimeOverridesStoreTests: XCTestCase { store = RuntimeOverridesStore() } - func test_containsValue() async { - store.store = ["TEST_key1": "TEST_value1"] - - let containsValue1 = await store.containsValue(forKey: "TEST_key1") - let containsValue2 = await store.containsValue(forKey: "TEST_key2") - - XCTAssertTrue(containsValue1) - XCTAssertFalse(containsValue2) - } - - func test_containsValueSync() { - store.store = ["TEST_key1": "TEST_value1"] - - let containsValue1 = store.containsValueSync(forKey: "TEST_key1") - let containsValue2 = store.containsValueSync(forKey: "TEST_key2") - - XCTAssertTrue(containsValue1) - XCTAssertFalse(containsValue2) - } - func test_value() async throws { store.store = [ "TEST_key1": "TEST_value1", "TEST_key2": "TEST_value2", ] - let value1: String = try await store.value(forKey: "TEST_key1") + let value1: String = try await store.value(forKey: "TEST_key1").get() XCTAssertEqual(value1, "TEST_value1") do { - let _: Int = try await store.value(forKey: "TEST_key2") + let _: Int = try await store.value(forKey: "TEST_key2").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.typeMismatch { } catch { + } catch FeatureFlagStoreError.typeMismatch { } catch { XCTFail("Unexpected error: \(error)") } do { - let _: Bool = try await store.value(forKey: "TEST_key3") + let _: Bool = try await store.value(forKey: "TEST_key3").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.valueNotFound(key: let key) { - XCTAssertEqual(key, "TEST_key3") - } catch { + } catch FeatureFlagStoreError.valueNotFound { } catch { XCTFail("Unexpected error: \(error)") } } @@ -75,22 +53,20 @@ final class RuntimeOverridesStoreTests: XCTestCase { "TEST_key2": "TEST_value2", ] - let value1: String = try store.valueSync(forKey: "TEST_key1") + let value1: String = try store.valueSync(forKey: "TEST_key1").get() XCTAssertEqual(value1, "TEST_value1") do { - let _: Int = try store.valueSync(forKey: "TEST_key2") + let _: Int = try store.valueSync(forKey: "TEST_key2").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.typeMismatch { } catch { + } catch FeatureFlagStoreError.typeMismatch { } catch { XCTFail("Unexpected error: \(error)") } do { - let _: Bool = try store.valueSync(forKey: "TEST_key3") + let _: Bool = try store.valueSync(forKey: "TEST_key3").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.valueNotFound(key: let key) { - XCTAssertEqual(key, "TEST_key3") - } catch { + } catch FeatureFlagStoreError.valueNotFound { } catch { XCTFail("Unexpected error: \(error)") } } diff --git a/Tests/YMFFTests/Cases/TransparentFeatureFlagStoreTests.swift b/Tests/YMFFTests/Cases/TransparentFeatureFlagStoreTests.swift index 889912b..1cf98c1 100644 --- a/Tests/YMFFTests/Cases/TransparentFeatureFlagStoreTests.swift +++ b/Tests/YMFFTests/Cases/TransparentFeatureFlagStoreTests.swift @@ -23,46 +23,24 @@ final class TransparentFeatureFlagStoreTests: XCTestCase { store = [:] } - func test_containsValue() async { - store["TEST_key1"] = "TEST_value1" - - let containsValue1 = await store.containsValue(forKey: "TEST_key1") - let containsValue2 = await store.containsValue(forKey: "TEST_key2") - - XCTAssertTrue(containsValue1) - XCTAssertFalse(containsValue2) - } - - func test_containsValueSync() { - store["TEST_key1"] = "TEST_value1" - - let containsValue1 = store.containsValueSync(forKey: "TEST_key1") - let containsValue2 = store.containsValueSync(forKey: "TEST_key2") - - XCTAssertTrue(containsValue1) - XCTAssertFalse(containsValue2) - } - func test_value() async throws { store["TEST_key1"] = "TEST_value1" store["TEST_key2"] = "TEST_value2" - let value1: String = try await store.value(forKey: "TEST_key1") + let value1: String = try await store.value(forKey: "TEST_key1").get() XCTAssertEqual(value1, "TEST_value1") do { - let _: Int = try await store.value(forKey: "TEST_key2") + let _: Int = try await store.value(forKey: "TEST_key2").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.typeMismatch { } catch { + } catch FeatureFlagStoreError.typeMismatch { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } do { - let _: Bool = try await store.value(forKey: "TEST_key3") + let _: Bool = try await store.value(forKey: "TEST_key3").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.valueNotFound(key: let key) { - XCTAssertEqual(key, "TEST_key3") - } catch { + } catch FeatureFlagStoreError.valueNotFound { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } } @@ -71,22 +49,20 @@ final class TransparentFeatureFlagStoreTests: XCTestCase { store["TEST_key1"] = "TEST_value1" store["TEST_key2"] = "TEST_value2" - let value1: String = try store.valueSync(forKey: "TEST_key1") + let value1: String = try store.valueSync(forKey: "TEST_key1").get() XCTAssertEqual(value1, "TEST_value1") do { - let _: Int = try store.valueSync(forKey: "TEST_key2") + let _: Int = try store.valueSync(forKey: "TEST_key2").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.typeMismatch { } catch { + } catch FeatureFlagStoreError.typeMismatch { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } do { - let _: Bool = try store.valueSync(forKey: "TEST_key3") + let _: Bool = try store.valueSync(forKey: "TEST_key3").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.valueNotFound(key: let key) { - XCTAssertEqual(key, "TEST_key3") - } catch { + } catch FeatureFlagStoreError.valueNotFound { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } } diff --git a/Tests/YMFFTests/Cases/UserDefaultsStoreTests.swift b/Tests/YMFFTests/Cases/UserDefaultsStoreTests.swift index cd7ee7c..7aaf8b0 100644 --- a/Tests/YMFFTests/Cases/UserDefaultsStoreTests.swift +++ b/Tests/YMFFTests/Cases/UserDefaultsStoreTests.swift @@ -11,6 +11,9 @@ @testable import YMFF import XCTest +#if !COCOAPODS +import YMFFProtocols +#endif final class UserDefaultsStoreTests: XCTestCase { @@ -34,46 +37,24 @@ final class UserDefaultsStoreTests: XCTestCase { super.tearDown() } - func test_containsValue() async { - userDefaults.set("TEST_value1", forKey: "TEST_key1") - - let containsValue1 = await store.containsValue(forKey: "TEST_key1") - let containsValue2 = await store.containsValue(forKey: "TEST_key2") - - XCTAssertTrue(containsValue1) - XCTAssertFalse(containsValue2) - } - - func test_containsValueSync() { - userDefaults.set("TEST_value1", forKey: "TEST_key1") - - let containsValue1 = store.containsValueSync(forKey: "TEST_key1") - let containsValue2 = store.containsValueSync(forKey: "TEST_key2") - - XCTAssertTrue(containsValue1) - XCTAssertFalse(containsValue2) - } - func test_value() async throws { userDefaults.set("TEST_value1", forKey: "TEST_key1") userDefaults.set("TEST_value2", forKey: "TEST_key2") - let value1: String = try await store.value(forKey: "TEST_key1") + let value1: String = try await store.value(forKey: "TEST_key1").get() XCTAssertEqual(value1, "TEST_value1") do { - let _: Int = try await store.value(forKey: "TEST_key2") + let _: Int = try await store.value(forKey: "TEST_key2").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.typeMismatch { } catch { + } catch FeatureFlagStoreError.typeMismatch { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } do { - let _: Bool = try await store.value(forKey: "TEST_key3") + let _: Bool = try await store.value(forKey: "TEST_key3").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.valueNotFound(key: let key) { - XCTAssertEqual(key, "TEST_key3") - } catch { + } catch FeatureFlagStoreError.valueNotFound { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } } @@ -82,22 +63,20 @@ final class UserDefaultsStoreTests: XCTestCase { userDefaults.set("TEST_value1", forKey: "TEST_key1") userDefaults.set("TEST_value2", forKey: "TEST_key2") - let value1: String = try store.valueSync(forKey: "TEST_key1") + let value1: String = try store.valueSync(forKey: "TEST_key1").get() XCTAssertEqual(value1, "TEST_value1") do { - let _: Int = try store.valueSync(forKey: "TEST_key2") + let _: Int = try store.valueSync(forKey: "TEST_key2").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.typeMismatch { } catch { + } catch FeatureFlagStoreError.typeMismatch { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } do { - let _: Bool = try store.valueSync(forKey: "TEST_key3") + let _: Bool = try store.valueSync(forKey: "TEST_key3").get() XCTFail("Expected an error") - } catch CommonFeatureFlagStoreError.valueNotFound(key: let key) { - XCTAssertEqual(key, "TEST_key3") - } catch { + } catch FeatureFlagStoreError.valueNotFound { } catch { XCTFail("Unexpected error: \(error.localizedDescription)") } } diff --git a/Tests/YMFFTests/Utilities/FeatureFlagStoreMock.swift b/Tests/YMFFTests/Utilities/FeatureFlagStoreMock.swift index 8d9293e..4e54fa2 100644 --- a/Tests/YMFFTests/Utilities/FeatureFlagStoreMock.swift +++ b/Tests/YMFFTests/Utilities/FeatureFlagStoreMock.swift @@ -16,13 +16,9 @@ import YMFFProtocols final class FeatureFlagStoreMock { - var containsValue_invocationCount = 0 - var containsValue_keys = [String]() - var containsValue_returnValue: Bool! - var value_invocationCount = 0 var value_keys = [String]() - var value_result: Result! + var value_result: Result! } @@ -30,23 +26,17 @@ final class FeatureFlagStoreMock { extension FeatureFlagStoreMock: FeatureFlagStore { - func containsValue(forKey key: String) async -> Bool { - containsValue_invocationCount += 1 - containsValue_keys.append(key) - return containsValue_returnValue - } - - func value(forKey key: String) async throws -> Value { + func value(forKey key: String) async -> Result { value_invocationCount += 1 value_keys.append(key) switch value_result! { case .success(let anyValue): if let value = anyValue as? Value { - return value + return .success(value) } else { - throw TestFeatureFlagStoreError.typeMismatch + return .failure(.typeMismatch) } - case .failure(let error): throw error + case .failure(let error): return .failure(error) } } diff --git a/Tests/YMFFTests/Utilities/MutableFeatureFlagStoreMock.swift b/Tests/YMFFTests/Utilities/MutableFeatureFlagStoreMock.swift index 3cd4f5f..b6f086d 100644 --- a/Tests/YMFFTests/Utilities/MutableFeatureFlagStoreMock.swift +++ b/Tests/YMFFTests/Utilities/MutableFeatureFlagStoreMock.swift @@ -16,13 +16,9 @@ import YMFFProtocols final class MutableFeatureFlagStoreMock { - var containsValue_invocationCount = 0 - var containsValue_keys = [String]() - var containsValue_returnValue: Bool! - var value_invocationCount = 0 var value_keys = [String]() - var value_result: Result! + var value_result: Result! var setValue_invocationCount = 0 var setValue_keyValuePairs = [(String, Any)]() @@ -41,23 +37,17 @@ final class MutableFeatureFlagStoreMock { extension MutableFeatureFlagStoreMock: MutableFeatureFlagStore { - func containsValue(forKey key: String) async -> Bool { - containsValue_invocationCount += 1 - containsValue_keys.append(key) - return containsValue_returnValue - } - - func value(forKey key: String) async throws -> Value { + func value(forKey key: String) async -> Result { value_invocationCount += 1 value_keys.append(key) switch value_result! { case .success(let anyValue): if let value = anyValue as? Value { - return value + return .success(value) } else { - throw TestFeatureFlagStoreError.typeMismatch + return .failure(.typeMismatch) } - case .failure(let error): throw error + case .failure(let error): return .failure(error) } } diff --git a/Tests/YMFFTests/Utilities/SynchronousFeatureFlagStoreMock.swift b/Tests/YMFFTests/Utilities/SynchronousFeatureFlagStoreMock.swift index de0de58..ddad330 100644 --- a/Tests/YMFFTests/Utilities/SynchronousFeatureFlagStoreMock.swift +++ b/Tests/YMFFTests/Utilities/SynchronousFeatureFlagStoreMock.swift @@ -16,13 +16,9 @@ import YMFFProtocols final class SynchronousFeatureFlagStoreMock { - var containsValueSync_invocationCount = 0 - var containsValueSync_keys = [String]() - var containsValueSync_returnValue: Bool! - var valueSync_invocationCount = 0 var valueSync_keys = [String]() - var valueSync_result: Result! + var valueSync_result: Result! } @@ -30,23 +26,17 @@ final class SynchronousFeatureFlagStoreMock { extension SynchronousFeatureFlagStoreMock: SynchronousFeatureFlagStore { - func containsValueSync(forKey key: String) -> Bool { - containsValueSync_invocationCount += 1 - containsValueSync_keys.append(key) - return containsValueSync_returnValue - } - - func valueSync(forKey key: String) throws -> Value { + func valueSync(forKey key: String) -> Result { valueSync_invocationCount += 1 valueSync_keys.append(key) switch valueSync_result! { case .success(let anyValue): if let value = anyValue as? Value { - return value + return .success(value) } else { - throw TestFeatureFlagStoreError.typeMismatch + return .failure(.typeMismatch) } - case .failure(let error): throw error + case .failure(let error): return .failure(error) } } diff --git a/Tests/YMFFTests/Utilities/SynchronousMutableFeatureFlagStoreMock.swift b/Tests/YMFFTests/Utilities/SynchronousMutableFeatureFlagStoreMock.swift index acd95e3..98ebac9 100644 --- a/Tests/YMFFTests/Utilities/SynchronousMutableFeatureFlagStoreMock.swift +++ b/Tests/YMFFTests/Utilities/SynchronousMutableFeatureFlagStoreMock.swift @@ -16,13 +16,9 @@ import YMFFProtocols final class SynchronousMutableFeatureFlagStoreMock { - var containsValueSync_invocationCount = 0 - var containsValueSync_keys = [String]() - var containsValueSync_returnValue: Bool! - var valueSync_invocationCount = 0 var valueSync_keys = [String]() - var valueSync_result: Result! + var valueSync_result: Result! var setValueSync_invocationCount = 0 var setValueSync_keyValuePairs = [(String, Any)]() @@ -41,23 +37,17 @@ final class SynchronousMutableFeatureFlagStoreMock { extension SynchronousMutableFeatureFlagStoreMock: SynchronousMutableFeatureFlagStore { - func containsValueSync(forKey key: String) -> Bool { - containsValueSync_invocationCount += 1 - containsValueSync_keys.append(key) - return containsValueSync_returnValue - } - - func valueSync(forKey key: String) throws -> Value { + func valueSync(forKey key: String) -> Result { valueSync_invocationCount += 1 valueSync_keys.append(key) switch valueSync_result! { case .success(let anyValue): if let value = anyValue as? Value { - return value + return .success(value) } else { - throw TestFeatureFlagStoreError.typeMismatch + return .failure(.typeMismatch) } - case .failure(let error): throw error + case .failure(let error): return .failure(error) } } diff --git a/Tests/YMFFTests/Utilities/TestFeatureFlagStoreError.swift b/Tests/YMFFTests/Utilities/TestFeatureFlagStoreError.swift index 6cdf93d..7d88a71 100644 --- a/Tests/YMFFTests/Utilities/TestFeatureFlagStoreError.swift +++ b/Tests/YMFFTests/Utilities/TestFeatureFlagStoreError.swift @@ -7,7 +7,6 @@ // enum TestFeatureFlagStoreError: Error, Equatable { - case typeMismatch case failedToSetValue case failedToRemoveValue }