protocol/aprs: refactored
Some checks failed
Run tests / test (1.25) (push) Failing after 1m37s
Run tests / test (stable) (push) Failing after 1m37s

This commit is contained in:
2026-03-02 22:28:17 +01:00
parent 452f521866
commit 63040a44b3
24 changed files with 3506 additions and 1533 deletions

View File

@@ -0,0 +1,69 @@
package aprs
import "testing"
func TestParseQuery(t *testing.T) {
tests := []struct {
Name string
Raw Raw
Want *Query
}{
{
"general query",
"?APRS?",
&Query{
Type: "APRS",
},
},
{
"general query for stations within a target footprint of radius 200 miles",
"?APRS? 34.02,-117.15,0200",
&Query{
Type: "APRS",
Latitude: 34.02,
Longitude: -117.15,
Radius: milesToMeters(200),
},
},
}
var decoder queryDecoder
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
frame := &Frame{Raw: test.Raw}
if !decoder.CanDecode(frame) {
t.Fatalf("%T can't decode %q", decoder, test.Raw)
}
v, err := decoder.Decode(frame)
if err != nil {
t.Fatal(err)
}
testCompareQuery(t, test.Want, v)
})
}
}
func testCompareQuery(t *testing.T, want *Query, value any) {
t.Helper()
test, ok := value.(*Query)
if !ok {
t.Fatalf("expected data to be a %T, got %T", want, value)
return
}
if test.Type != want.Type {
t.Errorf("expected type %q, got %q", want.Type, test.Type)
}
if !testAlmostEqual(test.Latitude, want.Latitude) {
t.Errorf("expected latitude %f, got %f", want.Latitude, test.Latitude)
}
if !testAlmostEqual(test.Longitude, want.Longitude) {
t.Errorf("expected longitude %f, got %f", want.Longitude, test.Longitude)
}
if !testAlmostEqual(test.Radius, want.Radius) {
t.Errorf("expected radius %f, got %f", want.Radius, test.Radius)
}
}