mirror of
https://github.com/cirruslabs/tart.git
synced 2026-10-03 20:55:59 +02:00
Ignore commented-out bootptab reservations (#1358)
This commit is contained in:
@@ -18,6 +18,11 @@ struct Bootptab {
|
||||
}
|
||||
|
||||
for line in contents.split(whereSeparator: \.isNewline) {
|
||||
// Skip comment lines
|
||||
guard !line.hasPrefix("#") else {
|
||||
continue
|
||||
}
|
||||
|
||||
let fields = line.split(whereSeparator: \.isWhitespace)
|
||||
|
||||
// Skip lines that don't look like reservation fields
|
||||
|
||||
@@ -3,6 +3,37 @@ import Network
|
||||
@testable import tart
|
||||
|
||||
final class BootptabTests: XCTestCase {
|
||||
func testCommentedReservation() throws {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
let contents = """
|
||||
%
|
||||
#client1 1 02:ab:00:01:02:03 192.168.64.2
|
||||
"""
|
||||
try contents.write(to: url, atomically: true, encoding: .utf8)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let bootptab = try XCTUnwrap(Bootptab(url))
|
||||
|
||||
XCTAssertNil(try bootptab.ResolveMACAddress(
|
||||
macAddress: MACAddress(fromString: "02:ab:00:01:02:03")!))
|
||||
}
|
||||
|
||||
func testCommentedReservationWithActiveReservation() throws {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
let contents = """
|
||||
%
|
||||
#client1 1 02:ab:00:01:02:03 192.168.64.2
|
||||
client1 1 02:ab:00:01:02:03 192.168.64.3
|
||||
"""
|
||||
try contents.write(to: url, atomically: true, encoding: .utf8)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let bootptab = try XCTUnwrap(Bootptab(url))
|
||||
|
||||
XCTAssertEqual(try bootptab.ResolveMACAddress(
|
||||
macAddress: MACAddress(fromString: "02:ab:00:01:02:03")!), IPv4Address("192.168.64.3"))
|
||||
}
|
||||
|
||||
func testResolveMACAddress() throws {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user