Test update/delete on merge provider index

This commit is contained in:
Davide De Rosa 2022-04-26 18:56:55 +02:00
parent 259a7e18ca
commit e10f33717d
2 changed files with 26 additions and 21 deletions

View File

@ -106,13 +106,18 @@ class ProviderRepository: Repository {
// update existing
providers.forEach { dto in
guard let name = dto.name else {
return
}
guard let ws = index.metadata.first(where: {
$0.name == dto.name
$0.name == name
}) else {
// delete if not in new index
pp_log.info("Deleting provider: \(name)")
context.delete(dto)
return
}
pp_log.info("Updating provider: \(name)")
dto.fullName = ws.fullName
dto.lastUpdate = Date()
}

View File

@ -58,26 +58,26 @@ class ProvidersTests: XCTestCase {
override func tearDown() {
// manager.reset()
}
// func testLoadBundledProviders() throws {
// let exp = expectation(description: "Load bundle")
//
// manager.loadBundledProvidersPublisher(vpnProtocol: .openVPN)
// .sink {
// switch $0 {
// case .finished:
// exp.fulfill()
//
// case .failure(let error):
// pp_log.error("Unable to load bundled providers: \(error)")
// exp.fulfill()
// }
// } receiveValue: {
// pp_log.debug("Loaded \($0.count) providers")
// }.store(in: &cancellables)
//
// waitForExpectations(timeout: 10.0, handler: nil)
// }
func testFetchLocalIndex() throws {
let exp = expectation(description: "Local index")
manager.fetchProvidersIndexPublisher(priority: .bundle)
.sink {
switch $0 {
case .finished:
exp.fulfill()
case .failure(let error):
pp_log.error("Unable to load remote provider: \(error)")
exp.fulfill()
}
} receiveValue: {
pp_log.debug("Loaded index")
}.store(in: &cancellables)
waitForExpectations(timeout: 10.0, handler: nil)
}
func testFetchRemoteIndex() throws {
let exp = expectation(description: "Remote index")