Huge Instance -> Rover refactor, for clarification
This commit is contained in:
parent
33f25a7414
commit
0fbad15c01
10 changed files with 96 additions and 96 deletions
|
@ -16,8 +16,8 @@ type Account struct {
|
|||
// Id represents a unique ID per account and is set one registered
|
||||
Id uuid.UUID `json:"id"`
|
||||
|
||||
// Primary represents the primary instance that this account owns
|
||||
Primary uuid.UUID `json:"primary"`
|
||||
// Rover represents the rover that this account owns
|
||||
Rover uuid.UUID `json:"rover"`
|
||||
}
|
||||
|
||||
// Represents the accountant data to store
|
||||
|
@ -58,12 +58,12 @@ func (a *Accountant) RegisterAccount(name string) (acc Account, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// AssignPrimary assigns primary ownership of an instance to an account
|
||||
func (a *Accountant) AssignPrimary(account uuid.UUID, instance uuid.UUID) error {
|
||||
// AssignRover assigns rover ownership of an rover to an account
|
||||
func (a *Accountant) AssignRover(account uuid.UUID, rover uuid.UUID) error {
|
||||
|
||||
// Find the account matching the ID
|
||||
if this, ok := a.Accounts[account]; ok {
|
||||
this.Primary = instance
|
||||
this.Rover = rover
|
||||
a.Accounts[account] = this
|
||||
} else {
|
||||
return fmt.Errorf("no account found for id: %s", account)
|
||||
|
@ -72,11 +72,11 @@ 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) {
|
||||
// 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 {
|
||||
return this.Primary, nil
|
||||
return this.Rover, nil
|
||||
}
|
||||
return uuid.UUID{}, fmt.Errorf("no account found for id: %s", account)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func TestAccountant_RegisterAccount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAccountant_AssignGetPrimary(t *testing.T) {
|
||||
func TestAccountant_AssignGetRover(t *testing.T) {
|
||||
accountant := NewAccountant()
|
||||
if len(accountant.Accounts) != 0 {
|
||||
t.Error("New accountant created with non-zero account number")
|
||||
|
@ -62,14 +62,14 @@ func TestAccountant_AssignGetPrimary(t *testing.T) {
|
|||
|
||||
inst := uuid.New()
|
||||
|
||||
err = accountant.AssignPrimary(a.Id, inst)
|
||||
err = accountant.AssignRover(a.Id, inst)
|
||||
if err != nil {
|
||||
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")
|
||||
t.Error("Failed to set rover for created account")
|
||||
} else if accountant.Accounts[a.Id].Rover != inst {
|
||||
t.Error("Rover for assigned account is incorrect")
|
||||
} else if id, err := accountant.GetRover(a.Id); err != nil {
|
||||
t.Error("Failed to get rover for account")
|
||||
} else if id != inst {
|
||||
t.Error("Fetched primary is incorrect for account")
|
||||
t.Error("Fetched rover is incorrect for account")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue