Skip to content

Commit 23fdff9

Browse files
committed
Work in progress: Fixed some test run time errors.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 9ab9ad9 commit 23fdff9

13 files changed

Lines changed: 160 additions & 151 deletions

Tests/Interface/MockRemoteInterface.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,12 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
576576
public var enumerateCallHandler: ((String, EnumerateDepth, Bool, [String], Data?, Account, NKRequestOptions, @escaping (URLSessionTask) -> Void) -> Void)?
577577

578578
public init(
579+
account: Account,
579580
rootItem: MockRemoteItem? = nil,
580581
rootTrashItem: MockRemoteItem? = nil,
581582
pagination: Bool = false
582583
) {
584+
self.mockedAccounts[account.ncKitAccount] = account
583585
self.rootItem = rootItem
584586
self.rootTrashItem = rootTrashItem
585587
self.pagination = pagination

Tests/InterfaceTests/MockRemoteInterfaceTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
2020
}
2121

2222
func testItemForRemotePath() {
23-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
23+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
2424
debugPrint(remoteInterface)
2525
let itemA = MockRemoteItem(
2626
identifier: "a",
@@ -82,15 +82,15 @@ final class MockRemoteInterfaceTests: XCTestCase {
8282
}
8383

8484
func testItemForRootPath() {
85-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
85+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
8686
debugPrint(remoteInterface)
8787
XCTAssertEqual(
8888
remoteInterface.item(remotePath: Self.account.davFilesUrl, account: Self.account.ncKitAccount), rootItem
8989
)
9090
}
9191

9292
func testPathParentPath() {
93-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
93+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
9494
debugPrint(remoteInterface)
9595
let testPath = Self.account.davFilesUrl + "/a/B/c/d"
9696
let expectedPath = Self.account.davFilesUrl + "/a/B/c"
@@ -101,7 +101,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
101101
}
102102

103103
func testRootPathParentPath() {
104-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
104+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
105105
debugPrint(remoteInterface)
106106
let testPath = Self.account.davFilesUrl + "/"
107107
let expectedPath = Self.account.davFilesUrl + "/"
@@ -112,7 +112,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
112112
}
113113

114114
func testNameFromPath() throws {
115-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
115+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
116116
debugPrint(remoteInterface)
117117
let testPath = Self.account.davFilesUrl + "/a/b/c/d"
118118
let expectedName = "d"
@@ -121,7 +121,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
121121
}
122122

123123
func testCreateFolder() async {
124-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
124+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
125125
debugPrint(remoteInterface)
126126
let newFolderAPath = Self.account.davFilesUrl + "/A"
127127
let newFolderA_BPath = Self.account.davFilesUrl + "/A/B/"
@@ -148,7 +148,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
148148
}
149149

150150
func testUpload() async throws {
151-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
151+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
152152
debugPrint(remoteInterface)
153153
let fileUrl = URL.temporaryDirectory.appendingPathComponent("file.txt", conformingTo: .text)
154154
let fileData = Data("Hello, World!".utf8)
@@ -174,7 +174,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
174174
}
175175

176176
func testUploadTargetName() async throws {
177-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
177+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
178178
debugPrint(remoteInterface)
179179
let fileName = UUID().uuidString
180180
let fileUrl = URL.temporaryDirectory.appendingPathComponent(fileName)
@@ -202,9 +202,9 @@ final class MockRemoteInterfaceTests: XCTestCase {
202202
let data = Data(repeating: 1, count: 8)
203203
try data.write(to: fileUrl)
204204

205-
let remoteInterface =
206-
MockRemoteInterface(rootItem: MockRemoteItem.rootItem(account: Self.account))
205+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: MockRemoteItem.rootItem(account: Self.account))
207206
debugPrint(remoteInterface)
207+
208208
let remotePath = Self.account.davFilesUrl + "/file.txt"
209209
let chunkSize = 3
210210
var uploadedChunks = [RemoteFileChunk]()
@@ -261,7 +261,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
261261
let previousUploadedChunks = [previousUploadedChunk]
262262

263263
let remoteInterface =
264-
MockRemoteInterface(rootItem: MockRemoteItem.rootItem(account: Self.account))
264+
MockRemoteInterface(account: Self.account, rootItem: MockRemoteItem.rootItem(account: Self.account))
265265
debugPrint(remoteInterface)
266266
remoteInterface.currentChunks = [uploadUuid: previousUploadedChunks]
267267

@@ -317,7 +317,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
317317
}
318318

319319
func testMove() async {
320-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
320+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
321321
debugPrint(remoteInterface)
322322
let itemA = MockRemoteItem(
323323
identifier: "a",
@@ -382,7 +382,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
382382
}
383383

384384
func testDownload() async throws {
385-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
385+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
386386
remoteInterface.injectMock(Self.account)
387387

388388
debugPrint(remoteInterface)
@@ -415,7 +415,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
415415
}
416416

417417
func testEnumerate() async {
418-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
418+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
419419
debugPrint(remoteInterface)
420420
let itemA = MockRemoteItem(
421421
identifier: "a",
@@ -571,7 +571,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
571571
}
572572

573573
func testDelete() async {
574-
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
574+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem, rootTrashItem: rootTrashItem)
575575
debugPrint(remoteInterface)
576576
let itemA = MockRemoteItem(
577577
identifier: "a",
@@ -637,7 +637,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
637637
}
638638

639639
func testTrashedItems() async throws {
640-
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
640+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem, rootTrashItem: rootTrashItem)
641641
debugPrint(remoteInterface)
642642
let itemA = MockRemoteItem(
643643
identifier: "a",
@@ -684,7 +684,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
684684
// consistent (this is what we are able to use to match pre-trashing items with their
685685
// post-trashing metadata)
686686
func testTrashingManglesIdentifiers() async {
687-
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
687+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem, rootTrashItem: rootTrashItem)
688688
debugPrint(remoteInterface)
689689
let folderOriginalIdentifier = "folder"
690690
let folder = MockRemoteItem(
@@ -730,7 +730,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
730730
}
731731

732732
func testRestoreFromTrash() async {
733-
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
733+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem, rootTrashItem: rootTrashItem)
734734
debugPrint(remoteInterface)
735735
let itemA = MockRemoteItem(
736736
identifier: "a",
@@ -759,7 +759,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
759759
}
760760

761761
func testNoDirectMoveFromTrash() async {
762-
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
762+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem, rootTrashItem: rootTrashItem)
763763
debugPrint(remoteInterface)
764764
let folder = MockRemoteItem(
765765
identifier: "folder",
@@ -813,7 +813,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
813813
}
814814

815815
func testEnforceOverwriteOnRestore() async {
816-
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
816+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem, rootTrashItem: rootTrashItem)
817817
debugPrint(remoteInterface)
818818
let itemA = MockRemoteItem(
819819
identifier: "a",
@@ -848,7 +848,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
848848
}
849849

850850
func testFetchUserProfile() async {
851-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
851+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
852852
debugPrint(remoteInterface)
853853

854854
let (account, profile, _, error) = await remoteInterface.getUserProfileAsync(
@@ -863,7 +863,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
863863
}
864864

865865
func testTryAuthenticationAttempt() async {
866-
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
866+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
867867
debugPrint(remoteInterface)
868868
let state = await remoteInterface.tryAuthenticationAttempt(account: Self.account)
869869
XCTAssertEqual(state, .success)

0 commit comments

Comments
 (0)