Files
RouterOS/RouterOSAssistantTests/RouterOSCommandBuilderTests.swift
T
KayandClaude Sonnet 5 016f57f613 M5: WLAN-Schritt + echte set-Operation im Befehlsmodell
RouterOSCommand unterstützt jetzt neben .add auch .set (bestehenden
Eintrag ändern statt neuen anzulegen) — nötig, weil WLAN-Interfaces
schon vor jeder Konfiguration existieren. SSH löst das per CLI-eigenem
"set [find field=value] ..." inline auf; REST hat dafür keine
Entsprechung und muss den Eintrag erst per GET suchen (matchField/
matchValue), seine .id auslesen, dann PATCH auf restPath/<id> senden
(RestTransport.findItemID). Mit dem Nutzer abgestimmte Entscheidung
gegen die einfachere "WLAN nur über SSH"-Variante.

WifiNetworkConfig: pro erkanntem Legacy-Wireless-Interface
(/interface wireless, type=wlan) eine SSID/Passwort-Konfiguration,
Sicherheitsprofil (WPA2) wird zuerst angelegt, dann per set mit dem
Interface verknüpft. Geräte ohne WLAN zeigen einen Hinweistext statt
des Formulars (User-Anforderung: muss berücksichtigt werden). Geräte
mit dem neueren "wifi"-Treiber (type=wifi, wifiwave2/802.11ax) werden
erkannt, aber bewusst nicht unterstützt -- anderes Menü, eigener
Umbau nötig, dazu Hinweistext.

cliPath wurde in allen bisherigen Command-Buildern (Wan/Lan/Vlan) zu
menuPath + .add migriert, da RouterOSCommand jetzt operation-basiert
ist statt den Aktionswort im Pfad-String zu verstecken.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
2026-09-12 13:41:25 +02:00

78 lines
2.8 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, 4)
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")
}
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")
}
}