Add the /commands path to handle a set of commands

Entirely synchronous now but allows for the "move" command
This commit is contained in:
Marc Di Luzio 2020-06-03 18:40:19 +01:00
parent e5d5d123a6
commit e2857d7506
5 changed files with 169 additions and 19 deletions

View file

@ -71,3 +71,12 @@ func (a *Accountant) AssignPrimary(account uuid.UUID, instance uuid.UUID) error
return nil
}
// GetPrimary gets the primary instance for the account
func (a *Accountant) GetPrimary(account uuid.UUID) (uuid.UUID, error) {
// Find the account matching the ID
if this, ok := a.Accounts[account]; ok {
return this.Primary, nil
}
return uuid.UUID{}, fmt.Errorf("no account found for id: %s", account)
}

View file

@ -48,7 +48,7 @@ func TestAccountant_RegisterAccount(t *testing.T) {
}
}
func TestAccountant_AssignPrimary(t *testing.T) {
func TestAccountant_AssignGetPrimary(t *testing.T) {
accountant := NewAccountant()
if len(accountant.Accounts) != 0 {
t.Error("New accountant created with non-zero account number")
@ -67,5 +67,9 @@ func TestAccountant_AssignPrimary(t *testing.T) {
t.Error("Failed to set primary for created account")
} else if accountant.Accounts[a.Id].Primary != inst {
t.Error("Primary for assigned account is incorrect")
} else if id, err := accountant.GetPrimary(a.Id); err != nil {
t.Error("Failed to get primary for account")
} else if id != inst {
t.Error("Fetched primary is incorrect for account")
}
}