Files
MacMonitor/Tests/MMProcessDetailsTests.swift
T
gronod a46f91f2ad
MacMonitor CI/CD Pipeline / Build & Test (Intel x86_64) (push) Canceled after 0s
feat(telemetry): implement per-process thread, file descriptor, and socket inspector (fixes #12)
2026-09-08 12:41:56 +01:00

51 lines
1.7 KiB
Swift

import XCTest
@testable import MacMonitor
final class MMProcessDetailsTests: XCTestCase {
func testInspectionSummaryCalculation() {
let mockThreads: [[String: Any]] = [
["threadId": 1, "state": "Running"],
["threadId": 2, "state": "Waiting"]
]
let mockFDs: [[String: Any]] = [
["fd": 0, "type": "File", "path": "/dev/null"],
["fd": 1, "type": "File", "path": "/tmp/test.log"],
["fd": 3, "type": "Socket", "path": "TCP 127.0.0.1:80 -> 127.0.0.1:50000"]
]
let mockSockets: [[String: Any]] = [
["fd": 3, "protocol": "TCP", "localAddress": "127.0.0.1", "localPort": 80, "state": "LISTEN"]
]
let summary = MMProcessDetailInspector.summarizeInspectionResults(
withPID: 1234,
threads: mockThreads,
fds: mockFDs,
sockets: mockSockets
)
let pid = summary["pid"] as? Int ?? 0
let threadCount = summary["threadCount"] as? Int ?? 0
let openFDCount = summary["openFDCount"] as? Int ?? 0
let socketCount = summary["socketCount"] as? Int ?? 0
XCTAssertEqual(pid, 1234)
XCTAssertEqual(threadCount, 2)
XCTAssertEqual(openFDCount, 3)
XCTAssertEqual(socketCount, 1)
}
func testLiveProcessInspection() {
let currentPid = getpid()
let result = MMProcessDetailInspector.inspectProcess(withPID: currentPid)
XCTAssertNotNil(result)
let threadCount = result?["threadCount"] as? Int ?? 0
XCTAssertGreaterThan(threadCount, 0)
let fds = result?["fileDescriptors"] as? [[String: Any]]
XCTAssertNotNil(fds)
}
}