mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-26 03:17:49 +02:00
- Info.WiFi uses json "wf" with omitempty so systems without Wi-Fi no longer store/broadcast "wifi":null - move osascript exec into wifi_darwin.go; drop unused commandRunner - share strongest-connection logic between table cell and sorting - trim agent/wifi README
41 lines
1015 B
Go
41 lines
1015 B
Go
package system
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/fxamacker/cbor/v2"
|
|
)
|
|
|
|
func TestWiFiWireSnapshot(t *testing.T) {
|
|
signal := -55.0
|
|
for _, wifi := range []map[string]WiFi{nil, {}, {"wlan0": {SSID: "home", Signal: &signal}, "wlan1": {}}} {
|
|
original := CombinedData{Info: Info{WiFi: wifi}, Stats: Stats{WiFi: make(map[string]int8, len(wifi))}}
|
|
for id := range wifi {
|
|
original.Stats.WiFi[id] = -55
|
|
}
|
|
encoded, err := cbor.Marshal(original)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var decoded CombinedData
|
|
if err = cbor.Unmarshal(encoded, &decoded); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(decoded.Info.WiFi) != len(wifi) || len(decoded.Stats.WiFi) != len(wifi) {
|
|
t.Fatal(decoded)
|
|
}
|
|
encoded, err = json.Marshal(decoded.Info)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var info map[string]any
|
|
if err = json.Unmarshal(encoded, &info); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := info["wf"]; ok != (len(wifi) > 0) {
|
|
t.Fatalf("wf present = %v for snapshot %v", ok, wifi)
|
|
}
|
|
}
|
|
}
|