Skip to content

Commit 27efb92

Browse files
committed
Work in Progress
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 1226ae0 commit 27efb92

5 files changed

Lines changed: 75 additions & 47 deletions

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
],
2020
dependencies: [
2121
.package(url: "https://github.com/nextcloud/NextcloudCapabilitiesKit.git", from: "2.4.0"),
22-
.package(url: "https://github.com/nextcloud/NextcloudKit", exact: "7.2.2"),
22+
.package(path: "../NextcloudKit"),
2323
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.55.0"),
2424
.package(url: "https://github.com/realm/realm-swift.git", from: "20.0.1"),
2525
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0")

Sources/NextcloudFileProviderKitMocks/FileProviderLogMock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public actor FileProviderLogMock: FileProviderLogging {
1212
logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FileProviderLogMock")
1313
}
1414

15-
public func write(category _: String, level _: OSLogType, message: String, details _: [FileProviderLogDetailKey: Any?]) {
15+
public func write(category _: String, level _: OSLogType, message: String, details _: [FileProviderLogDetailKey: (any Sendable)?]) {
1616
logger.debug("\(message, privacy: .public)")
1717
}
1818
}

Sources/NextcloudFileProviderKitMocks/TestableRemoteInterface.swift

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
2929
account _: Account,
3030
options _: NKRequestOptions,
3131
requestHandler _: @escaping (UploadRequest) -> Void,
32-
taskHandler _: @escaping (URLSessionTask) -> Void,
32+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void,
3333
progressHandler _: @escaping (Progress) -> Void
3434
) async -> (
3535
account: String,
@@ -56,7 +56,7 @@ public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
5656
log _: any FileProviderLogging,
5757
chunkUploadStartHandler _: @escaping ([RemoteFileChunk]) -> Void,
5858
requestHandler _: @escaping (UploadRequest) -> Void,
59-
taskHandler _: @escaping (URLSessionTask) -> Void,
59+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void,
6060
progressHandler _: @escaping (Progress) -> Void,
6161
chunkUploadCompleteHandler _: @escaping (RemoteFileChunk) -> Void
6262
) async -> (
@@ -74,17 +74,17 @@ public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
7474
overwrite _: Bool,
7575
account _: Account,
7676
options _: NKRequestOptions,
77-
taskHandler _: @escaping (URLSessionTask) -> Void
77+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void
7878
) async -> (account: String, data: Data?, error: NKError) { ("", nil, .invalidResponseError) }
7979

8080
public func downloadAsync(
81-
serverUrlFileName _: Any,
82-
fileNameLocalPath _: String,
83-
account _: String,
84-
options _: NKRequestOptions,
85-
requestHandler _: @escaping (_ request: DownloadRequest) -> Void,
86-
taskHandler _: @escaping (_ task: URLSessionTask) -> Void,
87-
progressHandler _: @escaping (_ progress: Progress) -> Void
81+
serverUrlFileName: Any,
82+
fileNameLocalPath: String,
83+
account: String,
84+
options: NKRequestOptions,
85+
requestHandler: @escaping (_ request: DownloadRequest) -> Void,
86+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void,
87+
progressHandler: @escaping (_ progress: Progress) -> Void
8888
) async -> (
8989
account: String,
9090
etag: String?,
@@ -105,7 +105,7 @@ public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
105105
requestBody _: Data?,
106106
account _: Account,
107107
options _: NKRequestOptions,
108-
taskHandler _: @escaping (URLSessionTask) -> Void
108+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void
109109
) async -> (account: String, files: [NKFile], data: AFDataResponse<Data>?, error: NKError) {
110110
("", [], nil, .invalidResponseError)
111111
}
@@ -114,54 +114,69 @@ public struct TestableRemoteInterface: RemoteInterface, @unchecked Sendable {
114114
remotePath _: String,
115115
account _: Account,
116116
options _: NKRequestOptions,
117-
taskHandler _: @escaping (URLSessionTask) -> Void
117+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void
118118
) async -> (account: String, response: HTTPURLResponse?, error: NKError) {
119119
("", nil, .invalidResponseError)
120120
}
121121

