Skip to content

Commit

Permalink
fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jul 30, 2024
1 parent 3297ad1 commit 27941dd
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 367 deletions.
7 changes: 6 additions & 1 deletion Packages/Ngrokit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ let package = Package(
],
swiftSettings: swiftSettings
),
.target(
name: "NgrokitMocks",
dependencies: ["Ngrokit"],
swiftSettings: swiftSettings
),
.testTarget(
name: "NgrokitTests",
dependencies: ["Ngrokit"]
dependencies: ["Ngrokit", "NgrokitMocks"]
)
]
)
Expand Down
2 changes: 1 addition & 1 deletion Packages/Ngrokit/Sources/NgrokitMocks/MockAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//

import Foundation
import NgrokOpenAPIClient
package import NgrokOpenAPIClient

#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
2 changes: 1 addition & 1 deletion Packages/Ngrokit/Sources/NgrokitMocks/MockDataHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
package import Foundation
import Ngrokit

package struct MockDataHandle: DataHandle {
Expand Down
4 changes: 2 additions & 2 deletions Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
import Ngrokit
package import Foundation
package import Ngrokit

package final class MockNgrokCLIAPI: NgrokCLIAPI {
package let process: any NgrokProcess
Expand Down
6 changes: 5 additions & 1 deletion Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
package import Foundation
import Ngrokit

package final class MockNgrokProcess: NgrokProcess {
func terminate() {

}

package let id: UUID

package init(id: UUID) {
Expand Down
8 changes: 6 additions & 2 deletions Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
import Ngrokit
package import Foundation
package import Ngrokit

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

}

package typealias PipeType = MockPipe

package let executableFilePath: String
Expand Down
4 changes: 2 additions & 2 deletions Packages/Ngrokit/Sources/NgrokitMocks/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
package import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
package import FoundationNetworking
#endif

extension URL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
internal import Network

extension BindingConfiguration {
internal func urls(defaultIsSecure: Bool, defaultPort: Int) -> [URL] {
let isSecure = self.hasIsSecure ? self.isSecure : defaultIsSecure
let port = self.hasPort ? Int(self.port) : defaultPort
internal func urls(defaults : URLDefaultConfiguration) -> [URL] {
let isSecure = self.hasIsSecure ? self.isSecure : defaults.isSecure
let port = self.hasPort ? Int(self.port) : defaults.port
return self.hosts.compactMap { host in
if host.isLocalhost() { return nil }
if host.isValidIPv6Address() { return nil }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@
public import Logging
#endif

public struct URLDefaultConfiguration {
public init(isSecure: Bool = false, port: Int = 8080) {
self.isSecure = isSecure
self.port = port
}

public let isSecure: Bool
public let port: Int
}

public actor BonjourClient {
private let browser: NWBrowser
private let streams = StreamManager<UUID, URL>()
private let logger: Logger?
private let defaultURLConfiguration: URLDefaultConfiguration

public var urls: AsyncStream<URL> {
get async {
Expand All @@ -63,15 +74,15 @@
}
}

public init(logger: Logger? = nil) {
public init(logger: Logger? = nil, defaultURLConfiguration : URLDefaultConfiguration = .init()) {

assert(logger != nil)
let descriptor: NWBrowser.Descriptor
#if os(watchOS)

descriptor = .bonjourWithTXTRecord(type: "_sublimation._tcp", domain: nil)
#else
descriptor = .bonjour(type: "_sublimation._tcp", domain: nil)
#endif

let browser = NWBrowser(for: descriptor, using: .tcp)
self.defaultURLConfiguration = defaultURLConfiguration
self.browser = browser
self.logger = logger
browser.browseResultsChangedHandler = { results, _ in self.parseResults(results) }
Expand Down Expand Up @@ -100,6 +111,7 @@
case indexMismatch(Int)
case base64Decoding
}

private static func bindingConfiguration(txtRecordDictionary: [String: String]) throws
-> BindingConfiguration
{
Expand All @@ -126,7 +138,6 @@
}
let values = pairs.map(\.1)
guard let data: Data = .init(base64Encoded: values.joined()) else {
// self.logger?.error("Unable to decode Base64 TXT Record for \(result.endpoint.debugDescription)")
throw TXTRecordError.base64Decoding
}
return try .init(serializedData: data)
Expand All @@ -146,7 +157,7 @@
continue
}
#warning("Defaults should be passed to connection")
let urls = configuration.urls(defaultIsSecure: false, defaultPort: 8_080)
let urls = configuration.urls(defaults: self.defaultURLConfiguration)
self.append(urls: urls)
}
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 27941dd

Please sign in to comment.