From 044b6f281a426606aaefe7a73ad891b177af7c4f Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino Date: Tue, 17 Sep 2024 19:50:56 +0200 Subject: [PATCH] Swift 6 and Swift Testing --- Package.swift | 19 ++++----------- Sources/SendGridKit/SendGridClient.swift | 4 ++-- Tests/SendGridKitTests/SendGridTestsKit.swift | 24 +++++++------------ 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Package.swift b/Package.swift index 609aaff..c02ed21 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,10 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.0 import PackageDescription let package = Package( name: "sendgrid-kit", platforms: [ - .macOS(.v13), + .macOS(.v14), ], products: [ .library(name: "SendGridKit", targets: ["SendGridKit"]), @@ -17,24 +17,13 @@ let package = Package( name: "SendGridKit", dependencies: [ .product(name: "AsyncHTTPClient", package: "async-http-client"), - ], - swiftSettings: swiftSettings + ] ), .testTarget( name: "SendGridKitTests", dependencies: [ .target(name: "SendGridKit"), - ], - swiftSettings: swiftSettings + ] ), ] ) - -var swiftSettings: [SwiftSetting] { [ - .enableUpcomingFeature("ExistentialAny"), - .enableUpcomingFeature("ConciseMagicFile"), - .enableUpcomingFeature("ForwardTrailingClosures"), - .enableUpcomingFeature("DisableOutwardActorInference"), - .enableUpcomingFeature("StrictConcurrency"), - .enableExperimentalFeature("StrictConcurrency=complete"), -] } diff --git a/Sources/SendGridKit/SendGridClient.swift b/Sources/SendGridKit/SendGridClient.swift index 53b1e7a..ef8ac0c 100644 --- a/Sources/SendGridKit/SendGridClient.swift +++ b/Sources/SendGridKit/SendGridClient.swift @@ -1,4 +1,4 @@ -@preconcurrency import Foundation +import Foundation import NIO import AsyncHTTPClient import NIOHTTP1 @@ -41,7 +41,7 @@ public struct SendGridClient: Sendable { ).get() // If the request was accepted, simply return - guard response.status != .ok && response.status != .accepted else { return } + if response.status == .ok || response.status == .accepted { return } // JSONDecoder will handle empty body by throwing decoding error let byteBuffer = response.body ?? ByteBuffer(.init()) diff --git a/Tests/SendGridKitTests/SendGridTestsKit.swift b/Tests/SendGridKitTests/SendGridTestsKit.swift index 1f9c17f..d55cb92 100644 --- a/Tests/SendGridKitTests/SendGridTestsKit.swift +++ b/Tests/SendGridKitTests/SendGridTestsKit.swift @@ -1,22 +1,16 @@ -import XCTest +import Testing import AsyncHTTPClient @testable import SendGridKit -class SendGridKitTests: XCTestCase { - private var httpClient: HTTPClient! - private var client: SendGridClient! +struct SendGridKitTests { + var client: SendGridClient - override func setUp() { - httpClient = HTTPClient(eventLoopGroupProvider: .singleton) - // TODO: Replace with your API key to test! - client = SendGridClient(httpClient: httpClient, apiKey: "YOUR-API-KEY") - } - - override func tearDown() async throws { - try await httpClient.shutdown() + init() { + // TODO: Replace with a valid API key to test + client = SendGridClient(httpClient: HTTPClient.shared, apiKey: "YOUR-API-KEY") } - func testSendEmail() async throws { + @Test func sendEmail() async throws { // TODO: Replace to address with the email address you'd like to recieve your test email let emailAddress = EmailAddress("TO-ADDRESS") // TODO: Replace from address with the email address associated with your verified Sender Identity @@ -40,8 +34,8 @@ class SendGridKitTests: XCTestCase { attachments: [attachment] ) - do { + await withKnownIssue { try await client.send(email: email) - } catch {} + } } }