Skip to content

Commit 488704c

Browse files
committed
Convert MastodonTests
1 parent b3bbeb0 commit 488704c

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed

Tests/AppTests/MastodonTests.swift

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
import Dependencies
1818
import SemanticVersion
19-
import XCTVapor
19+
import Testing
2020

2121

22-
final class MastodonTests: AppTestCase {
22+
@Suite struct MastodonTests {
2323

24-
func test_apiURL() throws {
24+
@Test func apiURL() throws {
2525
let url = try Mastodon.apiURL(with: "message")
26-
XCTAssert(url.contains("visibility=unlisted"), "was: \(url)")
26+
#expect(url.contains("visibility=unlisted"), "was: \(url)")
2727
}
2828

29-
func test_endToEnd() async throws {
29+
@Test func endToEnd() async throws {
3030
let message = QueueIsolated<String?>(nil)
3131
try await withDependencies {
3232
$0.environment.allowSocialPosts = { true }
@@ -52,7 +52,7 @@ final class MastodonTests: AppTestCase {
5252
if message.value == nil {
5353
message.setValue(msg)
5454
} else {
55-
XCTFail("message must only be set once")
55+
Issue.record("message must only be set once")
5656
}
5757
}
5858
$0.shell.run = { @Sendable cmd, path in
@@ -62,67 +62,69 @@ final class MastodonTests: AppTestCase {
6262
return ""
6363
}
6464
} operation: {
65-
// setup
66-
let url = "https://github.com/foo/bar"
67-
68-
try await withDependencies {
69-
$0.date.now = .now
70-
$0.packageListRepository.fetchPackageList = { @Sendable _ in [url.url] }
71-
$0.packageListRepository.fetchPackageDenyList = { @Sendable _ in [] }
72-
$0.packageListRepository.fetchCustomCollections = { @Sendable _ in [] }
73-
$0.packageListRepository.fetchCustomCollection = { @Sendable _, _ in [] }
74-
} operation: {
75-
// run first two processing steps
76-
try await reconcile(client: app.client, database: app.db)
77-
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
78-
79-
// MUT - analyze, triggering the post
80-
try await Analyze.analyze(client: app.client,
81-
database: app.db,
82-
mode: .limit(10))
83-
84-
do {
85-
let msg = try XCTUnwrap(message.value)
86-
XCTAssertTrue(msg.hasPrefix("📦 foo just added a new package, Mock"), "was \(msg)")
87-
}
65+
try await withApp { app in
66+
// setup
67+
let url = "https://github.com/foo/bar"
8868

89-
// run stages again to simulate the cycle...
90-
message.setValue(nil)
91-
try await reconcile(client: app.client, database: app.db)
92-
}
69+
try await withDependencies {
70+
$0.date.now = .now
71+
$0.packageListRepository.fetchPackageList = { @Sendable _ in [url.url] }
72+
$0.packageListRepository.fetchPackageDenyList = { @Sendable _ in [] }
73+
$0.packageListRepository.fetchCustomCollections = { @Sendable _ in [] }
74+
$0.packageListRepository.fetchCustomCollection = { @Sendable _, _ in [] }
75+
} operation: {
76+
// run first two processing steps
77+
try await reconcile(client: app.client, database: app.db)
78+
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
9379

94-
try await withDependencies {
95-
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime)
96-
} operation: {
97-
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
80+
// MUT - analyze, triggering the post
81+
try await Analyze.analyze(client: app.client,
82+
database: app.db,
83+
mode: .limit(10))
9884

99-
// MUT - analyze, triggering posts if any
100-
try await Analyze.analyze(client: app.client,
101-
database: app.db,
102-
mode: .limit(10))
103-
}
85+
do {
86+
let msg = try #require(message.value)
87+
#expect(msg.hasPrefix("📦 foo just added a new package, Mock"), "was \(msg)")
88+
}
10489

105-
// validate - there are no new posts to send
106-
XCTAssertNil(message.value)
90+
// run stages again to simulate the cycle...
91+
message.setValue(nil)
92+
try await reconcile(client: app.client, database: app.db)
93+
}
10794

108-
// Now simulate receiving a package update: version 2.0.0
109-
try await withDependencies {
110-
$0.git.getTags = { @Sendable _ in [.tag(2, 0, 0)] }
111-
} operation: {
11295
try await withDependencies {
113-
// fast forward our clock by the deadtime interval again (*2) and re-ingest
114-
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime * 2)
96+
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime)
11597
} operation: {
11698
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
117-
// MUT - analyze again
99+
100+
// MUT - analyze, triggering posts if any
118101
try await Analyze.analyze(client: app.client,
119102
database: app.db,
120103
mode: .limit(10))
121104
}
122105

123-
// validate
124-
let msg = try XCTUnwrap(message.value)
125-
XCTAssertTrue(msg.hasPrefix("⬆️ foo just released Mock v2.0.0"), "was: \(msg)")
106+
// validate - there are no new posts to send
107+
#expect(message.value == nil)
108+
109+
// Now simulate receiving a package update: version 2.0.0
110+
try await withDependencies {
111+
$0.git.getTags = { @Sendable _ in [.tag(2, 0, 0)] }
112+
} operation: {
113+
try await withDependencies {
114+
// fast forward our clock by the deadtime interval again (*2) and re-ingest
115+
$0.date.now = .now.addingTimeInterval(Constants.reIngestionDeadtime * 2)
116+
} operation: {
117+
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
118+
// MUT - analyze again
119+
try await Analyze.analyze(client: app.client,
120+
database: app.db,
121+
mode: .limit(10))
122+
}
123+
124+
// validate
125+
let msg = try #require(message.value)
126+
#expect(msg.hasPrefix("⬆️ foo just released Mock v2.0.0"), "was: \(msg)")
127+
}
126128
}
127129
}
128130
}

0 commit comments

Comments
 (0)