package main import "testing" // The transport is a stored choice now, but installs exist that predate it and // hold only a host. Reading those as "bridge" is what keeps a working station // working across the upgrade — the old code used a host for exactly that. func TestTheLinkIsReadFromAnOlderInstall(t *testing.T) { cases := []struct { link, host, want string }{ {"", "", kenwoodLinkUSB}, // nothing configured {"", "192.168.1.50:4999", kenwoodLinkBridge}, // upgraded: host only {kenwoodLinkUSB, "192.168.1.50:4999", kenwoodLinkUSB}, // chose USB, host left behind {kenwoodLinkBridge, "", kenwoodLinkBridge}, {kenwoodLinkNative, "", kenwoodLinkNative}, {"nonsense", "", kenwoodLinkUSB}, // a value nobody wrote: fall back, don't guess } for _, c := range cases { if got := kenwoodLinkOr(c.link, c.host); got != c.want { t.Errorf("link=%q host=%q → %q, want %q", c.link, c.host, got, c.want) } } } // The one that matters after the fact: an operator who picks USB while an old // host is still stored must get the COM port. The previous code preferred the // host whenever it was non-empty, which is invisible from the settings page. func TestChoosingUSBBeatsALeftoverHost(t *testing.T) { if got := kenwoodLinkOr(kenwoodLinkUSB, "10.0.0.9:4999"); got != kenwoodLinkUSB { t.Fatalf("a leftover host overrode the operator's choice: %q", got) } }