Add /spawn command to let an account spawn it's primary instance
This commit is contained in:
parent
0a1f7a37c4
commit
50c970fea2
6 changed files with 151 additions and 11 deletions
|
@ -3,6 +3,8 @@ package accounts
|
|||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestNewAccountant(t *testing.T) {
|
||||
|
@ -64,7 +66,7 @@ func TestAccountant_LoadSave(t *testing.T) {
|
|||
|
||||
if len(accountant.data.Accounts) != 1 {
|
||||
t.Error("No new account made")
|
||||
} else if accountant.data.Accounts[0].Name != name {
|
||||
} else if accountant.data.Accounts[a.Id].Name != name {
|
||||
t.Error("New account created with wrong name")
|
||||
}
|
||||
|
||||
|
@ -87,7 +89,30 @@ func TestAccountant_LoadSave(t *testing.T) {
|
|||
// Verify we have the same account again
|
||||
if len(accountant.data.Accounts) != 1 {
|
||||
t.Error("No account after load")
|
||||
} else if accountant.data.Accounts[0].Name != name {
|
||||
} else if accountant.data.Accounts[a.Id].Name != name {
|
||||
t.Error("New account created with wrong name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountant_AssignPrimary(t *testing.T) {
|
||||
accountant := NewAccountant(os.TempDir())
|
||||
if len(accountant.data.Accounts) != 0 {
|
||||
t.Error("New accountant created with non-zero account number")
|
||||
}
|
||||
|
||||
name := "one"
|
||||
a := Account{Name: name}
|
||||
a, err := accountant.RegisterAccount(a)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
inst := uuid.New()
|
||||
|
||||
err = accountant.AssignPrimary(a.Id, inst)
|
||||
if err != nil {
|
||||
t.Error("Failed to set primary for created account")
|
||||
} else if accountant.data.Accounts[a.Id].Primary != inst {
|
||||
t.Error("Primary for assigned account is incorrect")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue