forked from kay/RouterOS
Beide Bugs in ExpertViewModel.pendingCommand, betreffen Experte-Tab direkt (nicht nur den neuen Übersicht-Bearbeiten-Weg): - Bug 25: ein geleertes Textfeld (z.B. Kommentar löschen) wurde beim Speichern aus den Argumenten gefiltert statt explizit als "" gesendet — RouterOS' `set` ändert nur übergebene Parameter, ein weggelassener bleibt unangetastet statt geleert. Fix: Feld bleibt im Argument-Set, wenn es vorher einen Wert hatte; RouterOSCommand's SSH-Zeilen-Rendering gibt einen leeren Wert jetzt als `""` statt als nacktes `feld=` aus. - Bug 26: eine Route bearbeiten (z.B. nur Kommentar ändern) scheiterte mit "bad parameter immediate-gw" — dieses von RouterOS mitgelieferte, nur lesbare/berechnete Feld landete unkuratiert in den freien "Weiteren Parametern" und wurde bei jedem Speichern blind mitgeschickt. Fix: ein unkuratiertes Feld wird nur noch gesendet, wenn sein Wert sich gegenüber dem ursprünglich geladenen Item tatsächlich geändert hat. 54 Unit-Tests grün (neue ExpertViewModelTests + eine Ergänzung in RouterOSCommandBuilderTests). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YDmUd93KxsYGr2kLTotWnG
120 lines
4.4 KiB
Swift
120 lines
4.4 KiB
Swift
import XCTest
|
|
@testable import RouterOSAssistant
|
|
|
|
final class RouterOSCommandBuilderTests: XCTestCase {
|
|
func testWanDhcpClientCommand() {
|
|
let config = WanConfig(interfaceName: "ether1", mode: .dhcpClient)
|
|
let commands = config.buildCommands()
|
|
|
|
XCTAssertEqual(commands.count, 1)
|
|
XCTAssertEqual(commands[0].menuPath, "/ip dhcp-client")
|
|
XCTAssertEqual(commands[0].operation, .add)
|
|
XCTAssertEqual(commands[0].arguments["interface"], "ether1")
|
|
}
|
|
|
|
func testWanStaticIPCommandsIncludeRouteOnlyWhenGatewayGiven() {
|
|
var config = WanConfig(interfaceName: "ether1", mode: .staticIP)
|
|
config.staticAddress = "203.0.113.5/24"
|
|
|
|
XCTAssertEqual(config.buildCommands().count, 1)
|
|
|
|
config.staticGateway = "203.0.113.1"
|
|
let commands = config.buildCommands()
|
|
|
|
XCTAssertEqual(commands.count, 2)
|
|
XCTAssertEqual(commands[0].arguments["address"], "203.0.113.5/24")
|
|
XCTAssertEqual(commands[1].arguments["gateway"], "203.0.113.1")
|
|
}
|
|
|
|
func testWanPppoeCommand() {
|
|
var config = WanConfig(interfaceName: "ether1", mode: .pppoe)
|
|
config.pppoeUsername = "user@isp"
|
|
config.pppoePassword = "secret"
|
|
|
|
let commands = config.buildCommands()
|
|
|
|
XCTAssertEqual(commands.count, 1)
|
|
XCTAssertEqual(commands[0].menuPath, "/interface pppoe-client")
|
|
XCTAssertEqual(commands[0].arguments["user"], "user@isp")
|
|
XCTAssertEqual(commands[0].arguments["password"], "secret")
|
|
}
|
|
|
|
func testLanDhcpCommandsCoverAddressPoolServerAndNetwork() {
|
|
let config = LanDhcpConfig()
|
|
let commands = config.buildCommands()
|
|
|
|
XCTAssertEqual(commands.count, 6)
|
|
XCTAssertEqual(commands[0].menuPath, "/ip address")
|
|
XCTAssertEqual(commands[1].menuPath, "/ip pool")
|
|
XCTAssertEqual(commands[2].menuPath, "/ip dhcp-server")
|
|
XCTAssertEqual(commands[3].menuPath, "/ip dhcp-server network")
|
|
XCTAssertEqual(commands[3].arguments["gateway"], "192.168.88.1")
|
|
XCTAssertEqual(commands[4].menuPath, "/interface list")
|
|
XCTAssertEqual(commands[4].arguments["name"], "LAN")
|
|
XCTAssertEqual(commands[5].menuPath, "/interface list member")
|
|
XCTAssertEqual(commands[5].arguments["list"], "LAN")
|
|
XCTAssertEqual(commands[5].arguments["interface"], "bridge")
|
|
}
|
|
|
|
func testLanDhcpCommandsDetachInterfaceFromBridgeWhenNotDefaultBridge() {
|
|
var config = LanDhcpConfig()
|
|
config.interfaceName = "ether4"
|
|
let commands = config.buildCommands()
|
|
|
|
XCTAssertEqual(commands.count, 7)
|
|
XCTAssertEqual(commands[0].menuPath, "/interface bridge port")
|
|
XCTAssertEqual(commands[0].operation, .remove(matchField: "interface", matchValue: "ether4"))
|
|
XCTAssertEqual(commands[1].menuPath, "/ip address")
|
|
}
|
|
|
|
func testCliLineRendersEmptyValueAsExplicitEmptyQuotes() {
|
|
let command = RouterOSCommand.set(
|
|
menuPath: "/ip route",
|
|
restPath: "ip/route",
|
|
matchField: ".id",
|
|
matchValue: "*1",
|
|
arguments: ["comment": ""],
|
|
summary: "test"
|
|
)
|
|
|
|
XCTAssertEqual(command.cliLine, "/ip route set [find .id=*1] comment=\"\"")
|
|
}
|
|
|
|
func testCliLineRendersSortedQuotedArgumentsForAdd() {
|
|
let command = RouterOSCommand.add(
|
|
menuPath: "/interface pppoe-client",
|
|
restPath: "interface/pppoe-client",
|
|
arguments: ["user": "user@isp", "password": "a secret"],
|
|
summary: "test"
|
|
)
|
|
|
|
XCTAssertEqual(command.cliLine, "/interface pppoe-client add password=\"a secret\" user=user@isp")
|
|
}
|
|
|
|
func testCliLineRendersFindLookupForSet() {
|
|
let command = RouterOSCommand.set(
|
|
menuPath: "/interface wireless",
|
|
restPath: "interface/wireless",
|
|
matchField: "name",
|
|
matchValue: "wlan1",
|
|
arguments: ["ssid": "Home"],
|
|
summary: "test"
|
|
)
|
|
|
|
XCTAssertEqual(command.cliLine, "/interface wireless set [find name=wlan1] ssid=Home")
|
|
}
|
|
|
|
func testCliLineRendersFindLookupForAction() {
|
|
let command = RouterOSCommand.action(
|
|
menuPath: "/ip dhcp-server lease",
|
|
restPath: "ip/dhcp-server/lease",
|
|
name: "make-static",
|
|
matchField: ".id",
|
|
matchValue: "*7",
|
|
summary: "test"
|
|
)
|
|
|
|
XCTAssertEqual(command.cliLine, "/ip dhcp-server lease make-static [find .id=*7]")
|
|
}
|
|
}
|