Skip to content

Commit 9807984

Browse files
authored
Clean up VECTOR implementation (#687)
1 parent cf5b152 commit 9807984

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

pkg/composer/vector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (c *Composer) ComposeVectorResponse(response brevity.VectorResponse) Natura
5050
distance,
5151
),
5252
Speech: fmt.Sprintf(
53-
"%s, vector to %s, %s %d",
53+
"%s, vector to %s, %s, %d",
5454
callsign,
5555
response.Location,
5656
pronounceBearing(response.Vector.Bearing()),

pkg/controller/vector.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (c *Controller) HandleVector(ctx context.Context, request *brevity.VectorRe
5050
response.Status = targetLocation != nil
5151

5252
if response.Status {
53+
if len(targetLocation.Names) > 0 {
54+
response.Location = targetLocation.Names[0]
55+
}
56+
5357
origin := trackfile.LastKnown().Point
5458
target := targetLocation.Point()
5559
declination := c.scope.Declination(origin)

pkg/controller/vector_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ func TestHandleVector_HappyPath(t *testing.T) {
7474
assert.Nil(t, resp.BRA)
7575
}
7676

77+
func TestHandleVector_UsesCanonicalConfiguredLocationName(t *testing.T) {
78+
t.Parallel()
79+
locs := []locations.Location{
80+
{Names: []string{"home plate", "base"}, Longitude: 30.0, Latitude: 40.0},
81+
}
82+
h := newControllerTestHarness(t, locs)
83+
h.insertAircraft(t, "Eagle 1 Reaper", acmiF15C, coalitions.Blue, orb.Point{30.1, 40.1})
84+
85+
h.ctrl.HandleVector(h.ctx, &brevity.VectorRequest{
86+
Callsign: "eagle 1",
87+
Location: "base",
88+
})
89+
got := h.expectResponse(t)
90+
resp, ok := got.(brevity.VectorResponse)
91+
require.True(t, ok)
92+
assert.Equal(t, "home plate", resp.Location)
93+
assert.True(t, resp.Contact)
94+
assert.True(t, resp.Status)
95+
require.NotNil(t, resp.Vector)
96+
assert.Nil(t, resp.BRA)
97+
}
98+
7799
func TestHandleVector_Tanker_NoCompatibleTanker(t *testing.T) {
78100
t.Parallel()
79101
h := newControllerTestHarness(t, nil)

0 commit comments

Comments
 (0)