12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ import Foundation
16
+
15
17
@testable import App
16
18
17
- import XCTest
19
+ import Testing
18
20
19
21
20
- class VersionImmutableReferenceDiffTests : XCTestCase {
21
- // Tests different version diffing scenarios for lower level
22
- // [Version.ImmutableReference] interface.
23
- // Scenarios:
24
- // 1) branch changes commit hash
25
- // 2) new tag is added
26
- // 3) tag is removed
27
- // 4) branch is removed
28
- // 5) tag is moved
22
+ // Tests different version diffing scenarios for lower level
23
+ // [Version.ImmutableReference] interface.
24
+ // Scenarios:
25
+ // 1) branch changes commit hash
26
+ // 2) new tag is added
27
+ // 3) tag is removed
28
+ // 4) branch is removed
29
+ // 5) tag is moved
30
+ @ Suite struct VersionDiffTests {
29
31
30
- func test_diff_1 ( ) throws {
32
+ @ Test func ImmutableReference_diff_1 ( ) throws {
31
33
// Branch changes commit hash
32
34
// setup
33
35
let saved : [ Version . ImmutableReference ] = [
@@ -42,15 +44,12 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
42
44
] )
43
45
44
46
// validate
45
- XCTAssertEqual ( res. toAdd,
46
- [ . init( reference: . branch( " main " ) , commit: " hash3 " ) ] )
47
- XCTAssertEqual ( res. toDelete,
48
- [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
49
- XCTAssertEqual ( res. toKeep,
50
- [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
47
+ #expect( res. toAdd == [ . init( reference: . branch( " main " ) , commit: " hash3 " ) ] )
48
+ #expect( res. toDelete == [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
49
+ #expect( res. toKeep == [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
51
50
}
52
51
53
- func test_diff_2 ( ) throws {
52
+ @ Test func ImmutableReference_diff_2 ( ) throws {
54
53
// New tag is incoming
55
54
// setup
56
55
let saved : [ Version . ImmutableReference ] = [
@@ -66,15 +65,13 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
66
65
] )
67
66
68
67
// validate
69
- XCTAssertEqual ( res. toAdd,
70
- [ . init( reference: . tag( 2 , 0 , 0 ) , commit: " hash4 " ) ] )
71
- XCTAssertEqual ( res. toDelete, [ ] )
72
- XCTAssertEqual ( res. toKeep,
73
- [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ,
68
+ #expect( res. toAdd == [ . init( reference: . tag( 2 , 0 , 0 ) , commit: " hash4 " ) ] )
69
+ #expect( res. toDelete == [ ] )
70
+ #expect( res. toKeep == [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ,
74
71
. init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
75
72
}
76
73
77
- func test_diff_3 ( ) throws {
74
+ @ Test func ImmutableReference_diff_3 ( ) throws {
78
75
// Tag was deleted upstream
79
76
// setup
80
77
let saved : [ Version . ImmutableReference ] = [
@@ -88,14 +85,12 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
88
85
] )
89
86
90
87
// validate
91
- XCTAssertEqual ( res. toAdd, [ ] )
92
- XCTAssertEqual ( res. toDelete,
93
- [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
94
- XCTAssertEqual ( res. toKeep,
95
- [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
88
+ #expect( res. toAdd == [ ] )
89
+ #expect( res. toDelete == [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
90
+ #expect( res. toKeep == [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
96
91
}
97
92
98
- func test_diff_4 ( ) throws {
93
+ @ Test func ImmutableReference_diff_4 ( ) throws {
99
94
// Branch was deleted upstream
100
95
// setup
101
96
let saved : [ Version . ImmutableReference ] = [
@@ -109,14 +104,12 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
109
104
] )
110
105
111
106
// validate
112
- XCTAssertEqual ( res. toAdd, [ ] )
113
- XCTAssertEqual ( res. toDelete,
114
- [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
115
- XCTAssertEqual ( res. toKeep,
116
- [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
107
+ #expect( res. toAdd == [ ] )
108
+ #expect( res. toDelete == [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
109
+ #expect( res. toKeep == [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
117
110
}
118
111
119
- func test_diff_5 ( ) throws {
112
+ @ Test func ImmutableReference_diff_5 ( ) throws {
120
113
// Tag was changed - retagging a release
121
114
// setup
122
115
let saved : [ Version . ImmutableReference ] = [
@@ -131,47 +124,40 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
131
124
] )
132
125
133
126
// validate
134
- XCTAssertEqual ( res. toAdd, [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash3 " ) ] )
135
- XCTAssertEqual ( res. toDelete, [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
136
- XCTAssertEqual ( res. toKeep,
137
- [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
127
+ #expect( res. toAdd == [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash3 " ) ] )
128
+ #expect( res. toDelete == [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
129
+ #expect( res. toKeep == [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
138
130
}
139
131
140
- }
141
-
142
-
143
- class VersionDiffTests : AppTestCase {
144
- // Test [Version] based diff (higher level interface)
145
- // Just run an integration scenario, the details are covered in the test above
146
-
147
- func test_diff_1( ) async throws {
148
- // Branch changes commit hash
149
- // setup
150
- let pkg = try await savePackage ( on: app. db, " 1 " )
151
- let keptId = UUID ( )
152
- let saved : [ Version ] = [
153
- try . init( package : pkg, commit: " hash1 " , reference: . branch( " main " ) ) ,
154
- try . init( id: keptId,
155
- package : pkg, commit: " hash2 " , reference: . tag( 1 , 2 , 3 ) ) ,
156
- ]
157
- try await saved. save ( on: app. db)
158
-
159
- // MUT
160
- let res = Version . diff ( local: saved, incoming: [
161
- try . init( package : pkg, commit: " hash3 " , reference: . branch( " main " ) ) ,
162
- try . init( package : pkg, commit: " hash2 " , reference: . tag( 1 , 2 , 3 ) ) ,
163
- try . init( package : pkg, commit: " hash4 " , reference: . tag( 2 , 0 , 0 ) ) ,
164
- ] )
165
-
166
- // validate
167
- XCTAssertEqual ( res. toAdd. map ( \. immutableReference) ,
168
- [ . init( reference: . branch( " main " ) , commit: " hash3 " ) ,
169
- . init( reference: . tag( 2 , 0 , 0 ) , commit: " hash4 " ) ] )
170
- XCTAssertEqual ( res. toDelete. map ( \. immutableReference) ,
171
- [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
172
- XCTAssertEqual ( res. toKeep. map ( \. immutableReference) ,
173
- [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
174
- XCTAssertEqual ( res. toKeep. map ( \. id) , [ keptId] )
132
+ @Test func Version_diff_1( ) async throws {
133
+ // Test [Version] based diff (higher level interface)
134
+ // Just run an integration scenario, the details are covered in the test above
135
+ try await withApp { app in
136
+ // Branch changes commit hash
137
+ // setup
138
+ let pkg = try await savePackage ( on: app. db, " 1 " )
139
+ let keptId = UUID ( )
140
+ let saved : [ Version ] = [
141
+ try . init( package : pkg, commit: " hash1 " , reference: . branch( " main " ) ) ,
142
+ try . init( id: keptId,
143
+ package : pkg, commit: " hash2 " , reference: . tag( 1 , 2 , 3 ) ) ,
144
+ ]
145
+ try await saved. save ( on: app. db)
146
+
147
+ // MUT
148
+ let res = Version . diff ( local: saved, incoming: [
149
+ try . init( package : pkg, commit: " hash3 " , reference: . branch( " main " ) ) ,
150
+ try . init( package : pkg, commit: " hash2 " , reference: . tag( 1 , 2 , 3 ) ) ,
151
+ try . init( package : pkg, commit: " hash4 " , reference: . tag( 2 , 0 , 0 ) ) ,
152
+ ] )
153
+
154
+ // validate
155
+ #expect( res. toAdd. map ( \. immutableReference) == [ . init( reference: . branch( " main " ) , commit: " hash3 " ) ,
156
+ . init( reference: . tag( 2 , 0 , 0 ) , commit: " hash4 " ) ] )
157
+ #expect( res. toDelete. map ( \. immutableReference) == [ . init( reference: . branch( " main " ) , commit: " hash1 " ) ] )
158
+ #expect( res. toKeep. map ( \. immutableReference) == [ . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
159
+ #expect( res. toKeep. map ( \. id) == [ keptId] )
160
+ }
175
161
}
176
162
177
163
}
0 commit comments