Implement Accounts for vaultWallet

This commit is contained in:
chris-j-h 2019-07-08 13:08:28 +01:00
parent 9aa1427846
commit 98ff8b9a19
2 changed files with 24 additions and 1 deletions

View File

@ -16,6 +16,7 @@ type vaultWallet struct {
url accounts.URL
vault vaultService
updateFeed *event.Feed
accounts []accounts.Account
}
// vault related behaviour that will be specific to each vault type
@ -62,7 +63,10 @@ func (w vaultWallet) Close() error {
}
func (w vaultWallet) Accounts() []accounts.Account {
panic("implement me")
cpy := make([]accounts.Account, len(w.accounts))
copy(cpy, w.accounts)
return cpy
}
func (w vaultWallet) Contains(account accounts.Account) bool {

View File

@ -550,3 +550,22 @@ func TestVaultWallet_Close_Hashicorp_ReturnsStateToBeforeOpen(t *testing.T) {
t.Fatalf("cmp does not consider the two wallets equal after one was opened and closed:\n%v", diff)
}
}
func TestVaultWallet_Accounts_ReturnsCopyOfAccountsInWallet(t *testing.T) {
w := vaultWallet{
accounts: []accounts.Account{{URL: accounts.URL{Scheme: "http", Path: "url:1"}}},
}
got := w.Accounts()
if !cmp.Equal(w.accounts, got) {
t.Fatalf("want: %v, got: %v", w.accounts, got)
}
got[0].URL = accounts.URL{Scheme: "http", Path: "changed:1"}
if cmp.Equal(w.accounts, got) {
t.Fatalf("changes to the returned accounts should not change the wallet's record of accounts")
}
}