Skip to content

Commit

Permalink
update rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 14, 2024
1 parent 3a2d81a commit 2326834
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 }, [])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit 2326834

Please sign in to comment.