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
1719import Dependencies
1820import InlineSnapshotTesting
1921import NIOConcurrencyHelpers
20- import XCTVapor
22+ import Testing
23+ import Vapor
2124
2225
23- class SocialTests : AppTestCase {
26+ @ Suite struct SocialTests {
2427
25- func test_versionUpdateMessage ( ) throws {
26- XCTAssertEqual (
28+ @ Test func versionUpdateMessage ( ) throws {
29+ #expect (
2730 Social . versionUpdateMessage (
2831 packageName: " packageName " ,
2932 repositoryOwnerName: " owner " ,
3033 url: " http://localhost:8080/owner/SuperAwesomePackage " ,
3134 version: . init( 2 , 6 , 4 ) ,
3235 summary: " This is a test package " ,
33- maxLength: Social . postMaxLength) ,
34- """
36+ maxLength: Social . postMaxLength) == """
3537 ⬆️ owner just released packageName v2.6.4 – This is a test package
3638
3739 http://localhost:8080/owner/SuperAwesomePackage#releases
3840 """
3941 )
4042
4143 // no summary
42- XCTAssertEqual (
44+ #expect (
4345 Social . versionUpdateMessage (
4446 packageName: " packageName " ,
4547 repositoryOwnerName: " owner " ,
4648 url: " http://localhost:8080/owner/SuperAwesomePackage " ,
4749 version: . init( 2 , 6 , 4 ) ,
4850 summary: nil ,
49- maxLength: Social . postMaxLength) ,
50- """
51+ maxLength: Social . postMaxLength) == """
5152 ⬆️ owner just released packageName v2.6.4
5253
5354 http://localhost:8080/owner/SuperAwesomePackage#releases
5455 """
5556 )
5657
5758 // empty summary
58- XCTAssertEqual (
59+ #expect (
5960 Social . versionUpdateMessage (
6061 packageName: " packageName " ,
6162 repositoryOwnerName: " owner " ,
6263 url: " http://localhost:8080/owner/SuperAwesomePackage " ,
6364 version: . init( 2 , 6 , 4 ) ,
6465 summary: " " ,
65- maxLength: Social . postMaxLength) ,
66- """
66+ maxLength: Social . postMaxLength) == """
6767 ⬆️ owner just released packageName v2.6.4
6868
6969 http://localhost:8080/owner/SuperAwesomePackage#releases
7070 """
7171 )
7272
7373 // whitespace summary
74- XCTAssertEqual (
74+ #expect (
7575 Social . versionUpdateMessage (
7676 packageName: " packageName " ,
7777 repositoryOwnerName: " owner " ,
7878 url: " http://localhost:8080/owner/SuperAwesomePackage " ,
7979 version: . init( 2 , 6 , 4 ) ,
8080 summary: " \n " ,
81- maxLength: Social . postMaxLength) ,
82- """
81+ maxLength: Social . postMaxLength) == """
8382 ⬆️ owner just released packageName v2.6.4
8483
8584 http://localhost:8080/owner/SuperAwesomePackage#releases
8685 """
8786 )
8887 }
8988
90- func test_versionUpdateMessage_trimming ( ) throws {
89+ @ Test func versionUpdateMessage_trimming ( ) throws {
9190 let msg = Social . versionUpdateMessage (
9291 packageName: " packageName " ,
9392 repositoryOwnerName: " owner " ,
@@ -97,153 +96,160 @@ class SocialTests: AppTestCase {
9796 maxLength: Social . postMaxLength
9897 )
9998
100- XCTAssertEqual ( msg. count, 490 )
101- XCTAssertEqual ( msg, """
99+ #expect ( msg. count == 490 )
100+ #expect ( msg == """
102101 ⬆️ owner just released packageName v2.6.4 – xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx…
103102
104103 http://localhost:8080/owner/SuperAwesomePackage#releases
105104 """ )
106105 }
107106
108- func test_newPackageMessage ( ) throws {
109- XCTAssertEqual (
107+ @ Test func newPackageMessage ( ) throws {
108+ #expect (
110109 Social . newPackageMessage (
111110 packageName: " packageName " ,
112111 repositoryOwnerName: " owner " ,
113112 url: " http://localhost:8080/owner/SuperAwesomePackage " ,
114113 summary: " This is a test package " ,
115114 maxLength: Social . postMaxLength
116- ) ,
117- """
115+ ) == """
118116 📦 owner just added a new package, packageName – This is a test package
119117
120118 http://localhost:8080/owner/SuperAwesomePackage
121119 """
122120 )
123121 }
124122
125- func test_firehoseMessage_new_version( ) async throws {
126- // setup
127- let pkg = Package ( url: " 1 " . asGithubUrl. url, status: . ok)
128- try await pkg. save ( on: app. db)
129- try await Repository ( package : pkg,
130- name: " repoName " ,
131- owner: " owner " ,
132- summary: " This is a test package " ) . save ( on: app. db)
133- let version = try Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
134- try await version. save ( on: app. db)
135- let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
136-
137- // MUT
138- let res = Social . firehoseMessage ( package : jpr,
139- version: version,
140- maxLength: Social . postMaxLength)
141-
142- // validate
143- XCTAssertEqual ( res, """
144- ⬆️ owner just released MyPackage v1.2.3 – This is a test package
123+ @Test func firehoseMessage_new_version( ) async throws {
124+ try await withApp { app in
125+ // setup
126+ let pkg = Package ( url: " 1 " . asGithubUrl. url, status: . ok)
127+ try await pkg. save ( on: app. db)
128+ try await Repository ( package : pkg,
129+ name: " repoName " ,
130+ owner: " owner " ,
131+ summary: " This is a test package " ) . save ( on: app. db)
132+ let version = try Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
133+ try await version. save ( on: app. db)
134+ let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
135+
136+ // MUT
137+ let res = Social . firehoseMessage ( package : jpr,
138+ version: version,
139+ maxLength: Social . postMaxLength)
145140
141+ // validate
142+ #expect( res == """
143+ ⬆️ owner just released MyPackage v1.2.3 – This is a test package
144+
146145 http://localhost:8080/owner/repoName#releases
147146 """ )
147+ }
148148 }
149149
150- func test_firehoseMessage_new_package( ) async throws {
151- // setup
152- let pkg = Package ( url: " 1 " . asGithubUrl. url, status: . new)
153- try await pkg. save ( on: app. db)
154- try await Repository ( package : pkg,
155- name: " repoName " ,
156- owner: " owner " ,
157- summary: " This is a test package " ) . save ( on: app. db)
158- let version = try Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
159- try await version. save ( on: app. db)
160- let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
161-
162- // MUT
163- let res = Social . firehoseMessage ( package : jpr,
164- version: version,
165- maxLength: Social . postMaxLength)
166-
167- // validate
168- XCTAssertEqual ( res, """
169- 📦 owner just added a new package, MyPackage – This is a test package
150+ @Test func firehoseMessage_new_package( ) async throws {
151+ try await withApp { app in
152+ // setup
153+ let pkg = Package ( url: " 1 " . asGithubUrl. url, status: . new)
154+ try await pkg. save ( on: app. db)
155+ try await Repository ( package : pkg,
156+ name: " repoName " ,
157+ owner: " owner " ,
158+ summary: " This is a test package " ) . save ( on: app. db)
159+ let version = try Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
160+ try await version. save ( on: app. db)
161+ let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
162+
163+ // MUT
164+ let res = Social . firehoseMessage ( package : jpr,
165+ version: version,
166+ maxLength: Social . postMaxLength)
170167
168+ // validate
169+ #expect( res == """
170+ 📦 owner just added a new package, MyPackage – This is a test package
171+
171172 http://localhost:8080/owner/repoName
172173 """ )
174+ }
173175 }
174176
175- func test_postToFirehose_only_release_and_preRelease ( ) async throws {
177+ @ Test func postToFirehose_only_release_and_preRelease ( ) async throws {
176178 // ensure we only post about releases and pre-releases
177- // setup
178- let pkg = Package ( url: " 1 " . asGithubUrl. url)
179- try await pkg. save ( on: app. db)
180- try await Repository ( package : pkg,
181- name: " repoName " ,
182- owner: " repoOwner " ,
183- summary: " This is a test package " ) . save ( on: app. db)
184- try await Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
185- . save ( on: app. db)
186- try await Version ( package : pkg,
187- commitDate: Date ( timeIntervalSince1970: 0 ) ,
188- packageName: " MyPackage " ,
189- reference: . tag( 2 , 0 , 0 , " b1 " ) ) . save ( on: app. db)
190- try await Version ( package : pkg, packageName: " MyPackage " , reference: . branch( " main " ) )
191- . save ( on: app. db)
192- let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
193- let versions = try await Analyze . updateLatestVersions ( on: app. db, package : jpr)
194-
195- let posted : NIOLockedValueBox < Int > = . init( 0 )
179+ try await withApp { app in
180+ // setup
181+ let pkg = Package ( url: " 1 " . asGithubUrl. url)
182+ try await pkg. save ( on: app. db)
183+ try await Repository ( package : pkg,
184+ name: " repoName " ,
185+ owner: " repoOwner " ,
186+ summary: " This is a test package " ) . save ( on: app. db)
187+ try await Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
188+ . save ( on: app. db)
189+ try await Version ( package : pkg,
190+ commitDate: Date ( timeIntervalSince1970: 0 ) ,
191+ packageName: " MyPackage " ,
192+ reference: . tag( 2 , 0 , 0 , " b1 " ) ) . save ( on: app. db)
193+ try await Version ( package : pkg, packageName: " MyPackage " , reference: . branch( " main " ) )
194+ . save ( on: app. db)
195+ let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
196+ let versions = try await Analyze . updateLatestVersions ( on: app. db, package : jpr)
197+
198+ let posted : NIOLockedValueBox < Int > = . init( 0 )
199+
200+ try await withDependencies {
201+ $0. environment. allowSocialPosts = { true }
202+ $0. httpClient. mastodonPost = { @Sendable _ in posted. withLockedValue { $0 += 1 } }
203+ } operation: {
204+ // MUT
205+ try await Social . postToFirehose ( client: app. client,
206+ package : jpr,
207+ versions: versions)
208+ }
196209
197- try await withDependencies {
198- $0. environment. allowSocialPosts = { true }
199- $0. httpClient. mastodonPost = { @Sendable _ in posted. withLockedValue { $0 += 1 } }
200- } operation: {
201- // MUT
202- try await Social . postToFirehose ( client: app. client,
203- package : jpr,
204- versions: versions)
210+ // validate
211+ try await XCTAssertEqualAsync ( posted. withLockedValue { $0 } , 2 )
205212 }
206-
207- // validate
208- try await XCTAssertEqualAsync ( posted. withLockedValue { $0 } , 2 )
209213 }
210214
211- func test_postToFirehose_only_latest ( ) async throws {
215+ @ Test func postToFirehose_only_latest ( ) async throws {
212216 // ensure we only post about latest versions
213- // setup
214- let pkg = Package ( url: " 1 " . asGithubUrl. url, status: . ok)
215- try await pkg. save ( on: app. db)
216- try await Repository ( package : pkg,
217- name: " repoName " ,
218- owner: " repoOwner " ,
219- summary: " This is a test package " ) . save ( on: app. db)
220- try await Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
221- . save ( on: app. db)
222- try await Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 2 , 0 , 0 ) )
223- . save ( on: app. db)
224- let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
225- let versions = try await Analyze . updateLatestVersions ( on: app. db, package : jpr)
226-
227- let posted : NIOLockedValueBox < Int > = . init( 0 )
228-
229- try await withDependencies {
230- $0. environment. allowSocialPosts = { true }
231- $0. httpClient. mastodonPost = { @Sendable msg in
232- XCTAssertTrue ( msg. contains ( " v2.0.0 " ) )
233- posted. withLockedValue { $0 += 1 }
217+ try await withApp { app in
218+ // setup
219+ let pkg = Package ( url: " 1 " . asGithubUrl. url, status: . ok)
220+ try await pkg. save ( on: app. db)
221+ try await Repository ( package : pkg,
222+ name: " repoName " ,
223+ owner: " repoOwner " ,
224+ summary: " This is a test package " ) . save ( on: app. db)
225+ try await Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 1 , 2 , 3 ) )
226+ . save ( on: app. db)
227+ try await Version ( package : pkg, packageName: " MyPackage " , reference: . tag( 2 , 0 , 0 ) )
228+ . save ( on: app. db)
229+ let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
230+ let versions = try await Analyze . updateLatestVersions ( on: app. db, package : jpr)
231+
232+ let posted : NIOLockedValueBox < Int > = . init( 0 )
233+
234+ try await withDependencies {
235+ $0. environment. allowSocialPosts = { true }
236+ $0. httpClient. mastodonPost = { @Sendable msg in
237+ #expect( msg. contains ( " v2.0.0 " ) )
238+ posted. withLockedValue { $0 += 1 }
239+ }
240+ } operation: {
241+ // MUT
242+ try await Social . postToFirehose ( client: app. client,
243+ package : jpr,
244+ versions: versions)
234245 }
235- } operation: {
236- // MUT
237- try await Social . postToFirehose ( client: app. client,
238- package : jpr,
239- versions: versions)
240- }
241246
242- // validate
243- try await XCTAssertEqualAsync ( posted. withLockedValue { $0 } , 1 )
247+ // validate
248+ try await XCTAssertEqualAsync ( posted. withLockedValue { $0 } , 1 )
249+ }
244250 }
245251
246- func test_urlEncoding ( ) async throws {
252+ @ Test func urlEncoding ( ) async throws {
247253 let called = ActorIsolated ( false )
248254 try await withDependencies {
249255 $0. environment. mastodonCredentials = { . init( accessToken: " fakeToken " ) }
@@ -254,7 +260,7 @@ class SocialTests: AppTestCase {
254260 https://mas.to/api/v1/statuses?status=%E2%AC%86%EF%B8%8F%20owner%20just%20released%20packageName%20v2.6.4%0A%0Ahttp://localhost:8080/owner/SuperAwesomePackage%23releases&visibility=unlisted
255261 """
256262 }
257- XCTAssertEqual ( headers, HTTPHeaders ( [
263+ #expect ( headers == HTTPHeaders ( [
258264 ( " Authorization " , " Bearer fakeToken " ) ,
259265 ( " Idempotency-Key " , UUID . id0. uuidString) ,
260266 ] ) )
0 commit comments