-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathOutgoingConnectionServiceTests.swift
50 lines (45 loc) · 1.68 KB
/
OutgoingConnectionServiceTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// OutgoingConnectionServiceTests.swift
// MullvadVPNTests
//
// Created by Mojgan on 2023-11-02.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import Foundation
@testable import MullvadVPN
import XCTest
final class OutgoingConnectionServiceTests: XCTestCase {
func testSuccessGetOutgoingConnectionInfo() async throws {
let mockOutgoingConnectionProxy = OutgoingConnectionProxyStub(
ipV4: .mock,
ipV6: .mock,
error: nil
)
let outgoingConnectionService = OutgoingConnectionService(outgoingConnectionProxy: mockOutgoingConnectionProxy)
let successExpectation = expectation(description: "Did receive exit IPs")
let result = try await outgoingConnectionService.getOutgoingConnectionInfo()
if result.ipv4 == .mock,
result.ipv6 == .mock {
successExpectation.fulfill()
}
await fulfillment(of: [successExpectation], timeout: 1.0)
}
func testFailureGetOutgoingConnectionInfo() async throws {
let mockOutgoingConnectionProxy = OutgoingConnectionProxyStub(
ipV4: .mock,
ipV6: .mock,
error: NetworkErrorStub.somethingWentWrong
)
let outgoingConnectionService = OutgoingConnectionService(outgoingConnectionProxy: mockOutgoingConnectionProxy)
let failExpectation = expectation(description: "Did not receive exit IPs")
do {
_ = try await outgoingConnectionService.getOutgoingConnectionInfo()
} catch {
failExpectation.fulfill()
}
await fulfillment(of: [failExpectation], timeout: 1.0)
}
}
enum NetworkErrorStub: Error {
case somethingWentWrong
}