@@ -22,22 +22,21 @@ import XCTVapor
2222final class MastodonTests : AppTestCase {
2323
2424 func test_endToEnd( ) async throws {
25+ let message = QueueIsolated < String ? > ( nil )
2526 try await withDependencies {
2627 $0. environment. allowSocialPosts = { true }
27- } operation: {
28- // setup
29- let message = QueueIsolated < String ? > ( nil )
30- Current . mastodonPost = { _, msg in
28+ $0. environment. mastodonPost = { @Sendable _, msg in
3129 if message. value == nil {
3230 message. setValue ( msg)
3331 } else {
3432 XCTFail ( " message must only be set once " )
3533 }
3634 }
37-
35+ } operation: {
36+ // setup
3837 let url = " https://github.com/foo/bar "
3938 Current . fetchMetadata = { _, owner, repository in . mock( owner: owner, repository: repository) }
40-
39+
4140 Current . git. commitCount = { @Sendable _ in 12 }
4241 Current . git. firstCommitDate = { @Sendable _ in . t0 }
4342 Current . git. lastCommitDate = { @Sendable _ in . t2 }
@@ -50,14 +49,14 @@ final class MastodonTests: AppTestCase {
5049 2 \t Person 2
5150 """
5251 }
53-
52+
5453 Current . shell. run = { @Sendable cmd, path in
5554 if cmd. description. hasSuffix ( " swift package dump-package " ) {
5655 return #"{ "name": "Mock", "products": [], "targets": [] }"#
5756 }
5857 return " "
5958 }
60-
59+
6160 try await withDependencies {
6261 $0. date. now = . now
6362 $0. packageListRepository. fetchPackageList = { @Sendable _ in [ url. url] }
@@ -68,39 +67,39 @@ final class MastodonTests: AppTestCase {
6867 // run first two processing steps
6968 try await reconcile ( client: app. client, database: app. db)
7069 try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
71-
70+
7271 // MUT - analyze, triggering the post
7372 try await Analyze . analyze ( client: app. client,
7473 database: app. db,
7574 mode: . limit( 10 ) )
76-
75+
7776 do {
7877 let msg = try XCTUnwrap ( message. value)
7978 XCTAssertTrue ( msg. hasPrefix ( " 📦 foo just added a new package, Mock " ) , " was \( msg) " )
8079 }
81-
80+
8281 // run stages again to simulate the cycle...
8382 message. setValue ( nil )
8483 try await reconcile ( client: app. client, database: app. db)
8584 }
86-
85+
8786 try await withDependencies {
8887 $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime)
8988 } operation: {
9089 try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
91-
90+
9291 // MUT - analyze, triggering posts if any
9392 try await Analyze . analyze ( client: app. client,
9493 database: app. db,
9594 mode: . limit( 10 ) )
9695 }
97-
96+
9897 // validate - there are no new posts to send
9998 XCTAssertNil ( message. value)
100-
99+
101100 // Now simulate receiving a package update: version 2.0.0
102101 Current . git. getTags = { @Sendable _ in [ . tag( 2 , 0 , 0 ) ] }
103-
102+
104103 try await withDependencies {
105104 // fast forward our clock by the deadtime interval again (*2) and re-ingest
106105 $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime * 2 )
@@ -111,7 +110,7 @@ final class MastodonTests: AppTestCase {
111110 database: app. db,
112111 mode: . limit( 10 ) )
113112 }
114-
113+
115114 // validate
116115 let msg = try XCTUnwrap ( message. value)
117116 XCTAssertTrue ( msg. hasPrefix ( " ⬆️ foo just released Mock v2.0.0 " ) , " was: \( msg) " )
0 commit comments