diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-11-05 07:37:27 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-11-07 12:46:51 +0100 |
| commit | 485b26bc50543d1a7d2850e9efbb86c57a1f0fe9 (patch) | |
| tree | d9a3418bace056d5fd1cd3f4ba2e87d0a0140be1 | |
| parent | 59a33cc70de48f879a8f5e2d9f78e7533bc14db5 (diff) | |
| download | mullvadvpn-485b26bc50543d1a7d2850e9efbb86c57a1f0fe9.tar.xz mullvadvpn-485b26bc50543d1a7d2850e9efbb86c57a1f0fe9.zip | |
Add tests
| -rw-r--r-- | ios/MullvadRESTTests/DurationTests.swift | 35 | ||||
| -rw-r--r-- | ios/MullvadRESTTests/ExponentialBackoffTests.swift | 59 | ||||
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 120 | ||||
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/xcshareddata/xcschemes/MullvadVPN.xcscheme | 10 |
4 files changed, 224 insertions, 0 deletions
diff --git a/ios/MullvadRESTTests/DurationTests.swift b/ios/MullvadRESTTests/DurationTests.swift new file mode 100644 index 0000000000..c5b5906c02 --- /dev/null +++ b/ios/MullvadRESTTests/DurationTests.swift @@ -0,0 +1,35 @@ +// +// DurationTests.swift +// MullvadRESTTests +// +// Created by pronebird on 05/11/2022. +// Copyright © 2022 Mullvad VPN AB. All rights reserved. +// + +@testable import MullvadREST +import XCTest + +final class DurationTests: XCTestCase { + func testComparable() throws { + XCTAssertEqual(REST.Duration.milliseconds(1000), .seconds(1)) + XCTAssertEqual(REST.Duration.milliseconds(.max), .seconds(.max)) + + XCTAssertGreaterThan(REST.Duration.milliseconds(1001), .seconds(1)) + XCTAssertGreaterThanOrEqual(REST.Duration.seconds(1), .milliseconds(1000)) + + XCTAssertLessThan(REST.Duration.milliseconds(999), .seconds(1)) + XCTAssertLessThanOrEqual(REST.Duration.seconds(1), .milliseconds(1000)) + } + + func testMultiplication() throws { + XCTAssertEqual(REST.Duration.seconds(4) * 4, .seconds(16)) + XCTAssertEqual(REST.Duration.seconds(4) * 4, .seconds(16)) + XCTAssertEqual(REST.Duration.milliseconds(.max - 1) * 2, .milliseconds(.max)) + } + + func testFormat() throws { + XCTAssertEqual(REST.Duration.milliseconds(999).format(), "999ms") + XCTAssertEqual(REST.Duration.milliseconds(1000).format(), "1s") + XCTAssertEqual(REST.Duration.milliseconds(1200).format(), "1.20s") + } +} diff --git a/ios/MullvadRESTTests/ExponentialBackoffTests.swift b/ios/MullvadRESTTests/ExponentialBackoffTests.swift new file mode 100644 index 0000000000..85529e260a --- /dev/null +++ b/ios/MullvadRESTTests/ExponentialBackoffTests.swift @@ -0,0 +1,59 @@ +// +// ExponentialBackoffTests.swift +// ExponentialBackoffTests +// +// Created by pronebird on 05/11/2022. +// Copyright © 2022 Mullvad VPN AB. All rights reserved. +// + +@testable import MullvadREST +import XCTest + +final class ExponentialBackoffTests: XCTestCase { + func testExponentialBackoff() { + var backoff = ExponentialBackoff(initial: .seconds(2), multiplier: 3) + + XCTAssertEqual(backoff.next(), .seconds(2)) + XCTAssertEqual(backoff.next(), .seconds(6)) + XCTAssertEqual(backoff.next(), .seconds(18)) + } + + func testAtMaximumValue() { + var backoff = ExponentialBackoff(initial: .milliseconds(.max - 1), multiplier: 2) + + XCTAssertEqual(backoff.next(), .milliseconds(.max - 1)) + XCTAssertEqual(backoff.next(), .seconds(.max)) + XCTAssertEqual(backoff.next(), .seconds(.max)) + } + + func testMaximumBound() { + var backoff = ExponentialBackoff( + initial: .milliseconds(2), + multiplier: 3, + maxDelay: .milliseconds(7) + ) + + XCTAssertEqual(backoff.next(), .milliseconds(2)) + XCTAssertEqual(backoff.next(), .milliseconds(6)) + XCTAssertEqual(backoff.next(), .milliseconds(7)) + } + + func testMinimumValue() { + var backoff = ExponentialBackoff(initial: .milliseconds(0), multiplier: 10) + + XCTAssertEqual(backoff.next(), .milliseconds(0)) + XCTAssertEqual(backoff.next(), .milliseconds(0)) + + backoff = ExponentialBackoff(initial: .milliseconds(1), multiplier: 0) + + XCTAssertEqual(backoff.next(), .milliseconds(1)) + XCTAssertEqual(backoff.next(), .milliseconds(0)) + } + + func testJitter() { + let initial = REST.Duration.milliseconds(500) + var iterator = Jittered(ExponentialBackoff(initial: initial, multiplier: 3)) + + XCTAssertGreaterThanOrEqual(iterator.next()!, initial) + } +} diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 6c393d2cad..a1cea3ff0a 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -304,6 +304,9 @@ 58F8AC0E25D3F8CE002BE0ED /* ProblemReportReviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58F8AC0D25D3F8CE002BE0ED /* ProblemReportReviewViewController.swift */; }; 58FB865526E8BF3100F188BC /* StorePaymentManagerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FB865426E8BF3100F188BC /* StorePaymentManagerError.swift */; }; 58FB865A26EA214400F188BC /* RelayCacheTrackerObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FB865926EA214400F188BC /* RelayCacheTrackerObserver.swift */; }; + 58FBFBE9291622580020E046 /* ExponentialBackoffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FBFBE8291622580020E046 /* ExponentialBackoffTests.swift */; }; + 58FBFBEA291622580020E046 /* MullvadREST.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06799ABC28F98E1D00ACD94E /* MullvadREST.framework */; }; + 58FBFBF1291630700020E046 /* DurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FBFBF0291630700020E046 /* DurationTests.swift */; }; 58FC040A27B3EE03001C21F0 /* TunnelMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FC040927B3EE03001C21F0 /* TunnelMonitor.swift */; }; 58FD5BE724192A2C00112C88 /* StoreReceipt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD5BE624192A2B00112C88 /* StoreReceipt.swift */; }; 58FD5BF024238EB300112C88 /* SKProduct+Formatting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD5BEF24238EB300112C88 /* SKProduct+Formatting.swift */; }; @@ -434,6 +437,13 @@ remoteGlobalIDString = 58FBDA9722A519BC00EB69A3; remoteInfo = WireGuardGoBridge; }; + 58FBFBEB291622580020E046 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 58CE5E58224146200008646E /* Project object */; + proxyType = 1; + remoteGlobalIDString = 06799ABB28F98E1D00ACD94E; + remoteInfo = MullvadREST; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -787,6 +797,9 @@ 58F8AC0D25D3F8CE002BE0ED /* ProblemReportReviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProblemReportReviewViewController.swift; sourceTree = "<group>"; }; 58FB865426E8BF3100F188BC /* StorePaymentManagerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorePaymentManagerError.swift; sourceTree = "<group>"; }; 58FB865926EA214400F188BC /* RelayCacheTrackerObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayCacheTrackerObserver.swift; sourceTree = "<group>"; }; + 58FBFBE6291622580020E046 /* MullvadRESTTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MullvadRESTTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 58FBFBE8291622580020E046 /* ExponentialBackoffTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExponentialBackoffTests.swift; sourceTree = "<group>"; }; + 58FBFBF0291630700020E046 /* DurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DurationTests.swift; sourceTree = "<group>"; }; 58FC040927B3EE03001C21F0 /* TunnelMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelMonitor.swift; sourceTree = "<group>"; }; 58FD5BE624192A2B00112C88 /* StoreReceipt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreReceipt.swift; sourceTree = "<group>"; }; 58FD5BEF24238EB300112C88 /* SKProduct+Formatting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SKProduct+Formatting.swift"; sourceTree = "<group>"; }; @@ -919,6 +932,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 58FBFBE3291622580020E046 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 58FBFBEA291622580020E046 /* MullvadREST.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -1200,6 +1221,7 @@ 581943D728F800C900B0CB5E /* MullvadLogging */, 581943F228F8014500B0CB5E /* MullvadTypes */, 06799ABD28F98E1D00ACD94E /* MullvadREST */, + 58FBFBE7291622580020E046 /* MullvadRESTTests */, 063F02742902B63F001FA09F /* RelayCache */, 5898D29929017DAC00EB5EBA /* RelaySelector */, 5898D28A29017BD400EB5EBA /* TunnelProviderMessaging */, @@ -1226,6 +1248,7 @@ 063F02732902B63F001FA09F /* RelayCache.framework */, 5898D28929017BD400EB5EBA /* libTunnelProviderMessaging.a */, 5898D29829017DAC00EB5EBA /* libRelaySelector.a */, + 58FBFBE6291622580020E046 /* MullvadRESTTests.xctest */, ); name = Products; sourceTree = "<group>"; @@ -1447,6 +1470,15 @@ path = Assets; sourceTree = "<group>"; }; + 58FBFBE7291622580020E046 /* MullvadRESTTests */ = { + isa = PBXGroup; + children = ( + 58FBFBF0291630700020E046 /* DurationTests.swift */, + 58FBFBE8291622580020E046 /* ExponentialBackoffTests.swift */, + ); + path = MullvadRESTTests; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -1733,6 +1765,24 @@ productReference = 58E5126528DDF04200B0BCDE /* libOperations.a */; productType = "com.apple.product-type.library.static"; }; + 58FBFBE5291622580020E046 /* MullvadRESTTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 58FBFBEF291622580020E046 /* Build configuration list for PBXNativeTarget "MullvadRESTTests" */; + buildPhases = ( + 58FBFBE2291622580020E046 /* Sources */, + 58FBFBE3291622580020E046 /* Frameworks */, + 58FBFBE4291622580020E046 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 58FBFBEC291622580020E046 /* PBXTargetDependency */, + ); + name = MullvadRESTTests; + productName = MullvadRESTTests; + productReference = 58FBFBE6291622580020E046 /* MullvadRESTTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -1799,6 +1849,9 @@ 58FBDA9722A519BC00EB69A3 = { CreatedOnToolsVersion = 10.2.1; }; + 58FBFBE5291622580020E046 = { + CreatedOnToolsVersion = 14.1; + }; }; }; buildConfigurationList = 58CE5E5B224146200008646E /* Build configuration list for PBXProject "MullvadVPN" */; @@ -1828,6 +1881,7 @@ 581943D528F800C900B0CB5E /* MullvadLogging */, 581943F028F8014500B0CB5E /* MullvadTypes */, 06799ABB28F98E1D00ACD94E /* MullvadREST */, + 58FBFBE5291622580020E046 /* MullvadRESTTests */, 063F02722902B63F001FA09F /* RelayCache */, 5898D29729017DAC00EB5EBA /* RelaySelector */, 5898D28829017BD300EB5EBA /* TunnelProviderMessaging */, @@ -1892,6 +1946,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 58FBFBE4291622580020E046 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -2290,6 +2351,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 58FBFBE2291622580020E046 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 58FBFBE9291622580020E046 /* ExponentialBackoffTests.swift in Sources */, + 58FBFBF1291630700020E046 /* DurationTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -2373,6 +2443,11 @@ target = 58FBDA9722A519BC00EB69A3 /* WireGuardGoBridge */; targetProxy = 58FBDAA122A52A6800EB69A3 /* PBXContainerItemProxy */; }; + 58FBFBEC291622580020E046 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 06799ABB28F98E1D00ACD94E /* MullvadREST */; + targetProxy = 58FBFBEB291622580020E046 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -3014,6 +3089,42 @@ }; name = Release; }; + 58FBFBED291622580020E046 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = CKG9MXH72F; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.mullvad.MullvadVPN.MullvadRESTTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 58FBFBEE291622580020E046 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = CKG9MXH72F; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = net.mullvad.MullvadVPN.MullvadRESTTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -3143,6 +3254,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 58FBFBEF291622580020E046 /* Build configuration list for PBXNativeTarget "MullvadRESTTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58FBFBED291622580020E046 /* Debug */, + 58FBFBEE291622580020E046 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ diff --git a/ios/MullvadVPN.xcodeproj/xcshareddata/xcschemes/MullvadVPN.xcscheme b/ios/MullvadVPN.xcodeproj/xcshareddata/xcschemes/MullvadVPN.xcscheme index 5f4b4b5a25..dc70ad4ec7 100644 --- a/ios/MullvadVPN.xcodeproj/xcshareddata/xcschemes/MullvadVPN.xcscheme +++ b/ios/MullvadVPN.xcodeproj/xcshareddata/xcschemes/MullvadVPN.xcscheme @@ -72,6 +72,16 @@ ReferencedContainer = "container:MullvadVPN.xcodeproj"> </BuildableReference> </TestableReference> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "58FBFBE5291622580020E046" + BuildableName = "MullvadRESTTests.xctest" + BlueprintName = "MullvadRESTTests" + ReferencedContainer = "container:MullvadVPN.xcodeproj"> + </BuildableReference> + </TestableReference> </Testables> </TestAction> <LaunchAction |
