Skip to content

Commit 9b66909

Browse files
Joan Martinfranmontiel
Joan Martin
authored andcommitted
Adding Fastlane and some sample tests for Futures
1 parent 46f1eac commit 9b66909

File tree

8 files changed

+232
-30
lines changed

8 files changed

+232
-30
lines changed

Harmony.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
5932E95F27A9473400253261 /* MockInteractorPut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59E5192027A9462600A18D72 /* MockInteractorPut.swift */; };
1919
5962B12327A951D8008B0EFF /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59B7AA1E27A83AC1001F5D8F /* Security.framework */; };
2020
59881E7C27A9DC9500D92121 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59881E7B27A9DC9500D92121 /* TestUtils.swift */; };
21-
59A418C4284E224200E33F2D /* InMemoryDataSourcesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59A418C3284E224200E33F2D /* InMemoryDataSourcesTests.swift */; };
2221
59A418C6284E240300E33F2D /* Nimble.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59A418C5284E240300E33F2D /* Nimble.xcframework */; };
2322
59A418C7284E255200E33F2D /* HarmonyTesting.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59E5190927A9349000A18D72 /* HarmonyTesting.framework */; };
2423
59B7A81D27A827F7001F5D8F /* Harmony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59B7A81227A827F6001F5D8F /* Harmony.framework */; };
@@ -103,6 +102,7 @@
103102
59B7AA1B27A83966001F5D8F /* KeychainGetInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B7AA1627A83966001F5D8F /* KeychainGetInteractor.swift */; };
104103
59B7AA1C27A83966001F5D8F /* SecureKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B7AA1727A83966001F5D8F /* SecureKey.swift */; };
105104
59E5191427A934B400A18D72 /* Harmony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59B7A81227A827F6001F5D8F /* Harmony.framework */; };
105+
D28C13F3285B090500E4F2CA /* FutureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28C13F2285B090500E4F2CA /* FutureTests.swift */; };
106106
D2D2163627AC280A00A104B8 /* LinkRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B7A85927A82971001F5D8F /* LinkRecognizer.swift */; };
107107
D2D2163727AC280A00A104B8 /* Future+Time.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B7A86B27A82971001F5D8F /* Future+Time.swift */; };
108108
D2D2163827AC280A00A104B8 /* DataSourceMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B7A84D27A82971001F5D8F /* DataSourceMapper.swift */; };
@@ -217,7 +217,6 @@
217217
/* Begin PBXFileReference section */
218218
59881E7A27A9D6D700D92121 /* HarmonyTesting.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = HarmonyTesting.podspec; sourceTree = "<group>"; };
219219
59881E7B27A9DC9500D92121 /* TestUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
220-
59A418C3284E224200E33F2D /* InMemoryDataSourcesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InMemoryDataSourcesTests.swift; sourceTree = "<group>"; };
221220
59A418C5284E240300E33F2D /* Nimble.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Nimble.xcframework; path = Carthage/Build/Nimble.xcframework; sourceTree = "<group>"; };
222221
59B7A81227A827F6001F5D8F /* Harmony.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Harmony.framework; sourceTree = BUILT_PRODUCTS_DIR; };
223222
59B7A81C27A827F7001F5D8F /* HarmonyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HarmonyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -599,6 +598,7 @@
599598
59E5192127A9462600A18D72 /* MockInteractorDelete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockInteractorDelete.swift; sourceTree = "<group>"; };
600599
59E5192227A9462F00A18D72 /* StringObjectMother.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringObjectMother.swift; sourceTree = "<group>"; };
601600
59E5192327A9463D00A18D72 /* UUIDObjectMother.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UUIDObjectMother.swift; sourceTree = "<group>"; };
601+
D28C13F2285B090500E4F2CA /* FutureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FutureTests.swift; sourceTree = "<group>"; };
602602
D2D2168E27AC280A00A104B8 /* Harmony.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Harmony.framework; sourceTree = BUILT_PRODUCTS_DIR; };
603603
D2D216A227AC291200A104B8 /* HarmonyTesting.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HarmonyTesting.framework; sourceTree = BUILT_PRODUCTS_DIR; };
604604
/* End PBXFileReference section */
@@ -764,7 +764,7 @@
764764
59B7A8CD27A8297A001F5D8F /* HarmonyTests */ = {
765765
isa = PBXGroup;
766766
children = (
767-
59A418C3284E224200E33F2D /* InMemoryDataSourcesTests.swift */,
767+
D28C13F2285B090500E4F2CA /* FutureTests.swift */,
768768
);
769769
path = HarmonyTests;
770770
sourceTree = "<group>";
@@ -1761,7 +1761,7 @@
17611761
isa = PBXSourcesBuildPhase;
17621762
buildActionMask = 2147483647;
17631763
files = (
1764-
59A418C4284E224200E33F2D /* InMemoryDataSourcesTests.swift in Sources */,
1764+
D28C13F3285B090500E4F2CA /* FutureTests.swift in Sources */,
17651765
);
17661766
runOnlyForDeploymentPostprocessing = 0;
17671767
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
6+
<true/>
7+
</dict>
8+
</plist>

Harmony.xcodeproj/xcshareddata/xcschemes/Harmony-iOS.xcscheme

-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31-
<TestableReference
32-
skipped = "NO">
33-
<BuildableReference
34-
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "59B7A81B27A827F7001F5D8F"
36-
BuildableName = "HarmonyTests.xctest"
37-
BlueprintName = "HarmonyTests"
38-
ReferencedContainer = "container:Harmony.xcodeproj">
39-
</BuildableReference>
40-
</TestableReference>
4131
</Testables>
4232
</TestAction>
4333
<LaunchAction

Harmony.xcodeproj/xcshareddata/xcschemes/HarmonyTesting-iOS.xcscheme

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "59B7A81B27A827F7001F5D8F"
36+
BuildableName = "HarmonyTests.xctest"
37+
BlueprintName = "HarmonyTests"
38+
ReferencedContainer = "container:Harmony.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
3141
</Testables>
3242
</TestAction>
3343
<LaunchAction

Tests/HarmonyTests/FutureTests.swift

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//
2+
// FutureTests.swift
3+
// HarmonyTests
4+
//
5+
// Created by Joan Martin on 16/6/22.
6+
//
7+
8+
import XCTest
9+
import Harmony
10+
import HarmonyTesting
11+
import Nimble
12+
13+
class FutureTests: XCTestCase {
14+
15+
override func setUpWithError() throws {
16+
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
}
18+
19+
override func tearDownWithError() throws {
20+
// Put teardown code here. This method is called after the invocation of each test method in the class.
21+
}
22+
23+
// Success Errors
24+
func test_future_value_set_on_init() throws {
25+
// Given
26+
let anyValue = Int.random(in: Int.min...Int.max)
27+
28+
// When
29+
let future = Future(anyValue)
30+
31+
// Then
32+
expect(try future.result.get()) == anyValue
33+
}
34+
35+
func test_future_value_set_on_set_value() throws {
36+
// Given
37+
let anyValue = Int.random(in: Int.min...Int.max)
38+
let future = Future<Int>()
39+
40+
// When
41+
future.set(anyValue)
42+
43+
// Then
44+
expect(try future.result.get()) == anyValue
45+
}
46+
47+
func test_future_value_set_on_set_value_or_error() throws {
48+
// Given
49+
let anyValue = Int.random(in: Int.min...Int.max)
50+
let future = Future<Int>()
51+
52+
// When
53+
future.set(value: anyValue, error: nil)
54+
55+
// Then
56+
expect(try future.result.get()) == anyValue
57+
}
58+
59+
func test_future_error_set_on_init() throws {
60+
// Given
61+
let anyError = CoreError.Unknown()
62+
63+
// When
64+
let future = Future<Int>(anyError)
65+
66+
// Then
67+
expect(try future.result.get()).to(throwError(anyError))
68+
}
69+
70+
func test_future_error_set_on_set_value() throws {
71+
// Given
72+
let anyError = CoreError.Unknown()
73+
let future = Future<Int>()
74+
75+
// When
76+
future.set(anyError)
77+
78+
// Then
79+
expect(try future.result.get()).to(throwError(anyError))
80+
}
81+
82+
func test_future_error_set_on_set_value_or_error() throws {
83+
// Given
84+
let anyError = CoreError.Unknown()
85+
86+
// When
87+
let future = Future<Int>()
88+
future.set(value: nil, error: anyError)
89+
90+
// Then
91+
expect(try future.result.get()).to(throwError(anyError))
92+
}
93+
94+
func test_future_states_on_value_first_then_after() throws {
95+
// Given
96+
let anyValue = Int.random(in: Int.min...Int.max)
97+
let future = Future<Int>()
98+
99+
// When
100+
expect(future.state) == Future.State.blank
101+
future.set(value: anyValue, error: nil)
102+
expect(future.state) == Future.State.waitingThen
103+
104+
// Then
105+
let expectation = expectation(description: "")
106+
future.then { val in
107+
expect(val) == anyValue
108+
expectation.fulfill()
109+
}
110+
waitForExpectations(timeout: 1, handler: nil)
111+
expect(future.state) == Future.State.sent
112+
}
113+
114+
func test_future_states_on_then_first_value_after() throws {
115+
// Given
116+
let anyValue = Int.random(in: Int.min...Int.max)
117+
let future = Future<Int>()
118+
119+
// When
120+
expect(future.state) == Future.State.blank
121+
future.set(value: anyValue, error: nil)
122+
expect(future.state) == Future.State.waitingThen
123+
124+
// Then
125+
let expectation = expectation(description: "")
126+
future.then { val in
127+
expect(val) == anyValue
128+
expectation.fulfill()
129+
}
130+
waitForExpectations(timeout: 1, handler: nil)
131+
expect(future.state) == Future.State.sent
132+
}
133+
134+
func test_future_states_result_first_value_after() throws {
135+
// Given
136+
let anyValue = Int.random(in: Int.min...Int.max)
137+
let queue = DispatchQueue(label: "")
138+
let future = Future<Int>()
139+
let expectation = expectation(description: "")
140+
141+
// When
142+
expect(future.state) == Future.State.blank
143+
queue.async {
144+
expect(future.state) == Future.State.blank
145+
expect(try? future.result.get()) == anyValue
146+
expect(future.state) == Future.State.sent
147+
expectation.fulfill()
148+
}
149+
150+
// Then
151+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
152+
// TODO: This next line fails the test. Not sure if it should.
153+
// expect(future.state) == Future.State.waitingContent
154+
future.set(anyValue)
155+
}
156+
waitForExpectations(timeout: 10, handler: nil)
157+
}
158+
159+
func test_future_states_value_first_result_after() throws {
160+
// Given
161+
let anyValue = Int.random(in: Int.min...Int.max)
162+
let future = Future<Int>()
163+
164+
// When
165+
expect(future.state) == Future.State.blank
166+
future.set(anyValue)
167+
168+
// Then
169+
expect(future.state) == Future.State.waitingThen
170+
expect(try? future.result.get()) == anyValue
171+
expect(future.state) == Future.State.sent
172+
}
173+
}

Tests/HarmonyTests/InMemoryDataSourcesTests.swift

-16
This file was deleted.

fastlane/Fastfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
lane :tests do
2+
run_tests(
3+
project: "Harmony.xcodeproj",
4+
devices: ["iPhone 13"],
5+
scheme: "HarmonyTesting-iOS"
6+
)
7+
end

fastlane/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
fastlane documentation
2+
----
3+
4+
# Installation
5+
6+
Make sure you have the latest version of the Xcode command line tools installed:
7+
8+
```sh
9+
xcode-select --install
10+
```
11+
12+
For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane)
13+
14+
# Available Actions
15+
16+
### tests
17+
18+
```sh
19+
[bundle exec] fastlane tests
20+
```
21+
22+
23+
24+
----
25+
26+
This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.
27+
28+
More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools).
29+
30+
The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools).

0 commit comments

Comments
 (0)