Skip to content

Commit

Permalink
Bring back Advisor unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
halo committed Feb 24, 2024
1 parent 958c56f commit bf71a4e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
63 changes: 32 additions & 31 deletions LinkLiarTests/AdvisorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@ import XCTest
@testable import LinkLiar

class AdvisorTests: XCTestCase {
//
// func testRandom() {
// let dictionary = [
// "e1:e1:e1:e1:e1:e1":
// ["action": "random"]
// ]
// let config = Config.Reader(dictionary)
// let interface = Interface("e1:e1:e1:e1:e1:e1")
// interface.overrideSoftMacInTests = MAC("e2:e2:e2:e2:e2:e2")
// let arbiter = Config.Arbiter(config: config, hardMAC: interface.hardMAC)
// arbiter.overrideAddressInTests = MAC("aa:aa:aa:aa:aa:aa")
// let advisor = Advisor(interface: interface, arbiter: arbiter)
//
// let expectedAddress = MAC("aa:aa:aa:aa:aa:aa")
// XCTAssertEqual(expectedAddress, advisor.addressForStandard)
// }
//
// func testRandomWhenAlreadyRandom() {
// let dictionary = [
// "e1:e1:e1:e1:e1:e1":
// ["action": "random"]
// ]
// let config = Config.Reader(dictionary)
// let interface = Interface("e1:e1:e1:e1:e1:e1")
// interface.overrideSoftMacInTests = MAC("00:03:93:e2:e2:e2")
// let arbiter = Config.Arbiter(config: config, hardMAC: interface.hardMAC)
// arbiter.overrideAddressInTests = MAC("aa:aa:aa:aa:aa:aa")
// let advisor = Advisor(interface: interface, arbiter: arbiter)
//
// XCTAssertNil(advisor.addressForStandard)
// }
func testRandom() {
let dictionary = [
"e1:e1:e1:e1:e1:e1":
["action": "random"]
]
let config = Config.Reader(dictionary)
let interface = Interface(bsd: BSD("en0")!,
hardMAC: MAC("e1:e1:e1:e1:e1:e1")!,
stubSoftMAC: MAC("e2:e2:e2:e2:e2:e2"))!
let arbiter = Config.Arbiter(config: config, hardMAC: interface.hardMAC)
arbiter.stubAddressInTests = MAC("aa:aa:aa:aa:aa:aa")
let advisor = Advisor(interface: interface, arbiter: arbiter)

let expectedAddress = MAC("aa:aa:aa:aa:aa:aa")
XCTAssertEqual(expectedAddress, advisor.address)
}

func testRandomWhenAlreadyRandom() {
let dictionary = [
"e1:e1:e1:e1:e1:e1":
["action": "random"]
]
let config = Config.Reader(dictionary)
let interface = Interface(bsd: BSD("en0")!,
hardMAC: MAC("e1:e1:e1:e1:e1:e1")!,
stubSoftMAC: MAC("00:03:93:e2:e2:e2"))!
let arbiter = Config.Arbiter(config: config, hardMAC: interface.hardMAC)
arbiter.stubAddressInTests = MAC("aa:aa:aa:aa:aa:aa")
let advisor = Advisor(interface: interface, arbiter: arbiter)

XCTAssertNil(advisor.address)
}
}
6 changes: 4 additions & 2 deletions LinkTools/Config/Arbiter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: MIT

extension Config {
/// Determines the priority of configuration values.
/// E.g. an interface specific value overrides general defaults.
class Arbiter {
// MARK: Class Methods

Expand Down Expand Up @@ -62,12 +64,12 @@ extension Config {
config.policy(hardMAC).exceptionAddress
}

var overrideAddressInTests: MAC?
var stubAddressInTests: MAC?

// MARK: Instance Methods

func randomAddress() -> MAC {
if let override = overrideAddressInTests {
if let override = stubAddressInTests {
Log.debug("Using static random address in tests")
return override
}
Expand Down

0 comments on commit bf71a4e

Please sign in to comment.