Skip to content

Commit

Permalink
updated swiftformat rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 9, 2024
1 parent 78bd9ff commit 9f73de8
Show file tree
Hide file tree
Showing 259 changed files with 2,465 additions and 1,961 deletions.
18 changes: 10 additions & 8 deletions AmplifyTestCommon/Helpers/AmplifyAssertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import XCTest

@testable import CwlPreconditionTesting

public func XCTAssertThrowFatalError(_ expression: @escaping () -> Void,
file: StaticString = #file,
line: UInt = #line) throws
{
public func XCTAssertThrowFatalError(
_ expression: @escaping () -> Void,
file: StaticString = #file,
line: UInt = #line
) throws {
#if (os(iOS) || os(macOS)) && (arch(arm64) || arch(x86_64))
var reached = false
let exception = catchBadInstruction {
Expand All @@ -27,10 +28,11 @@ public func XCTAssertThrowFatalError(_ expression: @escaping () -> Void,
#endif
}

public func XCTAssertNoThrowFatalError(_ expression: @escaping () -> Void,
file: StaticString = #file,
line: UInt = #line) throws
{
public func XCTAssertNoThrowFatalError(
_ expression: @escaping () -> Void,
file: StaticString = #file,
line: UInt = #line
) throws {
#if (os(iOS) || os(macOS)) && (arch(arm64) || arch(x86_64))
var reached = false
let exception = catchBadInstruction {
Expand Down
13 changes: 7 additions & 6 deletions AmplifyTestCommon/Helpers/HubListenerTestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ enum HubListenerTestUtilities {
/// - Parameter plugin: the plugin on which the listener will be checked
/// - Parameter timeout: the maximum length of time to wait for the listener to be registered
/// - Throws: if the plugin cannot be cast to `AWSHubPlugin`
static func waitForListener(with token: UnsubscribeToken,
plugin: HubCategoryPlugin? = nil,
timeout: TimeInterval,
file: StaticString = #file,
line: UInt = #line) async throws -> Bool
{
static func waitForListener(
with token: UnsubscribeToken,
plugin: HubCategoryPlugin? = nil,
timeout: TimeInterval,
file: StaticString = #file,
line: UInt = #line
) async throws -> Bool {

let plugin = try plugin ?? Amplify.Hub.getPlugin(for: AWSHubPlugin.key)

Expand Down
216 changes: 124 additions & 92 deletions AmplifyTestCommon/Mocks/MockAPICategoryPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import Foundation
class MockAPICategoryPlugin: MessageReporter,
APICategoryPlugin,
APICategoryReachabilityBehavior,
APICategoryGraphQLBehavior
{
APICategoryGraphQLBehavior {

var authProviderFactory: APIAuthProviderFactory?

Expand Down Expand Up @@ -86,12 +85,14 @@ class MockAPICategoryPlugin: MessageReporter,
}

let requestOptions = GraphQLOperationRequest<R>.Options(pluginOptions: nil)
let request = GraphQLOperationRequest<R>(apiName: request.apiName,
operationType: .subscription,
document: request.document,
variables: request.variables,
responseType: request.responseType,
options: requestOptions)
let request = GraphQLOperationRequest<R>(
apiName: request.apiName,
operationType: .subscription,
document: request.document,
variables: request.variables,
responseType: request.responseType,
options: requestOptions
)

let taskRunner = MockAWSGraphQLSubscriptionTaskRunner(request: request)
return taskRunner.sequence
Expand All @@ -113,12 +114,14 @@ class MockAPICategoryPlugin: MessageReporter,

func get(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation {
notify("get")
let operationRequest = RESTOperationRequest(apiName: request.apiName,
operationType: .get,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let operationRequest = RESTOperationRequest(
apiName: request.apiName,
operationType: .get,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: operationRequest)
return operation
}
Expand All @@ -130,124 +133,144 @@ class MockAPICategoryPlugin: MessageReporter,

func put(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation {
notify("put")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .put,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .put,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
return operation
}

func put(request: RESTRequest) async throws -> RESTTask.Success {
notify("put")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .put,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .put,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
let taskAdapter = AmplifyOperationTaskAdapter(operation: operation)
return try await taskAdapter.value
}

func post(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation {
notify("post")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .post,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .post,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
return operation
}

func post(request: RESTRequest) async throws -> RESTTask.Success {
notify("post")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .post,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .post,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
let taskAdapter = AmplifyOperationTaskAdapter(operation: operation)
return try await taskAdapter.value
}

func delete(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation {
notify("delete")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .delete,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .delete,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
return operation
}

func delete(request: RESTRequest) async throws -> RESTTask.Success {
notify("delete")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .delete,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .delete,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
let taskAdapter = AmplifyOperationTaskAdapter(operation: operation)
return try await taskAdapter.value
}

func patch(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation {
notify("patch")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .patch,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .patch,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
return operation
}

func patch(request: RESTRequest) async throws -> RESTTask.Success {
notify("patch")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .patch,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .patch,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
let taskAdapter = AmplifyOperationTaskAdapter(operation: operation)
return try await taskAdapter.value
}

func head(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation {
notify("head")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .head,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .head,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
return operation
}

func head(request: RESTRequest) async throws -> RESTTask.Success {
notify("head")
let request = RESTOperationRequest(apiName: request.apiName,
operationType: .head,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options())
let request = RESTOperationRequest(
apiName: request.apiName,
operationType: .head,
path: request.path,
queryParameters: request.queryParameters,
body: request.body,
options: RESTOperationRequest.Options()
)
let operation = MockAPIOperation(request: request)
let taskAdapter = AmplifyOperationTaskAdapter(operation: operation)
return try await taskAdapter.value
Expand Down Expand Up @@ -282,12 +305,15 @@ class MockGraphQLOperation<R: Decodable>: GraphQLOperation<R> {
override func resume() {
}

init(request: Request,
responseType: R.Type)
{
super.init(categoryType: .api,
eventName: HubPayload.EventName.API.mutate,
request: request)
init(
request: Request,
responseType: R.Type
) {
super.init(
categoryType: .api,
eventName: HubPayload.EventName.API.mutate,
request: request
)
}
}

Expand All @@ -299,12 +325,15 @@ class MockSubscriptionGraphQLOperation<R: Decodable>: GraphQLSubscriptionOperati
override func resume() {
}

init(request: Request,
responseType: R.Type)
{
super.init(categoryType: .api,
eventName: HubPayload.EventName.API.subscribe,
request: request)
init(
request: Request,
responseType: R.Type
) {
super.init(
categoryType: .api,
eventName: HubPayload.EventName.API.subscribe,
request: request
)
}
}

Expand All @@ -316,19 +345,22 @@ class MockAPIOperation: AmplifyOperation<RESTOperationRequest, Data, APIError>,
}

init(request: Request) {
super.init(categoryType: .api,
eventName: request.operationType.hubEventName,
request: request)
super.init(
categoryType: .api,
eventName: request.operationType.hubEventName,
request: request
)
}
}

class MockAPIAuthProviderFactory: APIAuthProviderFactory {
let oidcProvider: AmplifyOIDCAuthProvider?
let functionProvider: AmplifyFunctionAuthProvider?

init(oidcProvider: AmplifyOIDCAuthProvider? = nil,
functionProvider: AmplifyFunctionAuthProvider? = nil)
{
init(
oidcProvider: AmplifyOIDCAuthProvider? = nil,
functionProvider: AmplifyFunctionAuthProvider? = nil
) {
self.oidcProvider = oidcProvider
self.functionProvider = functionProvider
}
Expand Down
Loading

0 comments on commit 9f73de8

Please sign in to comment.