Commit b8ea495
committed
test(sensors-*): add --test hooks and fixture-based unit tests
The three `sensors-*` plugins talk to `psutil.sensors_*()` directly
instead of parsing a shell command, so they previously had no
fixture-based tests. Give each a `--test` hook that loads the return
value from a JSON fixture mirroring psutil's shape:
sensors-battery {"percent": ..., "secsleft": ..., "power_plugged": ...}
or `null` for "no battery installed"
sensors-fans {"<group>": [{"label": ..., "current": ...}]}
sensors-temperatures {"<group>": [{"label": ..., "current": ...,
"high": ..., "critical": ...}]}
Each plugin gains a declarative `TESTS` list that exercises the
obvious nominal / warn / crit / no-sensors cases plus a few edge
cases inspired by psutil's own test suite
(`tests/test_linux.py::TestSensors*`):
- sensors-battery: `power_plugged = None`, `secsleft = -1`
(POWER_TIME_UNKNOWN)
- sensors-temperatures: the `coretemp-and-acpitz-nominal` fixture
mixes sensors with and without threshold metadata
Real host captures also ship as additional fixtures so the suite
exercises real-world quirks the synthetic data would miss:
- sensors-temperatures `dell-laptop-real-capture`: nvme reports
`high = critical = 65261.85` (kelvin 65535 minus 273.15, a
"no threshold configured" sentinel) and `dell_ddv` reports
`high = 0.0` for the same reason.
- sensors-temperatures `coolermaster-real-capture`: two acpitz
zones plus `coretemp` Package + 6 cores, all nominal.
- sensors-fans `dell-laptop-real-capture`: labelled `dell_ddv` fans
plus the unlabelled `dell_smm` re-exposure of the same data.
- sensors-fans `coolermaster-real-capture`: the "no fans detected"
branch on a fanless desktop.
- sensors-battery `dell-laptop-real-capture`: 79 % plugged in and
charging.
- sensors-battery `coolermaster-real-capture`: the "no battery
installed" branch on a desktop.
Two related fixes to the plugins:
- **sensors-temperatures**: `_sanitize_threshold()` now rejects
sentinel "no threshold" values reported by real hardware:
`None`, `<= 0`, or above 200 C. Both the Dell `dell_ddv` zero and
the NVMe 65261.85 kelvin-overflow value used to trip the plugin
into STATE_WARN on any real host that runs those drivers; now
both are silently ignored and only real thresholds drive state.
Also bumps `__version__`.
- **sensors-battery**: the message string now ends with the state
marker (`[WARNING]` / `[CRITICAL]`), matching what sensors-fans
and sensors-temperatures already do per entry.1 parent 28a7752 commit b8ea495
26 files changed
Lines changed: 646 additions & 12 deletions
File tree
- check-plugins
- openvpn-client-list/unit-test/stdout
- sensors-battery
- unit-test
- stdout
- sensors-fans
- unit-test
- stdout
- sensors-temperatures
- unit-test
- stdout
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
27 | 41 | | |
28 | 42 | | |
29 | | - | |
| 43 | + | |
30 | 44 | | |
31 | 45 | | |
32 | 46 | | |
| |||
64 | 78 | | |
65 | 79 | | |
66 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
67 | 88 | | |
68 | 89 | | |
69 | 90 | | |
| |||
77 | 98 | | |
78 | 99 | | |
79 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
80 | 116 | | |
81 | 117 | | |
82 | 118 | | |
| |||
86 | 122 | | |
87 | 123 | | |
88 | 124 | | |
89 | | - | |
| 125 | + | |
90 | 126 | | |
91 | 127 | | |
92 | 128 | | |
93 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
94 | 134 | | |
95 | 135 | | |
96 | 136 | | |
| |||
121 | 161 | | |
122 | 162 | | |
123 | 163 | | |
| 164 | + | |
124 | 165 | | |
125 | 166 | | |
126 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments