Skip to content

Commit

Permalink
Swift 6 and Swift Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Sep 17, 2024
1 parent c7dda56 commit 044b6f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
19 changes: 4 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"]),
Expand All @@ -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"),
] }
4 changes: 2 additions & 2 deletions Sources/SendGridKit/SendGridClient.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@preconcurrency import Foundation
import Foundation
import NIO
import AsyncHTTPClient
import NIOHTTP1
Expand Down Expand Up @@ -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())
Expand Down
24 changes: 9 additions & 15 deletions Tests/SendGridKitTests/SendGridTestsKit.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -40,8 +34,8 @@ class SendGridKitTests: XCTestCase {
attachments: [attachment]
)

do {
await withKnownIssue {
try await client.send(email: email)
} catch {}
}
}
}

0 comments on commit 044b6f2

Please sign in to comment.