Only assign rovers to accounts if given an account

This commit is contained in:
Marc Di Luzio 2020-07-24 22:54:06 +01:00
parent 57621d169a
commit a93ce97b0b
3 changed files with 27 additions and 21 deletions

View file

@ -11,7 +11,7 @@ import (
func TestCommand_Toggle(t *testing.T) {
w := NewWorld(8)
a, err := w.SpawnRover("tmp")
a, err := w.SpawnRover("")
assert.NoError(t, err)
r, err := w.GetRover(a)
@ -37,7 +37,7 @@ func TestCommand_Toggle(t *testing.T) {
func TestCommand_Turn(t *testing.T) {
w := NewWorld(8)
a, err := w.SpawnRover("tmp")
a, err := w.SpawnRover("")
assert.NoError(t, err)
err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_turn, Bearing: roveapi.Bearing_NorthWest})
@ -51,7 +51,7 @@ func TestCommand_Turn(t *testing.T) {
func TestCommand_Stash(t *testing.T) {
w := NewWorld(8)
name, err := w.SpawnRover("tmp")
name, err := w.SpawnRover("")
assert.NoError(t, err)
info, err := w.GetRover(name)
@ -79,7 +79,7 @@ func TestCommand_Stash(t *testing.T) {
func TestCommand_Repair(t *testing.T) {
w := NewWorld(8)
name, err := w.SpawnRover("tmp")
name, err := w.SpawnRover("")
assert.NoError(t, err)
info, err := w.GetRover(name)
@ -119,7 +119,7 @@ func TestCommand_Repair(t *testing.T) {
func TestCommand_Broadcast(t *testing.T) {
w := NewWorld(8)
name, err := w.SpawnRover("tmp")
name, err := w.SpawnRover("")
assert.NoError(t, err)
// Enqueue the broadcast and tick
@ -134,7 +134,7 @@ func TestCommand_Broadcast(t *testing.T) {
func TestCommand_Salvage(t *testing.T) {
w := NewWorld(8)
name, err := w.SpawnRover("tmp")
name, err := w.SpawnRover("")
assert.NoError(t, err)
info, err := w.GetRover(name)
@ -213,7 +213,7 @@ func TestCommand_Transfer(t *testing.T) {
func TestCommand_Invalid(t *testing.T) {
w := NewWorld(8)
name, err := w.SpawnRover("tmp")
name, err := w.SpawnRover("")
assert.NoError(t, err)
err = w.Enqueue(name, &roveapi.Command{Command: roveapi.CommandType_none})

View file

@ -97,7 +97,13 @@ func (w *World) SpawnRover(account string) (string, error) {
// Append the rover to the list
w.Rovers[rover.Name] = rover
return rover.Name, w.Accountant.AssignData(account, "rover", rover.Name)
var err error
// Only assign if we've been given an account
if len(account) > 0 {
err = w.Accountant.AssignData(account, "rover", rover.Name)
}
return rover.Name, err
}
// GetRover gets a specific rover by name

View file

@ -18,9 +18,9 @@ func TestNewWorld(t *testing.T) {
func TestWorld_CreateRover(t *testing.T) {
world := NewWorld(8)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
b, err := world.SpawnRover("tmp")
b, err := world.SpawnRover("")
assert.NoError(t, err)
// Basic duplicate check
@ -33,7 +33,7 @@ func TestWorld_CreateRover(t *testing.T) {
func TestWorld_GetRover(t *testing.T) {
world := NewWorld(4)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
rover, err := world.GetRover(a)
@ -44,9 +44,9 @@ func TestWorld_GetRover(t *testing.T) {
func TestWorld_DestroyRover(t *testing.T) {
world := NewWorld(1)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
b, err := world.SpawnRover("tmp")
b, err := world.SpawnRover("")
assert.NoError(t, err)
err = world.DestroyRover(a)
@ -62,7 +62,7 @@ func TestWorld_DestroyRover(t *testing.T) {
func TestWorld_GetSetMovePosition(t *testing.T) {
world := NewWorld(4)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
pos := maths.Vector{
@ -97,9 +97,9 @@ func TestWorld_GetSetMovePosition(t *testing.T) {
func TestWorld_RadarFromRover(t *testing.T) {
// Create world that should have visible walls on the radar
world := NewWorld(2)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
b, err := world.SpawnRover("tmp")
b, err := world.SpawnRover("")
assert.NoError(t, err)
// Warp the rovers into position
@ -130,7 +130,7 @@ func TestWorld_RadarFromRover(t *testing.T) {
func TestWorld_RoverDamage(t *testing.T) {
world := NewWorld(2)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
pos := maths.Vector{
@ -160,7 +160,7 @@ func TestWorld_RoverDamage(t *testing.T) {
func TestWorld_Daytime(t *testing.T) {
world := NewWorld(1)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
// Remove rover charge
@ -199,10 +199,10 @@ func TestWorld_Daytime(t *testing.T) {
func TestWorld_Broadcast(t *testing.T) {
world := NewWorld(8)
a, err := world.SpawnRover("tmp")
a, err := world.SpawnRover("")
assert.NoError(t, err)
b, err := world.SpawnRover("tmp")
b, err := world.SpawnRover("")
assert.NoError(t, err)
// Warp rovers near to eachother
@ -265,7 +265,7 @@ func TestWorld_Sailing(t *testing.T) {
world.Tick() // One initial tick to set the wind direction the first time
world.Wind = roveapi.Bearing_North // Set the wind direction to north
name, err := world.SpawnRover("tmp")
name, err := world.SpawnRover("")
assert.NoError(t, err)
// Warp the rover to 0,0 after clearing it