Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/ApplePlatformChecks/CertificateCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Foundation
import NetTesterLib

final public class CertificateCheck: NSObject, CheckProtocol {
public var debugInformation: String { debugBreadcrumbs.joined(separator: "\n")}
private var debugBreadcrumbs: [String] = []
public var debugInformation: String { shouldShowDebugInformation ? debugBreadcrumbs.joined(separator: "\n") : "" }
public private(set) var debugBreadcrumbs: [String] = []
public var name: String?
public private(set) var status: CheckStatus = .notLaunchedYet
private var session: URLSession?
Expand Down
6 changes: 6 additions & 0 deletions Sources/NetTesterLib/CheckProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ public enum CheckStatus: Sendable {
/// Strictly speaking, it is not sendable, but I only send it once mutations are done..
public protocol CheckProtocol: AnyObject, Sendable {
var status: CheckStatus { get }
var debugBreadcrumbs: [String] { get }
var debugInformation: String { get }
var shouldShowDebugInformation: Bool { get }
var name: String? { get set }

@discardableResult
func performCheck() async -> CheckStatus
}

extension CheckProtocol {
public var shouldShowDebugInformation: Bool {
[.failed, .warning].contains(status)
}

public func named(_ name: String) -> Self {
self.name = name
return self
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetTesterLib/ThrowableCheck.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open class ThrowableCheck: CheckProtocol {
open var status: CheckStatus = .notLaunchedYet
public var debugInformation: String { debugBreadcrumbs.joined(separator: "\n")}
public var debugInformation: String { shouldShowDebugInformation ? debugBreadcrumbs.joined(separator: "\n") : "" }
open var debugBreadcrumbs: [String] = []

open var name: String?
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetTesterUIKit/NetworkCheckCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NetworkCheckCell: UITableViewCell {
textLabel?.text = check.name ?? "\(type(of: check))"
imageView?.image = check.status.cellImage
imageView?.tintColor = check.status.cellImageTint
detailTextLabel?.text = [.failed, .warning].contains(check.status) ? check.debugInformation : nil
detailTextLabel?.text = check.debugInformation
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/network-tester-cli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ checks.append(CertificateCheck(url: URL(string: "https://google.com")!, expected

let runner = CheckRunner()
runner.didUpdate = { check in
if check.debugInformation.isEmpty {
if check.debugBreadcrumbs.isEmpty {
print("check \(check) finished")

} else {
print("check \(check) finished:")
print(check.debugInformation)
print(check.debugBreadcrumbs.joined(separator: "\n"))
}
print()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/network-tester-tui/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct CheckView: View {
}
if [.warning, .failed].contains(check.status) {
Text("")
ForEach(Array(check.debugInformation.split(separator: "\n").map {" \($0)"}.enumerated()), id: \.offset) {
ForEach(Array(check.debugBreadcrumbs.map { " \($0)" }.enumerated()), id: \.offset) {
Text($0.element)
}
Text("")
Expand Down