122-
public func lockUnlockFile(serverUrlFileName _: String, type _: NKLockType?, shouldLock _: Bool, account _: Account, options _: NKRequestOptions, taskHandler _: @escaping (URLSessionTask) -> Void) async throws -> NKLock? {
122+
public func lockUnlockFile(serverUrlFileName _: String, type _: NKLockType?, shouldLock _: Bool, account _: Account, options _: NKRequestOptions, taskHandler _: @Sendable @escaping (URLSessionTask) -> Void) async throws -> NKLock? {
123123
throw NKError.invalidResponseError
124124
}
125125

126-
public func trashedItems(
127-
account _: Account, options _: NKRequestOptions, taskHandler _: @escaping (URLSessionTask) -> Void
128-
) async -> (account: String, trashedItems: [NKTrash], data: Data?, error: NKError) {
126+
public func listingTrashAsync(
127+
filename: String?,
128+
showHiddenFiles: Bool,
129+
account: String,
130+
options: NKRequestOptions,
131+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void
132+
) async -> (
133+
account: String,
134+
items: [NKTrash]?,
135+
responseData: AFDataResponse<Data>?,
136+
error: NKError
137+
) {
129138
("", [], nil, .invalidResponseError)
130139
}
131140

132141
public func restoreFromTrash(
133142
filename _: String,
134143
account _: Account,
135144
options _: NKRequestOptions,
136-
taskHandler _: @escaping (URLSessionTask) -> Void
145+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void
137146
) async -> (account: String, data: Data?, error: NKError) { ("", nil, .invalidResponseError) }
138147

139148
public func downloadThumbnail(
140149
url _: URL,
141150
account _: Account,
142151
options _: NKRequestOptions,
143-
taskHandler _: @escaping (URLSessionTask) -> Void
152+
taskHandler _: @Sendable @escaping (URLSessionTask) -> Void
144153
) async -> (account: String, data: Data?, error: NKError) { ("", nil, .invalidResponseError) }
145154

146-
public func fetchUserProfile(
147-
account _: Account, options _: NKRequestOptions, taskHandler _: @escaping (URLSessionTask) -> Void
148-
) async -> (account: String, userProfile: NKUserProfile?, data: Data?, error: NKError) {
155+
public func getUserProfileAsync(
156+
account: String,
157+
options: NKRequestOptions,
158+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void
159+
) async -> (
160+
account: String,
161+
userProfile: NKUserProfile?,
162+
responseData: AFDataResponse<Data>?,
163+
error: NKError
164+
) {
149165
("", nil, nil, .invalidResponseError)
150166
}
151167

152168
public func tryAuthenticationAttempt(
153-
account _: Account, options _: NKRequestOptions, taskHandler _: @escaping (URLSessionTask) -> Void
169+
account _: Account, options _: NKRequestOptions, taskHandler _: @Sendable @escaping (URLSessionTask) -> Void
154170
) async -> AuthenticationAttemptResultState { .connectionError }
155171

156172
public typealias FetchResult = (account: String, capabilities: Capabilities?, data: Data?, error: NKError)
157173

158-
public var fetchCapabilitiesHandler:
159-
((Account, NKRequestOptions, @escaping (URLSessionTask) -> Void) async -> FetchResult)?
174+
public var fetchCapabilitiesHandler: (@Sendable (Account, NKRequestOptions, @Sendable @escaping (URLSessionTask) -> Void) async -> FetchResult)?
160175

161176
public func fetchCapabilities(
162177
account: Account,
163178
options: NKRequestOptions = .init(),
164-
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in }
179+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void = { _ in }
165180
) async -> FetchResult {
166181
let ncKitAccount = account.ncKitAccount
167182
await RetrievedCapabilitiesActor.shared.setOngoingFetch(

Tests/Interface/MockChangeNotificationInterface.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import Foundation
55
import NextcloudFileProviderKit
66

7-
public class MockChangeNotificationInterface: ChangeNotificationInterface, @unchecked Sendable {
8-
public var changeHandler: (() -> Void)?
9-
public init(changeHandler: (() -> Void)? = nil) {
7+
final public class MockChangeNotificationInterface: ChangeNotificationInterface {
8+
let changeHandler: (@Sendable () -> Void)?
9+
10+
public init(changeHandler: (@Sendable () -> Void)? = nil) {
1011
self.changeHandler = changeHandler
1112
}
1213

Tests/Interface/MockRemoteInterface.swift

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
621621
return sanitisedPath
622622
}
623623

624-
func item(remotePath: String, account: Account) -> MockRemoteItem? {
624+
func item(remotePath: String, account: String) -> MockRemoteItem? {
625625
guard let rootItem, !remotePath.isEmpty else {
626626
print("Invalid root item or remote path, cannot get item in item tree.")
627627
return nil
@@ -996,10 +996,10 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
996996
serverUrlFileName: Any,
997997
fileNameLocalPath: String,
998998
account: String,
999-
options _: NKRequestOptions,
1000-
requestHandler _: @escaping (_ request: DownloadRequest) -> Void = { _ in },
1001-
taskHandler _: @escaping (_ task: URLSessionTask) -> Void = { _ in },
1002-
progressHandler _: @escaping (_ progress: Progress) -> Void = { _ in }
999+
options: NKRequestOptions,
1000+
requestHandler: @escaping (_ request: DownloadRequest) -> Void,
1001+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void,
1002+
progressHandler: @escaping (_ progress: Progress) -> Void
10031003
) async -> (
10041004
account: String,
10051005
etag: String?,
@@ -1034,11 +1034,11 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
10341034
}
10351035
} catch {
10361036
print("Could not write item data: \(error)")
1037-
return (account.ncKitAccount, nil, nil, 0, nil, nil, .urlError)
1037+
return (account, nil, nil, 0, nil, nil, .urlError)
10381038
}
10391039

10401040
return (
1041-
account.ncKitAccount,
1041+
account,
10421042
item.versionIdentifier,
10431043
item.creationDate as Date,
10441044
item.size,
@@ -1194,11 +1194,18 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
11941194
return nil
11951195
}
11961196

1197-
public func trashedItems(
1198-
account: Account,
1199-
options _: NKRequestOptions = .init(),
1200-
taskHandler _: @escaping (URLSessionTask) -> Void = { _ in }
1201-
) async -> (account: String, trashedItems: [NKTrash], data: Data?, error: NKError) {
1197+
public func listingTrashAsync(
1198+
filename: String?,
1199+
showHiddenFiles: Bool,
1200+
account: String,
1201+
options: NKRequestOptions,
1202+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void
1203+
) async -> (
1204+
account: String,
1205+
items: [NKTrash]?,
1206+
responseData: AFDataResponse<Data>?,
1207+
error: NKError
1208+
) {
12021209
guard let rootTrashItem else { return (account.ncKitAccount, [], nil, .invalidData) }
12031210
return (account.ncKitAccount, rootTrashItem.children.map { $0.toNKTrash() }, nil, .success)
12041211
}
@@ -1247,11 +1254,16 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
12471254
return Capabilities(data: capsData ?? Data())
12481255
}
12491256

1250-
public func fetchUserProfile(
1251-
account: Account,
1252-
options _: NKRequestOptions = .init(),
1253-
taskHandler _: @escaping (URLSessionTask) -> Void = { _ in }
1254-
) async -> (account: String, userProfile: NKUserProfile?, data: Data?, error: NKError) {
1257+
func getUserProfileAsync(
1258+
account: String,
1259+
options: NKRequestOptions,
1260+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void
1261+
) async -> (
1262+
account: String,
1263+
userProfile: NKUserProfile?,
1264+
responseData: AFDataResponse<Data>?,
1265+
error: NKError
1266+
) {
12551267
let profile = NKUserProfile()
12561268
profile.address = account.serverUrl
12571269
profile.backend = "mock"

0 commit comments

Comments
 (0)