50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
"""NIC link label: an unknown link must never read as a working one.
|
|
|
|
Link speed and duplex are paired onto the interface rows from a second WMI
|
|
class, so three states are possible: read successfully, unreadable, and
|
|
disconnected. Verified on a live box that a DISCONNECTED adapter returns empty
|
|
Speed and FullDuplex - two of four NICs on the test machine were in that state.
|
|
|
|
That is the trap these tests pin. Defaulting an absent speed to 0 or an absent
|
|
duplex to False would report every unplugged NIC as half duplex, which is the
|
|
exact signature of the cable/port fault this field exists to catch. A column
|
|
that cries fault on every disconnected NIC is a column nobody reads.
|
|
"""
|
|
|
|
from plugins.endpoints.api.routes import _link_label
|
|
|
|
|
|
def test_a_gigabit_full_duplex_link_is_not_annotated():
|
|
"""The normal case should be quiet so the abnormal case stands out."""
|
|
assert _link_label(1000000000, True) == '1 Gb'
|
|
|
|
|
|
def test_half_duplex_is_called_out_because_it_is_the_actionable_case():
|
|
assert _link_label(100000000, False) == '100 Mb half duplex'
|
|
|
|
|
|
def test_a_disconnected_adapter_reads_as_unknown_not_half_duplex():
|
|
"""The live-box case: disconnected NICs return empty speed and duplex.
|
|
|
|
Reading this as half duplex would flag every unplugged NIC as a fault.
|
|
"""
|
|
assert _link_label(None, None) == '-'
|
|
|
|
|
|
def test_an_unreadable_duplex_on_a_live_link_is_not_assumed_half():
|
|
"""Speed known, duplex not. Unknown duplex must not render as a fault."""
|
|
assert _link_label(10000000000, None) == '10 Gb'
|
|
|
|
|
|
def test_zero_speed_is_unknown_rather_than_a_zero_speed_link():
|
|
assert _link_label(0, True) == '-'
|
|
|
|
|
|
def test_sub_gigabit_speeds_stay_in_megabits():
|
|
assert _link_label(10000000, True) == '10 Mb'
|
|
|
|
|
|
def test_speeds_do_not_render_trailing_zeros():
|
|
"""2.5Gb NICs are common now; the label should not read '2.5000 Gb'."""
|
|
assert _link_label(2500000000, True) == '2.5 Gb'
|