Skip to content

Commit

Permalink
fixing tests for now
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jul 31, 2024
1 parent 27941dd commit e72fd89
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 64 deletions.
3 changes: 2 additions & 1 deletion Packages/Ngrokit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
12 changes: 6 additions & 6 deletions Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
2 changes: 1 addition & 1 deletion Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
package import Foundation
package import Ngrokit

package final class MockProcess: Processable {
public final class MockProcess: Processable {
package func terminate() {

}
Expand Down
6 changes: 5 additions & 1 deletion Packages/SublimationNgrok/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data?, any Error>]()
internal private(set) var queuedPostResponses = [Result<Void, any Error>]()
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<Data?, any Error>]()
package private(set) var queuedPostResponses = [Result<Void, any Error>]()
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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

import SublimationMocks
@testable import SublimationNgrok
import XCTest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MockProcess>(
cliAPI: MockNgrokCLIAPI(id: processID), ngrokClient: {
NgrokClient(transport: MockTransport())
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e72fd89

Please sign in to comment.