-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for non-sendable responses (#6)
* support for non-sendable responses * adjusted github CI
- Loading branch information
Showing
7 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: API breaking changes | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
linux: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
container: | ||
image: swift:latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
# https://github.com/actions/checkout/issues/766 | ||
- name: Mark the workspace as safe | ||
run: git config --global --add safe.directory ${GITHUB_WORKSPACE} | ||
- name: API breaking changes | ||
run: | | ||
swift package diagnose-api-breaking-changes origin/${GITHUB_BASE_REF} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Tests/VaporElementaryTests/NonSendableHTMLResponseTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Elementary | ||
import Vapor | ||
import VaporElementary | ||
import XCTest | ||
import XCTVapor | ||
|
||
final class NonSendableHTMLResponseTests: XCTestCase { | ||
var app: Application! | ||
|
||
override func setUp() async throws { | ||
self.app = try await Application.make(.testing) | ||
} | ||
|
||
override func tearDown() async throws { | ||
try await self.app.asyncShutdown() | ||
} | ||
|
||
func testAllowsSendableValuesToBeWrittenTwice() async throws { | ||
self.app.get { req in | ||
let html = HTMLResponse { "Hello" } | ||
_ = try await html.encodeResponse(for: req).body.collect(on: req.eventLoop) | ||
return html | ||
} | ||
|
||
let response = try await app.sendRequest(.GET, "/") | ||
XCTAssertEqual(response.status, .ok) | ||
XCTAssertEqual(String(buffer: response.body), #"Hello"#) | ||
} | ||
|
||
#if compiler(>=6.0) | ||
func testRespondsWithANonSendable() async throws { | ||
guard #available(macOS 15.0, *) else { | ||
throw XCTSkip("Test requires macOS 15.0") | ||
} | ||
self.app.get { _ in HTMLResponse { div { NonSendableHTML() } } } | ||
|
||
let response = try await app.sendRequest(.GET, "/") | ||
XCTAssertEqual(response.status, .ok) | ||
XCTAssertEqual(String(buffer: response.body), #"<div>Hello</div>"#) | ||
} | ||
#endif | ||
} | ||
|
||
@available(*, unavailable) | ||
extension NonSendableHTML: Sendable {} | ||
|
||
struct NonSendableHTML: HTML { | ||
var content: some HTML { | ||
"Hello" | ||
} | ||
} |