diff --git a/pkg/rove/command_test.go b/pkg/rove/command_test.go index 0dc2f11..ec9c1b5 100644 --- a/pkg/rove/command_test.go +++ b/pkg/rove/command_test.go @@ -3,6 +3,7 @@ package rove import ( "testing" + "github.com/mdiluz/rove/pkg/maths" "github.com/mdiluz/rove/proto/roveapi" "github.com/stretchr/testify/assert" ) @@ -76,7 +77,43 @@ func TestCommand_Stash(t *testing.T) { } func TestCommand_Repair(t *testing.T) { - // TODO: Test the repair command + w := NewWorld(8) + name, err := w.SpawnRover() + assert.NoError(t, err) + + info, err := w.GetRover(name) + assert.NoError(t, err) + assert.Equal(t, info.MaximumIntegrity, info.Integrity) + + // Put a blocking rock to the north + w.Atlas.SetObject(info.Pos.Added(maths.Vector{X: 0, Y: 1}), Object{Type: roveapi.Object_RockLarge}) + + // Try and move and make sure we're blocked + newpos, err := w.TryMoveRover(name, roveapi.Bearing_North) + assert.NoError(t, err) + assert.Equal(t, info.Pos, newpos) + + // Check we're damaged + info, err = w.GetRover(name) + assert.NoError(t, err) + assert.Equal(t, info.MaximumIntegrity-1, info.Integrity) + + // Stash a repair object + w.Atlas.SetObject(info.Pos, Object{Type: roveapi.Object_RockSmall}) + obj, err := w.RoverStash(name) + assert.NoError(t, err) + assert.Equal(t, roveapi.Object_RockSmall, obj) + + // Enqueue the repair and tick + err = w.Enqueue(name, &roveapi.Command{Command: roveapi.CommandType_repair}) + assert.NoError(t, err) + w.Tick() + + // Check we're repaired + info, err = w.GetRover(name) + assert.NoError(t, err) + assert.Equal(t, info.MaximumIntegrity, info.Integrity) + assert.Equal(t, 0, len(info.Inventory)) } func TestCommand_Broadcast(t *testing.T) {