-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab77d83
commit 4da5029
Showing
6 changed files
with
227 additions
and
81 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
Tests/NetworkReachabilityTests/NetworkMonitorCombineTests.swift
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,61 @@ | ||
// NetworkReachabiliy | ||
// NetworkMonitorCombineTests.swift | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2021 Varun Santhanam | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the Software), to deal | ||
// | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#if canImport(Network) | ||
import Network | ||
#endif | ||
|
||
#if canImport(Combine) | ||
|
||
import Combine | ||
import Foundation | ||
@testable import NetworkReachability | ||
import XCTest | ||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
final class NetworkMonitorCombineTests: XCTestCase { | ||
|
||
var cancellable: AnyCancellable? | ||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
func test_observe_combine() { | ||
let expectation = expectation(description: "pass") | ||
cancellable = NetworkMonitor | ||
.networkPathPublisher | ||
.map { $0.status == .satisfied } | ||
.removeDuplicates() | ||
.sink { isReachable in | ||
XCTAssertTrue(isReachable) | ||
expectation.fulfill() | ||
} | ||
waitForExpectations(timeout: 5) | ||
} | ||
|
||
deinit { | ||
cancellable?.cancel() | ||
} | ||
} | ||
|
||
#endif |
55 changes: 55 additions & 0 deletions
55
Tests/NetworkReachabilityTests/NetworkMonitorConcurrencyTests.swift
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,55 @@ | ||
// NetworkReachabiliy | ||
// NetworkMonitorConcurrencyTests.swift | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2021 Varun Santhanam | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the Software), to deal | ||
// | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#if canImport(Network) | ||
import Network | ||
#endif | ||
|
||
import Foundation | ||
@testable import NetworkReachability | ||
import XCTest | ||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
final class NetworkMonitorConcurrencyTests: XCTestCase { | ||
|
||
func test_get_concurrency() async { | ||
let path = await NetworkMonitor.networkPath | ||
XCTAssertEqual(path.status, .satisfied) | ||
} | ||
|
||
func test_observe_concurrency() { | ||
let expectation = expectation(description: "pass") | ||
|
||
Task { | ||
for await status in NetworkMonitor.networkPathUpdates.map(\.status) { | ||
if status == .satisfied { | ||
expectation.fulfill() | ||
} | ||
} | ||
} | ||
waitForExpectations(timeout: 5, handler: nil) | ||
} | ||
|
||
} |
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
58 changes: 58 additions & 0 deletions
58
Tests/NetworkReachabilityTests/ReachabilityMonitorCombineTests.swift
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,58 @@ | ||
// NetworkReachabiliy | ||
// ReachabilityMonitorCombineTests.swift | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2021 Varun Santhanam | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the Software), to deal | ||
// | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#if canImport(Combine) | ||
|
||
import Combine | ||
import Foundation | ||
@testable import NetworkReachability | ||
import XCTest | ||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
final class ReachabilityMonitorConcurrencyTests: XCTestCase { | ||
|
||
var cancellable: AnyCancellable? | ||
|
||
func test_observe_combine() { | ||
let expectation = expectation(description: "pass") | ||
cancellable = ReachabilityMonitor | ||
.reachabilityPublisher | ||
.map(\.status.isReachable) | ||
.replaceError(with: false) | ||
.removeDuplicates() | ||
.sink { isReachable in | ||
XCTAssertTrue(isReachable) | ||
expectation.fulfill() | ||
} | ||
waitForExpectations(timeout: 5) | ||
} | ||
|
||
deinit { | ||
cancellable?.cancel() | ||
} | ||
|
||
} | ||
|
||
#endif |
52 changes: 52 additions & 0 deletions
52
Tests/NetworkReachabilityTests/ReachabilityMonitorConcurrencyTests.swift
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,52 @@ | ||
// NetworkReachabiliy | ||
// ReachabilityMonitorConcurrencyTests.swift | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2021 Varun Santhanam | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the Software), to deal | ||
// | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
import Foundation | ||
@testable import NetworkReachability | ||
import XCTest | ||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
final class ReachabiltyMonitorConcurrencyTests: XCTestCase { | ||
|
||
func test_observe_concurrency() { | ||
let expectation = expectation(description: "pass") | ||
|
||
Task { | ||
do { | ||
for try await isReachable in ReachabilityMonitor.reachabilityUpdates.map(\.status.isReachable) { | ||
if isReachable { | ||
expectation.fulfill() | ||
} else { | ||
XCTFail() | ||
} | ||
} | ||
} catch { | ||
XCTFail() | ||
} | ||
} | ||
waitForExpectations(timeout: 5, handler: nil) | ||
} | ||
|
||
} |
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