-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New Feature: Health Check * Fix test for linux comparison * Simplify error check for linux * Remove debugDescription in ParseHealth
- Loading branch information
Showing
17 changed files
with
350 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ParseHealth+Combine.swift | ||
// ParseSwift | ||
// | ||
// Created by Corey Baker on 4/28/21. | ||
// Copyright © 2021 Parse Community. All rights reserved. | ||
// | ||
|
||
#if canImport(Combine) | ||
import Foundation | ||
import Combine | ||
|
||
// MARK: Combine | ||
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) | ||
public extension ParseHealth { | ||
|
||
// MARK: Check - Combine | ||
|
||
/** | ||
Calls the health check function *asynchronously*. Publishes when complete. | ||
- parameter options: A set of header options sent to the server. Defaults to an empty set. | ||
- returns: A publisher that eventually produces a single value and then finishes or fails. | ||
*/ | ||
static func checkPublisher(options: API.Options = []) -> Future<String, ParseError> { | ||
Future { promise in | ||
Self.check(options: options, | ||
completion: promise) | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// ParseHealth.swift | ||
// ParseSwift | ||
// | ||
// Created by Corey Baker on 4/28/21. | ||
// Copyright © 2021 Parse Community. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
`ParseHealth` allows you to check the health of a Parse Server. | ||
*/ | ||
public struct ParseHealth: ParseType, Decodable { | ||
|
||
/** | ||
Calls the health check function *synchronously* and returns a result of it's execution. | ||
- parameter options: A set of header options sent to the server. Defaults to an empty set. | ||
- returns: Returns the status of the server. | ||
- throws: An error of type `ParseError`. | ||
*/ | ||
static public func check(options: API.Options = []) throws -> String { | ||
try healthCommand().execute(options: options) | ||
} | ||
|
||
/** | ||
Calls the health check function *asynchronously* and returns a result of it's execution. | ||
- parameter options: A set of header options sent to the server. Defaults to an empty set. | ||
- parameter callbackQueue: The queue to return to after completion. Default value of .main. | ||
- parameter completion: A block that will be called when the health check completes or fails. | ||
It should have the following argument signature: `(Result<String, ParseError>)`. | ||
*/ | ||
static public func check(options: API.Options = [], | ||
callbackQueue: DispatchQueue = .main, | ||
completion: @escaping (Result<String, ParseError>) -> Void) { | ||
healthCommand() | ||
.executeAsync(options: options) { result in | ||
callbackQueue.async { | ||
completion(result) | ||
} | ||
} | ||
} | ||
|
||
internal static func healthCommand() -> API.NonParseBodyCommand<NoBody, String> { | ||
return API.NonParseBodyCommand(method: .POST, | ||
path: .health) { (data) -> String in | ||
return try ParseCoding.jsonDecoder().decode(HealthResponse.self, from: data).status | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// ParseHealthCombineTests.swift | ||
// ParseSwift | ||
// | ||
// Created by Corey Baker on 4/28/21. | ||
// Copyright © 2021 Parse Community. All rights reserved. | ||
// | ||
|
||
#if canImport(Combine) | ||
|
||
import Foundation | ||
import XCTest | ||
import Combine | ||
@testable import ParseSwift | ||
|
||
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) | ||
class ParseHealthCombineTests: XCTestCase { | ||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
guard let url = URL(string: "http://localhost:1337/1") else { | ||
XCTFail("Should create valid URL") | ||
return | ||
} | ||
ParseSwift.initialize(applicationId: "applicationId", | ||
clientKey: "clientKey", | ||
masterKey: "masterKey", | ||
serverURL: url, | ||
testing: true) | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
try super.tearDownWithError() | ||
MockURLProtocol.removeAll() | ||
#if !os(Linux) && !os(Android) | ||
try KeychainStore.shared.deleteAll() | ||
#endif | ||
try ParseStorage.shared.deleteAll() | ||
} | ||
|
||
func testCheck() { | ||
var subscriptions = Set<AnyCancellable>() | ||
let expectation1 = XCTestExpectation(description: "Save") | ||
|
||
let healthOfServer = "ok" | ||
let serverResponse = HealthResponse(status: healthOfServer) | ||
let encoded: Data! | ||
do { | ||
encoded = try ParseCoding.jsonEncoder().encode(serverResponse) | ||
} catch { | ||
XCTFail("Should encode/decode. Error \(error)") | ||
return | ||
} | ||
|
||
MockURLProtocol.mockRequests { _ in | ||
return MockURLResponse(data: encoded, statusCode: 200, delay: 0.0) | ||
} | ||
|
||
let publisher = ParseHealth.checkPublisher() | ||
.sink(receiveCompletion: { result in | ||
|
||
if case let .failure(error) = result { | ||
XCTFail(error.localizedDescription) | ||
} | ||
expectation1.fulfill() | ||
|
||
}, receiveValue: { health in | ||
XCTAssertEqual(health, healthOfServer) | ||
}) | ||
publisher.store(in: &subscriptions) | ||
|
||
wait(for: [expectation1], timeout: 20.0) | ||
} | ||
} | ||
#endif |
Oops, something went wrong.