Add /rover command to get rover info

This commit is contained in:
Marc Di Luzio 2020-06-05 22:23:01 +01:00
parent e2e0256d44
commit 9d57f48f98
6 changed files with 145 additions and 9 deletions

View file

@ -107,7 +107,6 @@ type Command struct {
// API: /radar POST
// Radar queries the current radar for the user
// Commands issues a set of commands from the user
func (s Server) Radar(d RadarData) (r RadarResponse, err error) {
err = s.POST("radar", d, &r)
return
@ -126,3 +125,26 @@ type RadarResponse struct {
// The set of positions for nearby rovers
Rovers []game.Vector `json:"rovers"`
}
// ================
// API: /rover POST
// Rover queries the current state of the rover
func (s Server) Rover(d RoverData) (r RoverResponse, err error) {
err = s.POST("rover", d, &r)
return
}
// RoverData describes the input data to request rover status
type RoverData struct {
Id string `json:"id"`
}
// RoverResponse includes information about the rover in question
type RoverResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
// The set of positions for nearby rovers
Position game.Vector `json:"position"`
}

View file

@ -109,3 +109,27 @@ func TestServer_Radar(t *testing.T) {
assert.NoError(t, err)
assert.True(t, r3.Success)
}
func TestServer_Rover(t *testing.T) {
d1 := RegisterData{
Name: uuid.New().String(),
}
r1, err := server.Register(d1)
assert.NoError(t, err)
assert.True(t, r1.Success)
assert.NotZero(t, len(r1.Id))
s := SpawnData{
Id: r1.Id,
}
r2, err := server.Spawn(s)
assert.NoError(t, err)
assert.True(t, r2.Success)
r := RoverData{
Id: r1.Id,
}
r3, err := server.Rover(r)
assert.NoError(t, err)
assert.True(t, r3.Success)
}