Skip to content

Commit ffd8eac

Browse files
Merge pull request #1 from swift-serverless/feature/swift-6
Feature/swift 6
2 parents 272786a + 10624ef commit ffd8eac

File tree

9 files changed

+252
-224
lines changed

9 files changed

+252
-224
lines changed

.github/workflows/swift-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414
jobs:
1515
swift-tests:
1616
name: 'Swift Tests'
17-
runs-on: macos-13
17+
runs-on: macos-15
1818
defaults:
1919
run:
2020
shell: bash

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// swift-tools-version: 5.7
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "BreezeLambdaAPIClient",
88
platforms: [
9-
.macOS(.v13),
9+
.macOS(.v15),
1010
.iOS(.v15)
1111
],
1212
products: [

Sources/BreezeLambdaAPIClient/APIClientEnv.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,30 @@
1414

1515
import Foundation
1616

17-
public struct APIClientEnv {
17+
public struct APIClientEnv: Sendable {
1818

1919
public let session: URLSession
2020

2121
public let baseURL: URL
2222

23-
public var cachePolicy: NSURLRequest.CachePolicy = .useProtocolCachePolicy
24-
public var logger: APIClientLogging?
25-
public var decoder: JSONDecoder = JSONDecoder()
26-
public var encoder: JSONEncoder = JSONEncoder()
23+
public let cachePolicy: NSURLRequest.CachePolicy
24+
public let logger: APIClientLogging?
25+
public let decoder: JSONDecoder
26+
public let encoder: JSONEncoder
2727

28-
public init(session: URLSession, baseURL: String) throws {
28+
public init(
29+
session: URLSession,
30+
baseURL: String,
31+
cachePolicy: NSURLRequest.CachePolicy = .useProtocolCachePolicy,
32+
logger: APIClientLogging? = nil,
33+
decoder: JSONDecoder = JSONDecoder(),
34+
encoder: JSONEncoder = JSONEncoder()
35+
) throws {
2936
self.session = session
37+
self.logger = logger
38+
self.decoder = decoder
39+
self.encoder = encoder
40+
self.cachePolicy = cachePolicy
3041
guard let url = URL(string: baseURL) else {
3142
throw APIClientError.invalidURL
3243
}

Sources/BreezeLambdaAPIClient/APIClientLogging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import Foundation
1616

17-
public protocol APIClientLogging {
17+
public protocol APIClientLogging: Sendable {
1818
func log(request: URLRequest)
1919
func log(data: Data, for response: URLResponse)
2020
}

Sources/BreezeLambdaAPIClient/BreezeLambdaAPIClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private struct Items<Item: KeyedCodable>: Codable {
2222
let items: [Item]
2323
}
2424

25-
public struct BreezeLambdaAPIClient<Item: KeyedCodable> {
25+
public struct BreezeLambdaAPIClient<Item: KeyedCodable>: Sendable {
2626

2727
let env: APIClientEnv
2828
let path: String

Tests/BreezeLambdaAPIClientTests/APIEndpointTests.swift

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,52 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
15+
import Testing
16+
import Foundation
1617
@testable import BreezeLambdaAPIClient
1718

18-
final class APIEndpointTests: XCTestCase {
19+
@Suite
20+
struct APIEndpointTests {
1921

20-
var environment: APIClientEnv!
21-
var sut: APIEndpoint!
22+
let environment: APIClientEnv
2223
let baseURL: String = "https://apitest123.execute-api.us-east-1.amazonaws.com"
2324

24-
override func setUpWithError() throws {
25+
init() throws {
2526
let session = URLSession(configuration: .ephemeral)
2627
environment = try APIClientEnv(session: session, baseURL: baseURL)
2728
}
2829

29-
override func tearDownWithError() throws {
30-
environment = nil
30+
@Test
31+
func initSetPath() throws {
32+
let sut = APIEndpoint(env: environment, path: "path", queryItems: [URLQueryItem(name: "name", value: "value")])
33+
#expect(sut.path == "path")
3134
}
3235

33-
func testInit() throws {
34-
sut = APIEndpoint(env: environment, path: "path", queryItems: [URLQueryItem(name: "name", value: "value")])
35-
XCTAssertEqual(sut.path, "path")
36-
}
37-
38-
func testUrl_whenNoPathAndNoQueryItemes() throws {
39-
sut = APIEndpoint(env: environment, path: "", queryItems: nil)
36+
@Test
37+
func url_whenNoPathAndNoQueryItemes() throws {
38+
let sut = APIEndpoint(env: environment, path: "", queryItems: nil)
4039
let url = try sut.url()
41-
XCTAssertEqual(url.absoluteString, "https://apitest123.execute-api.us-east-1.amazonaws.com")
40+
#expect(url.absoluteString == "https://apitest123.execute-api.us-east-1.amazonaws.com")
4241
}
4342

44-
func testUrl_whenNoQueryItemes() throws {
45-
sut = APIEndpoint(env: environment, path: "path", queryItems: nil)
43+
@Test
44+
func url_whenNoQueryItemes() throws {
45+
let sut = APIEndpoint(env: environment, path: "path", queryItems: nil)
4646
let url = try sut.url()
47-
XCTAssertEqual(url.absoluteString, "https://apitest123.execute-api.us-east-1.amazonaws.com/path")
47+
#expect(url.absoluteString == "https://apitest123.execute-api.us-east-1.amazonaws.com/path")
4848
}
4949

50-
func testUrl_whenNoPathAndQueryItemes() throws {
51-
sut = APIEndpoint(env: environment, path: "", queryItems: [URLQueryItem(name: "name", value: "value")])
50+
@Test
51+
func url_whenNoPathAndQueryItemes() throws {
52+
let sut = APIEndpoint(env: environment, path: "", queryItems: [URLQueryItem(name: "name", value: "value")])
5253
let url = try sut.url()
53-
XCTAssertEqual(url.absoluteString, "https://apitest123.execute-api.us-east-1.amazonaws.com?name=value")
54+
#expect(url.absoluteString == "https://apitest123.execute-api.us-east-1.amazonaws.com?name=value")
5455
}
5556

56-
func testUrl_whenQueryItemes() throws {
57-
sut = APIEndpoint(env: environment, path: "path", queryItems: [URLQueryItem(name: "name", value: "value")])
57+
@Test
58+
func url_whenQueryItemes() throws {
59+
let sut = APIEndpoint(env: environment, path: "path", queryItems: [URLQueryItem(name: "name", value: "value")])
5860
let url = try sut.url()
59-
XCTAssertEqual(url.absoluteString, "https://apitest123.execute-api.us-east-1.amazonaws.com/path?name=value")
61+
#expect(url.absoluteString == "https://apitest123.execute-api.us-east-1.amazonaws.com/path?name=value")
6062
}
6163
}

0 commit comments

Comments
 (0)