1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ import Foundation
16+
1517@testable import App
1618
17- import XCTest
19+ import Testing
1820
1921
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 {
2931
30- func test_diff_1 ( ) throws {
32+ @ Test func ImmutableReference_diff_1 ( ) throws {
3133 // Branch changes commit hash
3234 // setup
3335 let saved : [ Version . ImmutableReference ] = [
@@ -42,15 +44,12 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
4244 ] )
4345
4446 // 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 " ) ] )
5150 }
5251
53- func test_diff_2 ( ) throws {
52+ @ Test func ImmutableReference_diff_2 ( ) throws {
5453 // New tag is incoming
5554 // setup
5655 let saved : [ Version . ImmutableReference ] = [
@@ -66,15 +65,13 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
6665 ] )
6766
6867 // 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 " ) ,
7471 . init( reference: . tag( 1 , 2 , 3 ) , commit: " hash2 " ) ] )
7572 }
7673
77- func test_diff_3 ( ) throws {
74+ @ Test func ImmutableReference_diff_3 ( ) throws {
7875 // Tag was deleted upstream
7976 // setup
8077 let saved : [ Version . ImmutableReference ] = [
@@ -88,14 +85,12 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
8885 ] )
8986
9087 // 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 " ) ] )
9691 }
9792
98- func test_diff_4 ( ) throws {
93+ @ Test func ImmutableReference_diff_4 ( ) throws {
9994 // Branch was deleted upstream
10095 // setup
10196 let saved : [ Version . ImmutableReference ] = [
@@ -109,14 +104,12 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
109104 ] )
110105
111106 // 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 " ) ] )
117110 }
118111
119- func test_diff_5 ( ) throws {
112+ @ Test func ImmutableReference_diff_5 ( ) throws {
120113 // Tag was changed - retagging a release
121114 // setup
122115 let saved : [ Version . ImmutableReference ] = [
@@ -131,47 +124,40 @@ class VersionImmutableReferenceDiffTests: XCTestCase {
131124 ] )
132125
133126 // 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 " ) ] )
138130 }
139131
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+ }
175161 }
176162
177163}
0 commit comments