From 2326834f2bb98c77ad1698dc0e7d06b6f804fbe3 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Fri, 13 Sep 2024 19:10:18 -0500 Subject: [PATCH] update rules --- .../Internal/StorageTransferResponse.swift | 14 +++--- .../Storage/AWSS3StorageServiceTests.swift | 6 +-- ...S3StoragePluginBasicIntegrationTests.swift | 50 +++++++++---------- ...3StoragePluginGetURLIntegrationTests.swift | 8 +-- ...3StoragePluginUploadIntegrationTests.swift | 12 ++--- 5 files changed, 44 insertions(+), 46 deletions(-) diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageTransferResponse.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageTransferResponse.swift index 414b3b6ac1..27162d22d6 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageTransferResponse.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageTransferResponse.swift @@ -63,8 +63,7 @@ class StorageTransferResponse { // See https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html for S3 error responses guard let httpResponse, - transferTask.retryCount < transferTask.retryLimit - else { + transferTask.retryCount < transferTask.retryLimit else { return false } @@ -98,15 +97,16 @@ class StorageTransferResponse { } private func errorDescription(forStatusCode statusCode: Int) -> ErrorDescription { - let description = switch statusCode { + let description: String + switch statusCode { case 401: - "Unauthorized" + description = "Unauthorized" case 403: - "Forbidden" + description = "Forbidden" case 404: - "NotFound" + description = "NotFound" default: - "" + description = "" } return "Received HTTP Response status code \(statusCode) \(description)" diff --git a/AmplifyPlugins/Storage/Tests/AWSS3StoragePluginTests/Service/Storage/AWSS3StorageServiceTests.swift b/AmplifyPlugins/Storage/Tests/AWSS3StoragePluginTests/Service/Storage/AWSS3StorageServiceTests.swift index 93fe9e6f75..faf3f8b06c 100644 --- a/AmplifyPlugins/Storage/Tests/AWSS3StoragePluginTests/Service/Storage/AWSS3StorageServiceTests.swift +++ b/AmplifyPlugins/Storage/Tests/AWSS3StoragePluginTests/Service/Storage/AWSS3StorageServiceTests.swift @@ -228,8 +228,7 @@ class AWSS3StorageServiceTests: XCTestCase { let downloadTask = StorageTransferTask( transferType: .download(onEvent: { event in guard case .completed(let data) = event, - let data - else { + let data else { XCTFail("Expected .completed event with data") return } @@ -350,8 +349,7 @@ class AWSS3StorageServiceTests: XCTestCase { accelerate: true, onEvent: { event in guard case .failed(let error) = event, - case .unknown(let description, _) = error - else { + case .unknown(let description, _) = error else { XCTFail("Expected .failed event with .unknown error, got \(event)") return } diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift index 2e217ac782..c37da8b153 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginBasicIntegrationTests.swift @@ -67,10 +67,10 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.remove(key: key) // Only the remove operation results in an SDK request - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method }, [.delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -83,7 +83,7 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.uploadData(key: key, data: data, options: nil).value _ = try await Amplify.Storage.remove(key: key) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -101,10 +101,10 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.remove(key: key) // Only the remove operation results in an SDK request - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -120,7 +120,7 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.uploadFile(key: key, local: fileURL, options: nil).value _ = try await Amplify.Storage.remove(key: key) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -218,7 +218,7 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { let remoteURL = try await Amplify.Storage.getURL(key: key) // The presigned URL generation does not result in an SDK or HTTP call. - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), []) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, []) let (data, response) = try await URLSession.shared.data(from: remoteURL) let httpResponse = try XCTUnwrap(response as? HTTPURLResponse) @@ -251,7 +251,7 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { XCTAssert(requestRecorder.sdkRequests.map(\.method).allSatisfy { $0 == .head }) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), []) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, []) } /// - Given: A key for a non-existent S3 object @@ -268,8 +268,8 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { XCTAssertNotNil(url) // No SDK or URLRequest calls expected - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), []) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), []) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, []) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, []) } /// Given: An object in storage @@ -298,11 +298,11 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.remove(key: key) // S3 GetObjectList and DeleteObject calls are expected - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.get, .delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.get, .delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) // A single URLRequest call is expected - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) } /// Given: A collection of objects in storage numbering `objectCount`. @@ -344,16 +344,16 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { XCTAssertEqual( uploadedKeys.sorted(), - Array((firstPage + secondPage).map(\.key)).sorted() + Array((firstPage + secondPage).map { $0.key }).sorted() ) // S3 GetObjectList calls are expected (DeleteObject calls happen during tearDown) - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.get, .get]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.get, .get]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) // A URLRequest call for each uploaded file is expected let expectedURLRequestMethods: [String] = uploadedKeys.map { _ in "PUT" } - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), expectedURLRequestMethods) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, expectedURLRequestMethods) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -373,11 +373,11 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { XCTAssertEqual(result.items.count, 0) // A single SDK call for the ListObjectsV2 request is expected - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.get]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.get]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) // No URLRequest calls expected - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), []) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, []) } /// Given: No object in storage for the key @@ -407,12 +407,12 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.remove(key: key) - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.get, .delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.get, .delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) // A URLRequest call for each uploaded file is expected let expectedURLRequestMethods: [String] = keys.map { _ in "PUT" } - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), expectedURLRequestMethods) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, expectedURLRequestMethods) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -449,12 +449,12 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { // An SDK call for the ListObjectsV2 call and each deletion is expected let expectedMethods = [.get] + keys.map {_ in HttpMethodType.delete} - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), expectedMethods) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, expectedMethods) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) // A URLRequest call for each uploaded file is expected let expectedURLRequestMethods: [String] = keys.map { _ in "PUT" } - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), expectedURLRequestMethods) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, expectedURLRequestMethods) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -468,10 +468,10 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { let result = try await Amplify.Storage.remove(key: key, options: nil) XCTAssertEqual(result, key) - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -484,10 +484,10 @@ class AWSS3StoragePluginBasicIntegrationTests: AWSS3StoragePluginTestBase { let result = try await Amplify.Storage.remove(key: key, options: nil) XCTAssertEqual(result, key) - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), []) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, []) } // /// Given: Object with key `key` in storage diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginGetURLIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginGetURLIntegrationTests.swift index 718cc2370e..fbc9c9969b 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginGetURLIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginGetURLIntegrationTests.swift @@ -31,7 +31,7 @@ class AWSS3StoragePluginGetURLIntegrationTests: AWSS3StoragePluginTestBase { let remoteURL = try await Amplify.Storage.getURL(path: .fromString(key)) // The presigned URL generation does not result in an SDK or HTTP call. - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), []) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, []) let (data, response) = try await URLSession.shared.data(from: remoteURL) let httpResponse = try XCTUnwrap(response as? HTTPURLResponse) @@ -63,7 +63,7 @@ class AWSS3StoragePluginGetURLIntegrationTests: AWSS3StoragePluginTestBase { // A S3 HeadObject call is expected XCTAssert(requestRecorder.sdkRequests.map(\.method).allSatisfy { $0 == .head }) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), []) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, []) } /// - Given: A key for a non-existent S3 object @@ -80,7 +80,7 @@ class AWSS3StoragePluginGetURLIntegrationTests: AWSS3StoragePluginTestBase { XCTAssertNotNil(url) // No SDK or URLRequest calls expected - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), []) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), []) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, []) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, []) } } diff --git a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift index e5ff4462d6..4c94b7397f 100644 --- a/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift +++ b/AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginUploadIntegrationTests.swift @@ -67,10 +67,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) // Only the remove operation results in an SDK request - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method }, [.delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -83,7 +83,7 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.uploadData(path: .fromString("public/\(key)"), data: data, options: nil).value _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -101,10 +101,10 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) // Only the remove operation results in an SDK request - XCTAssertEqual(requestRecorder.sdkRequests.map(\.method), [.delete]) + XCTAssertEqual(requestRecorder.sdkRequests.map { $0.method}, [.delete]) try assertUserAgentComponents(sdkRequests: requestRecorder.sdkRequests) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) } @@ -120,7 +120,7 @@ class AWSS3StoragePluginUploadIntegrationTests: AWSS3StoragePluginTestBase { _ = try await Amplify.Storage.uploadFile(path: .fromString("public/\(key)"), local: fileURL, options: nil).value _ = try await Amplify.Storage.remove(path: .fromString("public/\(key)")) - XCTAssertEqual(requestRecorder.urlRequests.map(\.httpMethod), ["PUT"]) + XCTAssertEqual(requestRecorder.urlRequests.map { $0.httpMethod }, ["PUT"]) try assertUserAgentComponents(urlRequests: requestRecorder.urlRequests) }