From baa308ce32803592e57e614a1652a280c3550d4f Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 3 Sep 2024 12:49:08 -0500 Subject: [PATCH] chore(geo): resolve swiftformat errors and warnings --- .../AWSLocationGeoPlugin+ClientBehavior.swift | 24 +++++----- .../AWSLocationGeoPlugin+Configure.swift | 15 +++--- .../AWSLocationGeoPlugin+Reset.swift | 4 +- .../AWSLocationGeoPluginConfiguration.swift | 13 +++-- .../Configuration/GeoPluginConfigError.swift | 2 +- .../Dependency/AWSLocationBehavior.swift | 2 +- .../Constants/GeoPluginErrorConstants.swift | 4 +- .../Support/Utils/GeoErrorConvertible.swift | 4 +- ...tionGeoPluginAmplifyVersionableTests.swift | 2 +- ...LocationGeoPluginClientBehaviorTests.swift | 28 +++++------ .../AWSLocationGeoPluginConfigureTests.swift | 5 +- .../AWSLocationGeoPluginResetTests.swift | 2 +- .../AWSLocationGeoPluginTestBase.swift | 2 +- ...uginAmplifyOutputsConfigurationTests.swift | 2 +- ...SLocationGeoPluginConfigurationTests.swift | 48 +++++++++---------- .../Mocks/MockAWSClientConfiguration.swift | 2 +- .../MockAWSLocation+ClientBehavior.swift | 22 +++++---- .../Mocks/MockAWSLocation.swift | 10 ++-- .../Constants/GeoPluginTestConfig.swift | 2 +- ...AWSLocationGeoPluginIntegrationTests.swift | 2 +- .../GeoStressTests/GeoStressTests.swift | 16 +++---- 21 files changed, 108 insertions(+), 103 deletions(-) diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift index f79c09981f..3796a1ce68 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift @@ -10,7 +10,7 @@ import Foundation import AWSLocation -extension AWSLocationGeoPlugin { +public extension AWSLocationGeoPlugin { // MARK: - Search @@ -30,8 +30,9 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func search(for text: String, - options: Geo.SearchForTextOptions? = nil) async throws -> [Geo.Place] { + func search(for text: String, + options: Geo.SearchForTextOptions? = nil) async throws -> [Geo.Place] + { var request = SearchPlaceIndexForTextInput() @@ -73,9 +74,7 @@ extension AWSLocationGeoPlugin { let response = try await locationService.searchPlaceIndex(forText: request) var results = [LocationClientTypes.Place]() if let responseResults = response.results { - results = responseResults.compactMap { - $0.place - } + results = responseResults.compactMap(\.place) } let places: [Geo.Place] = results.compactMap { @@ -123,8 +122,9 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func search(for coordinates: Geo.Coordinates, - options: Geo.SearchForCoordinatesOptions? = nil) async throws -> [Geo.Place] { + func search(for coordinates: Geo.Coordinates, + options: Geo.SearchForCoordinatesOptions? = nil) async throws -> [Geo.Place] + { var request = SearchPlaceIndexForPositionInput() @@ -148,9 +148,7 @@ extension AWSLocationGeoPlugin { let response = try await locationService.searchPlaceIndex(forPosition: request) var results = [LocationClientTypes.Place]() if let responseResults = response.results { - results = responseResults.compactMap { - $0.place - } + results = responseResults.compactMap(\.place) } let places: [Geo.Place] = results.compactMap { @@ -194,7 +192,7 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func availableMaps() async throws -> [Geo.MapStyle] { + func availableMaps() async throws -> [Geo.MapStyle] { let mapStyles = Array(pluginConfig.maps.values) guard !mapStyles.isEmpty else { throw Geo.Error.invalidConfiguration( @@ -213,7 +211,7 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func defaultMap() async throws -> Geo.MapStyle { + func defaultMap() async throws -> Geo.MapStyle { guard let mapName = pluginConfig.defaultMap, let mapStyle = pluginConfig.maps[mapName] else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingDefaultMap.errorDescription, diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift index 6b194b48af..d1d9d29d4b 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift @@ -7,12 +7,12 @@ import Foundation @_spi(InternalAmplifyConfiguration) import Amplify +import AWSClientRuntime +import AWSLocation import AWSPluginsCore @_spi(PluginHTTPClientEngine) import InternalAmplifyCredentials -import AWSLocation -import AWSClientRuntime -extension AWSLocationGeoPlugin { +public extension AWSLocationGeoPlugin { /// Configures AWSLocationPlugin with the specified configuration. /// /// This method will be invoked as part of the Amplify configuration flow. @@ -20,7 +20,7 @@ extension AWSLocationGeoPlugin { /// - Parameter configuration: The configuration specified for this plugin. /// - Throws: /// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty. - public func configure(using configuration: Any?) throws { + func configure(using configuration: Any?) throws { let pluginConfiguration: AWSLocationGeoPluginConfiguration if let configuration = configuration as? AmplifyOutputsData { pluginConfiguration = try AWSLocationGeoPluginConfiguration(config: configuration) @@ -34,7 +34,7 @@ extension AWSLocationGeoPlugin { } /// Configure AWSLocationPlugin programatically using AWSLocationPluginConfiguration - public func configure(using configuration: AWSLocationGeoPluginConfiguration) throws { + func configure(using configuration: AWSLocationGeoPluginConfiguration) throws { let authService = AWSAuthService() let credentialsProvider = authService.getCredentialsProvider() let region = configuration.regionName @@ -64,9 +64,10 @@ extension AWSLocationGeoPlugin { /// - locationService: The location service object. /// - authService: The authentication service object. /// - pluginConfig: The configuration for the plugin. - func configure(locationService: AWSLocationBehavior, + internal func configure(locationService: AWSLocationBehavior, authService: AWSAuthServiceBehavior, - pluginConfig: AWSLocationGeoPluginConfiguration) { + pluginConfig: AWSLocationGeoPluginConfiguration) + { self.locationService = locationService self.authService = authService self.pluginConfig = pluginConfig diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift index b1b76ca452..a748002a2c 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift @@ -8,13 +8,13 @@ import Amplify import Foundation -extension AWSLocationGeoPlugin { +public extension AWSLocationGeoPlugin { /// Resets the state of the plugin. /// /// Sets stored objects to nil to allow deallocation, then calls onComplete closure /// to signal the reset has completed. - public func reset() async { + func reset() async { locationService = nil authService = nil pluginConfig = nil diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift index 4d25b090a5..65bdc81afc 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift @@ -6,8 +6,8 @@ // @_spi(InternalAmplifyConfiguration) import Amplify -import Foundation import AWSLocation +import Foundation public struct AWSLocationGeoPluginConfiguration { private static func urlString(regionName: String, mapName: String) -> String { @@ -60,7 +60,7 @@ public struct AWSLocationGeoPluginConfiguration { defaultSearchIndex: defaultSearchIndex, searchIndices: searchIndices) } - + init(config: AmplifyOutputsData) throws { guard let geo = config.geo else { throw GeoPluginConfigError.configurationInvalid(section: .plugin) @@ -102,7 +102,8 @@ public struct AWSLocationGeoPluginConfiguration { defaultMap: String?, maps: [String: Geo.MapStyle], defaultSearchIndex: String?, - searchIndices: [String]) { + searchIndices: [String]) + { self.regionName = regionName self.defaultMap = defaultMap self.maps = maps @@ -163,7 +164,8 @@ public struct AWSLocationGeoPluginConfiguration { } private static func getItemsObject(section: Section, - configObject: [String: JSONValue]) throws -> [String: JSONValue] { + configObject: [String: JSONValue]) throws -> [String: JSONValue] + { let itemsJSON = try getItemsJSON(section: section, configObject: configObject) let itemsObject = try getConfigObject(section: section, configJSON: itemsJSON) return itemsObject @@ -216,7 +218,8 @@ public struct AWSLocationGeoPluginConfiguration { } private static func getMaps(mapConfig: AmplifyOutputsData.Geo.Maps, - regionName: String) throws -> [String: Geo.MapStyle] { + regionName: String) throws -> [String: Geo.MapStyle] + { let mapTuples: [(String, Geo.MapStyle)] = try mapConfig.items.map { map in let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(regionName: regionName, mapName: map.key)) diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift index 749533765c..945a30037f 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift @@ -10,7 +10,7 @@ import Foundation typealias GeoPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion) -struct GeoPluginConfigError { +enum GeoPluginConfigError { static func configurationInvalid(section: AWSLocationGeoPluginConfiguration.Section) -> PluginError { PluginError.pluginConfigurationError( "Unable to decode \(section.key) configuration.", diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift index fdc71dc22f..2433afbc93 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import AWSLocation +import Foundation /// Behavior that `AWSLocationAdapter` will use. /// This protocol allows a way to create a Mock and ensure the plugin implementation is testable. diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift index 11250a7976..828cca0bc5 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift @@ -5,10 +5,10 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import Amplify +import Foundation -struct GeoPluginErrorConstants { +enum GeoPluginErrorConstants { static let missingDefaultSearchIndex: GeoPluginErrorString = ( "No default search index was found.", "Please ensure you have added search to your project before calling search functions.") diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift index ad35aea33a..15d21d1ba6 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift @@ -6,9 +6,9 @@ // import Amplify -import Foundation -import AWSLocation import AWSClientRuntime +import AWSLocation +import Foundation protocol GeoErrorConvertible { var geoError: Geo.Error { get } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift index a39a663998..52f909462f 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import XCTest import AWSLocationGeoPlugin +import XCTest // swiftlint:disable:next type_name class AWSLocationGeoPluginAmplifyVersionableTests: XCTestCase { diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift index f9ae3c2e71..438cccc387 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift @@ -7,8 +7,8 @@ import Amplify import AWSLocation -@testable import AWSLocationGeoPlugin import XCTest +@testable import AWSLocationGeoPlugin class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { let searchText = "coffee shop" @@ -28,8 +28,8 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: searchText, options: nil) var request = SearchPlaceIndexForTextInput() - request.text = self.searchText - self.mockLocation.verifySearchPlaceIndexForText(request) + request.text = searchText + mockLocation.verifySearchPlaceIndexForText(request) } catch { XCTFail("Failed with error: \(error)") } @@ -53,13 +53,13 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: searchText, options: options) var request = SearchPlaceIndexForTextInput() - request.text = self.searchText - request.biasPosition = [(self.coordinates.longitude), - (self.coordinates.latitude)] - request.filterCountries = options.countries?.map { $0.code } + request.text = searchText + request.biasPosition = [coordinates.longitude, + coordinates.latitude] + request.filterCountries = options.countries?.map(\.code) request.maxResults = options.maxResults ?? 0 request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex - self.mockLocation.verifySearchPlaceIndexForText(request) + mockLocation.verifySearchPlaceIndexForText(request) } catch { XCTFail("Failed with error: \(error)") } @@ -100,9 +100,9 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: coordinates, options: nil) var request = SearchPlaceIndexForPositionInput() - request.position = [(self.coordinates.longitude), - (self.coordinates.latitude)] - self.mockLocation.verifySearchPlaceIndexForPosition(request) + request.position = [coordinates.longitude, + coordinates.latitude] + mockLocation.verifySearchPlaceIndexForPosition(request) } catch { XCTFail("Failed with error: \(error)") } @@ -124,11 +124,11 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: coordinates, options: options) var request = SearchPlaceIndexForPositionInput() - request.position = [(self.coordinates.longitude), - (self.coordinates.latitude) ] + request.position = [coordinates.longitude, + coordinates.latitude] request.maxResults = options.maxResults ?? 0 request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex - self.mockLocation.verifySearchPlaceIndexForPosition(request) + mockLocation.verifySearchPlaceIndexForPosition(request) } catch { XCTFail("Failed with error: \(error)") } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift index f534374b07..1f31bb9b5b 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift @@ -6,8 +6,8 @@ // import Amplify -@testable import AWSLocationGeoPlugin import XCTest +@testable import AWSLocationGeoPlugin class AWSLocationGeoPluginConfigureTests: AWSLocationGeoPluginTestBase { // MARK: - Plugin Key test @@ -56,7 +56,8 @@ class AWSLocationGeoPluginConfigureTests: AWSLocationGeoPluginTestBase { XCTFail("Geo configuration should not succeed.") } catch { guard let pluginError = error as? PluginError, - case .pluginConfigurationError = pluginError else { + case .pluginConfigurationError = pluginError + else { XCTFail("Should throw invalidConfiguration exception. But received \(error) ") return } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift index 8362742b53..32fe84527a 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift @@ -6,8 +6,8 @@ // import Amplify -@testable import AWSLocationGeoPlugin import XCTest +@testable import AWSLocationGeoPlugin class AWSLocationGeoPluginResetTests: AWSLocationGeoPluginTestBase { func testReset() async { diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift index ee44deb0fb..4f0afb004f 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift @@ -5,11 +5,11 @@ // SPDX-License-Identifier: Apache-2.0 // +import XCTest @testable import Amplify @testable import AmplifyTestCommon @testable import AWSLocationGeoPlugin @testable import AWSPluginsTestCommon -import XCTest class AWSLocationGeoPluginTestBase: XCTestCase { var geoPlugin: AWSLocationGeoPlugin! diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift index 70e30ab8b4..6d7391e662 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -@testable @_spi(InternalAmplifyConfiguration) import Amplify import XCTest +@testable @_spi(InternalAmplifyConfiguration) import Amplify @testable import AWSLocationGeoPlugin diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift index 8118fc2fa0..d2a7e7c3a1 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift @@ -173,7 +173,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription) } } - + /// - Given: geo plugin configuration /// - When: the object initializes missing region /// - Then: the configuration fails to initialize with regionMissing error @@ -194,7 +194,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - When: the object initializes with an invalid region /// - Then: the configuration fails to initialize with regionInvalid error func testConfigureFailureForInvalidRegion() async { - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, JSONValue(integerLiteral: 1)), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, JSONValue(integerLiteral: 1)), (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -206,13 +206,13 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.regionInvalid.errorDescription) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a missing default maps section /// - Then: the configuration fails to initialize with defaultMissing error func testConfigureFailureForMissingDefaultMapsSection() async { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -224,7 +224,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.defaultMissing(section: .maps).errorDescription) } } - + /// - Given: geo plugin configuration /// - When: the object initializes without default map /// - Then: the configuration fails to initialize with mapDefaultNotFound error @@ -237,7 +237,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -256,7 +256,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { func testConfigureFailureForInvalidDefaultMapsSection() async { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, JSONValue(integerLiteral: 1))) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -277,7 +277,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { func testConfigureFailureForEmptyDefaultMapsSection() async { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, JSONValue(stringLiteral: ""))) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -289,13 +289,13 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.defaultIsEmpty(section: .maps).errorDescription) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a items default maps section /// - Then: the configuration fails to initialize with itemsMissing error func testConfigureFailureForMissingItemsMapsSection() async { - let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.default.key,GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -307,7 +307,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.itemsMissing(section: .maps).errorDescription) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid maps section /// - Then: the configuration fails to initialize with mapInvalid error @@ -316,7 +316,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -328,7 +328,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.mapInvalid(mapName: "testMap").errorDescription) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid maps section /// - Then: the configuration fails to initialize with mapStyleMissing error @@ -339,7 +339,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -351,8 +351,8 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.mapStyleMissing(mapName: "testMap").errorDescription) } } - - + + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid maps section /// - Then: the configuration fails to initialize with mapStyleMissing error @@ -365,7 +365,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -375,7 +375,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { } } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid map style url /// - Then: the configuration fails to initialize with mapStyleIsNotString error @@ -388,7 +388,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -411,7 +411,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -434,7 +434,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in @@ -446,7 +446,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { GeoPluginConfigError.itemsIsNotStringArray(section: .searchIndices).errorDescription) } } - + /// - Given: geo plugin configuration /// - When: configuration initializes with a mismatch search items and default item /// - Then: the configuration fails to initializes with searchDefaultNotFound error @@ -457,7 +457,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift index ec24a7486d..b34ef18c9b 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift @@ -6,8 +6,8 @@ // import AWSClientRuntime -import ClientRuntime import AWSLocation +import ClientRuntime import Foundation import XCTest diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift index 3f7fbb6c27..bb864f0ed1 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift @@ -6,38 +6,40 @@ // import AWSLocation -@testable import AWSLocationGeoPlugin import Foundation +@testable import AWSLocationGeoPlugin -extension MockAWSLocation { +public extension MockAWSLocation { - public func searchPlaceIndex(forText: SearchPlaceIndexForTextInput, + func searchPlaceIndex(forText: SearchPlaceIndexForTextInput, completionHandler: ((SearchPlaceIndexForTextOutput?, - Error?) -> Void)?) { + Error?) -> Void)?) + { searchPlaceIndexForTextCalled += 1 searchPlaceIndexForTextRequest = forText - if let completionHandler = completionHandler { + if let completionHandler { completionHandler(SearchPlaceIndexForTextOutput(), nil) } } - public func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput, + func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput, completionHandler: ((SearchPlaceIndexForPositionOutput?, - Error?) -> Void)?) { + Error?) -> Void)?) + { searchPlaceIndexForPositionCalled += 1 searchPlaceIndexForPositionRequest = forPosition - if let completionHandler = completionHandler { + if let completionHandler { completionHandler(SearchPlaceIndexForPositionOutput(), nil) } } - public func searchPlaceIndex(forText: SearchPlaceIndexForTextInput) async throws -> SearchPlaceIndexForTextOutput { + func searchPlaceIndex(forText: SearchPlaceIndexForTextInput) async throws -> SearchPlaceIndexForTextOutput { searchPlaceIndexForTextCalled += 1 searchPlaceIndexForTextRequest = forText return SearchPlaceIndexForTextOutput() } - public func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput) async throws -> SearchPlaceIndexForPositionOutput { + func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput) async throws -> SearchPlaceIndexForPositionOutput { searchPlaceIndexForPositionCalled += 1 searchPlaceIndexForPositionRequest = forPosition return SearchPlaceIndexForPositionOutput() diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift index 0dc4080432..ce1ffe3c84 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift @@ -33,16 +33,16 @@ public class MockAWSLocation: AWSLocationBehavior { public func getEscapeHatch() -> LocationClient { getEscapeHatchCalled += 1 - return self.locationClient + return locationClient } } -extension MockAWSLocation { - public func verifyGetEscapeHatch() { +public extension MockAWSLocation { + func verifyGetEscapeHatch() { XCTAssertEqual(getEscapeHatchCalled, 1) } - public func verifySearchPlaceIndexForText(_ request: SearchPlaceIndexForTextInput) { + func verifySearchPlaceIndexForText(_ request: SearchPlaceIndexForTextInput) { XCTAssertEqual(searchPlaceIndexForTextCalled, 1) guard let receivedRequest = searchPlaceIndexForTextRequest else { XCTFail("Did not receive request.") @@ -59,7 +59,7 @@ extension MockAWSLocation { XCTAssertEqual(receivedRequest.maxResults, request.maxResults) } - public func verifySearchPlaceIndexForPosition(_ request: SearchPlaceIndexForPositionInput) { + func verifySearchPlaceIndexForPosition(_ request: SearchPlaceIndexForPositionInput) { XCTAssertEqual(searchPlaceIndexForPositionCalled, 1) guard let receivedRequest = searchPlaceIndexForPositionRequest else { XCTFail("Did not receive request.") diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift index cf11c975e3..1587de563c 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift @@ -9,7 +9,7 @@ import Foundation @testable @_spi(InternalAmplifyConfiguration) import Amplify @testable import AWSLocationGeoPlugin -struct GeoPluginTestConfig { +enum GeoPluginTestConfig { static let timeout = 1.0 // Plugin Test Configuration diff --git a/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift b/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift index 682ef7f4be..6ff5a7bdf1 100644 --- a/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift +++ b/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import XCTest import AWSLocation +import XCTest @testable import Amplify @testable import AWSCognitoAuthPlugin diff --git a/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift b/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift index a512832e52..5b9c77b5f6 100644 --- a/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift +++ b/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift @@ -33,9 +33,9 @@ final class GeoStressTests: XCTestCase { override func tearDown() async throws { await Amplify.reset() } - + // MARK: - Stress Tests - + /// Test if concurrent execution of search(for: text) is successful /// - Given: Geo plugin with a valid configuration. /// - When: @@ -44,9 +44,9 @@ final class GeoStressTests: XCTestCase { /// - Place results are returned. /// func testMultipleSearchForText() async { - let successExpectation = expectation(description: "searchForText was successful") + let successExpectation = expectation(description: "searchForText was successful") successExpectation.expectedFulfillmentCount = concurrencyLimit - for _ in 1...concurrencyLimit { + for _ in 1 ... concurrencyLimit { Task { do { let options = Geo.SearchForTextOptions(area: .near(coordinates)) @@ -58,10 +58,10 @@ final class GeoStressTests: XCTestCase { } } } - + await fulfillment(of: [successExpectation], timeout: timeout) } - + /// Test if concurrent execution of search(for: coordinates) is successful /// - Given: Geo plugin with a valid configuration. /// - When: @@ -72,7 +72,7 @@ final class GeoStressTests: XCTestCase { func testMultipleSearchForCoordinates() async { let successExpectation = expectation(description: "searchForCoordinates was successful") successExpectation.expectedFulfillmentCount = concurrencyLimit - for _ in 1...concurrencyLimit { + for _ in 1 ... concurrencyLimit { Task { do { let places = try await Amplify.Geo.search(for: coordinates, options: nil) @@ -84,7 +84,7 @@ final class GeoStressTests: XCTestCase { } } } - + await fulfillment(of: [successExpectation], timeout: timeout) }