From e242fcc4f7edaedb6852386b533961db4cb89738 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 6 Jun 2020 00:18:41 +0100 Subject: [PATCH] Fix issue with command returning true when no rover was spawned --- cmd/rove/main_test.go | 2 +- pkg/accounts/accounts.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/rove/main_test.go b/cmd/rove/main_test.go index 46e10a8..405d1a8 100644 --- a/cmd/rove/main_test.go +++ b/cmd/rove/main_test.go @@ -41,7 +41,7 @@ func Test_InnerMain(t *testing.T) { assert.NoError(t, InnerMain("register")) // We've not spawned a rover yet so these should fail - // assert.Error(t, InnerMain("command")) // Currently not erroring, needs investigation + assert.Error(t, InnerMain("command")) // Currently not erroring, needs investigation assert.Error(t, InnerMain("radar")) assert.Error(t, InnerMain("rover")) diff --git a/pkg/accounts/accounts.go b/pkg/accounts/accounts.go index a961840..e1f6f12 100644 --- a/pkg/accounts/accounts.go +++ b/pkg/accounts/accounts.go @@ -75,8 +75,11 @@ func (a *Accountant) AssignRover(account uuid.UUID, rover uuid.UUID) error { // GetRover gets the rover rover for the account func (a *Accountant) GetRover(account uuid.UUID) (uuid.UUID, error) { // Find the account matching the ID - if this, ok := a.Accounts[account]; ok { + if this, ok := a.Accounts[account]; !ok { + return uuid.UUID{}, fmt.Errorf("no account found for id: %s", account) + } else if this.Rover == uuid.Nil { + return uuid.UUID{}, fmt.Errorf("no rover spawned for account %s", account) + } else { return this.Rover, nil } - return uuid.UUID{}, fmt.Errorf("no account found for id: %s", account) }