From e72fd895e86ba2736145a74d17b5eedca6532d6a Mon Sep 17 00:00:00 2001 From: Leo Dion Date: Tue, 30 Jul 2024 20:36:55 -0400 Subject: [PATCH] fixing tests for now --- Packages/Ngrokit/Package.swift | 3 +- .../NgrokitMocks/MockNgrokCLIAPI.swift | 6 +- .../NgrokitMocks/MockNgrokProcess.swift | 12 ++-- .../Sources/NgrokitMocks/MockProcess.swift | 2 +- Packages/SublimationNgrok/Package.swift | 6 +- .../MockServerApplication.swift | 25 +++++---- .../MockServerDelegate.swift | 14 ++--- .../MockTunnelClient.swift | 0 .../NgrokCLIAPIConfigurationTests.swift | 1 + .../NgrokCLIAPIServerFactoryTests.swift | 8 ++- .../NetworkResultTests.swift | 56 +++++++++---------- .../SublimationVapor/Sublimation.swift | 2 +- 12 files changed, 71 insertions(+), 64 deletions(-) rename Packages/{SublimationVapor/Tests/SublimationVaporTests => SublimationNgrok/Sources/SublimationMocks}/MockServerApplication.swift (69%) rename Packages/{SublimationVapor/Tests/SublimationVaporTests => SublimationNgrok/Sources/SublimationTunnel}/MockServerDelegate.swift (83%) rename Packages/SublimationNgrok/Sources/{SublimationMocks => SublimationTunnel}/MockTunnelClient.swift (100%) rename Packages/{SublimationVapor/Tests/SublimationVaporTests => SublimationNgrok/Tests/SublimationNgrokTests}/NgrokCLIAPIConfigurationTests.swift (98%) rename Packages/{SublimationVapor/Tests/SublimationVaporTests => SublimationNgrok/Tests/SublimationNgrokTests}/NgrokCLIAPIServerFactoryTests.swift (95%) rename Packages/{SublimationVapor/Tests/SublimationVaporTests => SublimationNgrok/Tests/SublimationTunnelTests}/NetworkResultTests.swift (82%) diff --git a/Packages/Ngrokit/Package.swift b/Packages/Ngrokit/Package.swift index ef581c5..206b165 100644 --- a/Packages/Ngrokit/Package.swift +++ b/Packages/Ngrokit/Package.swift @@ -38,7 +38,8 @@ let package = Package( .macCatalyst(.v17) ], products: [ - .library(name: "Ngrokit", targets: ["Ngrokit"]) + .library(name: "Ngrokit", targets: ["Ngrokit"]), + .library(name: "NgrokitMocks", targets: ["NgrokitMocks"]) ], dependencies: [ .package( diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift index eee1d88..b66212e 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift @@ -27,14 +27,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -package import Foundation +public import Foundation package import Ngrokit -package final class MockNgrokCLIAPI: NgrokCLIAPI { +public final class MockNgrokCLIAPI: NgrokCLIAPI { package let process: any NgrokProcess package private(set) var httpPorts = [Int]() - package convenience init(id: UUID) { + public convenience init(id: UUID) { self.init(process: MockNgrokProcess(id: id)) } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift index 76197ab..292b63d 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift @@ -27,19 +27,19 @@ // OTHER DEALINGS IN THE SOFTWARE. // -package import Foundation +public import Foundation import Ngrokit -package final class MockNgrokProcess: NgrokProcess { - func terminate() { +public final class MockNgrokProcess: NgrokProcess { + public func terminate() { } - package let id: UUID + public let id: UUID - package init(id: UUID) { + public init(id: UUID) { self.id = id } - package func run(onError _: @escaping @Sendable (any Error) -> Void) async throws {} + public func run(onError _: @escaping @Sendable (any Error) -> Void) async throws {} } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift index eceefba..00eb34c 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift @@ -30,7 +30,7 @@ package import Foundation package import Ngrokit -package final class MockProcess: Processable { +public final class MockProcess: Processable { package func terminate() { } diff --git a/Packages/SublimationNgrok/Package.swift b/Packages/SublimationNgrok/Package.swift index 4a64e6b..f4b1f8f 100644 --- a/Packages/SublimationNgrok/Package.swift +++ b/Packages/SublimationNgrok/Package.swift @@ -77,7 +77,11 @@ let package = Package( .testTarget( name: "SublimationTunnelTests", dependencies: ["SublimationTunnel", "SublimationMocks"] - ) + ), + .testTarget( + name: "SublimationNgrokTests", + dependencies: ["SublimationNgrok", "SublimationMocks", .product(name: "NgrokitMocks", package: "Ngrokit")] + ), ] ) // swiftlint:enable explicit_acl explicit_top_level_acl diff --git a/Packages/SublimationVapor/Tests/SublimationVaporTests/MockServerApplication.swift b/Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift similarity index 69% rename from Packages/SublimationVapor/Tests/SublimationVaporTests/MockServerApplication.swift rename to Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift index cc92cdc..55ee8cf 100644 --- a/Packages/SublimationVapor/Tests/SublimationVaporTests/MockServerApplication.swift +++ b/Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift @@ -27,31 +27,32 @@ // OTHER DEALINGS IN THE SOFTWARE. // -import Logging +package import Foundation +package import Logging import SublimationCore import XCTest -internal class MockServerApplication: Application { - internal let httpServerConfigurationPort: Int - internal let httpServerTLS: Bool - internal let logger: Logger +package class MockServerApplication: Application { + package let httpServerConfigurationPort: Int + package let httpServerTLS: Bool + package let logger: Logger - internal private(set) var postRequests = [(URL, Data?)]() - internal private(set) var getRequests = [URL]() - internal private(set) var queuedGetResponses = [Result]() - internal private(set) var queuedPostResponses = [Result]() - internal init(httpServerConfigurationPort: Int, httpServerTLS: Bool, logger: Logger) { + package private(set) var postRequests = [(URL, Data?)]() + package private(set) var getRequests = [URL]() + package private(set) var queuedGetResponses = [Result]() + package private(set) var queuedPostResponses = [Result]() + package init(httpServerConfigurationPort: Int, httpServerTLS: Bool, logger: Logger) { self.httpServerConfigurationPort = httpServerConfigurationPort self.httpServerTLS = httpServerTLS self.logger = logger } - internal func post(to url: URL, body: Data?) async throws { + package func post(to url: URL, body: Data?) async throws { postRequests.append((url, body)) try queuedPostResponses.remove(at: 0).get() } - internal func get(from url: URL) async throws -> Data? { + package func get(from url: URL) async throws -> Data? { getRequests.append(url) return try queuedGetResponses.remove(at: 0).get() } diff --git a/Packages/SublimationVapor/Tests/SublimationVaporTests/MockServerDelegate.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift similarity index 83% rename from Packages/SublimationVapor/Tests/SublimationVaporTests/MockServerDelegate.swift rename to Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift index 3e392df..757b9be 100644 --- a/Packages/SublimationVapor/Tests/SublimationVaporTests/MockServerDelegate.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift @@ -26,20 +26,18 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // +package import Foundation -@testable import SublimationTunnel -import XCTest +package final class MockServerDelegate: TunnelServerDelegate { + package let id: UUID -internal final class MockServerDelegate: TunnelServerDelegate { - internal let id: UUID - - internal init(id: UUID) { + package init(id: UUID) { self.id = id } - internal func server( + package func server( _: any TunnelServer, updatedTunnel _: any Tunnel ) {} - internal func server(_: any TunnelServer, errorDidOccur _: any Error) {} + package func server(_: any TunnelServer, errorDidOccur _: any Error) {} } diff --git a/Packages/SublimationNgrok/Sources/SublimationMocks/MockTunnelClient.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockTunnelClient.swift similarity index 100% rename from Packages/SublimationNgrok/Sources/SublimationMocks/MockTunnelClient.swift rename to Packages/SublimationNgrok/Sources/SublimationTunnel/MockTunnelClient.swift diff --git a/Packages/SublimationVapor/Tests/SublimationVaporTests/NgrokCLIAPIConfigurationTests.swift b/Packages/SublimationNgrok/Tests/SublimationNgrokTests/NgrokCLIAPIConfigurationTests.swift similarity index 98% rename from Packages/SublimationVapor/Tests/SublimationVaporTests/NgrokCLIAPIConfigurationTests.swift rename to Packages/SublimationNgrok/Tests/SublimationNgrokTests/NgrokCLIAPIConfigurationTests.swift index 93fce11..769cf7a 100644 --- a/Packages/SublimationVapor/Tests/SublimationVaporTests/NgrokCLIAPIConfigurationTests.swift +++ b/Packages/SublimationNgrok/Tests/SublimationNgrokTests/NgrokCLIAPIConfigurationTests.swift @@ -27,6 +27,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +import SublimationMocks @testable import SublimationNgrok import XCTest diff --git a/Packages/SublimationVapor/Tests/SublimationVaporTests/NgrokCLIAPIServerFactoryTests.swift b/Packages/SublimationNgrok/Tests/SublimationNgrokTests/NgrokCLIAPIServerFactoryTests.swift similarity index 95% rename from Packages/SublimationVapor/Tests/SublimationVaporTests/NgrokCLIAPIServerFactoryTests.swift rename to Packages/SublimationNgrok/Tests/SublimationNgrokTests/NgrokCLIAPIServerFactoryTests.swift index 3407c5c..526fa67 100644 --- a/Packages/SublimationVapor/Tests/SublimationVaporTests/NgrokCLIAPIServerFactoryTests.swift +++ b/Packages/SublimationNgrok/Tests/SublimationNgrokTests/NgrokCLIAPIServerFactoryTests.swift @@ -29,10 +29,12 @@ import HTTPTypes import Ngrokit -import NgrokitMocks import OpenAPIRuntime -@testable import SublimationNgrok +import SublimationMocks +import SublimationTunnel import XCTest +@testable import SublimationNgrok +import NgrokitMocks internal final class MockTransport: ClientTransport { // swiftlint:disable:next unavailable_function @@ -57,7 +59,7 @@ internal class NgrokCLIAPIServerFactoryTests: XCTestCase { ) let delegateID = UUID() let processID = UUID() - let configuration = NgrokCLIAPIConfiguration(serverApplication: application) + let configuration = NgrokCLIAPIConfiguration(application: application) let factory = NgrokCLIAPIServerFactory( cliAPI: MockNgrokCLIAPI(id: processID), ngrokClient: { NgrokClient(transport: MockTransport()) diff --git a/Packages/SublimationVapor/Tests/SublimationVaporTests/NetworkResultTests.swift b/Packages/SublimationNgrok/Tests/SublimationTunnelTests/NetworkResultTests.swift similarity index 82% rename from Packages/SublimationVapor/Tests/SublimationVaporTests/NetworkResultTests.swift rename to Packages/SublimationNgrok/Tests/SublimationTunnelTests/NetworkResultTests.swift index 92c9666..6e032b0 100644 --- a/Packages/SublimationVapor/Tests/SublimationVaporTests/NetworkResultTests.swift +++ b/Packages/SublimationNgrok/Tests/SublimationTunnelTests/NetworkResultTests.swift @@ -1,31 +1,31 @@ -// -// NetworkResultTests.swift -// Sublimation -// -// Created by Leo Dion. -// Copyright © 2024 BrightDigit. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the “Software”), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// +//// +//// NetworkResultTests.swift +//// Sublimation +//// +//// Created by Leo Dion. +//// Copyright © 2024 BrightDigit. +//// +//// Permission is hereby granted, free of charge, to any person +//// obtaining a copy of this software and associated documentation +//// files (the “Software”), to deal in the Software without +//// restriction, including without limitation the rights to use, +//// copy, modify, merge, publish, distribute, sublicense, and/or +//// sell copies of the Software, and to permit persons to whom the +//// Software is furnished to do so, subject to the following +//// conditions: +//// +//// The above copyright notice and this permission notice shall be +//// included in all copies or substantial portions of the Software. +//// +//// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +//// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +//// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +//// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +//// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +//// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +//// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +//// OTHER DEALINGS IN THE SOFTWARE. +//// import AsyncHTTPClient import OpenAPIRuntime diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift b/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift index 272300c..fcddaa6 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift @@ -33,7 +33,7 @@ import OpenAPIRuntime public import Sublimation public import Vapor -extension Sublimation: LifecycleHandler { +extension Sublimation: @retroactive LifecycleHandler { public func willBoot(_ application: Vapor.Application) throws { Task { try await self.sublimatory.run()