2021-12-24 02:20:25 -05:00
|
|
|
package gokwallet
|
2021-12-28 02:50:54 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestWallet tests all functions of a Wallet.
|
|
|
|
func TestWallet(t *testing.T) {
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var b bool
|
|
|
|
var conns []string
|
|
|
|
var folders []string
|
2021-12-28 05:48:08 -05:00
|
|
|
var wallets []string
|
2021-12-28 02:50:54 -05:00
|
|
|
var r *RecurseOpts = DefaultRecurseOpts
|
|
|
|
var wm *WalletManager
|
2021-12-28 05:48:08 -05:00
|
|
|
var wm2 *WalletManager
|
2021-12-28 02:50:54 -05:00
|
|
|
var w *Wallet
|
|
|
|
var w2 *Wallet
|
|
|
|
|
|
|
|
r.AllWalletItems = true
|
|
|
|
|
|
|
|
if wm, err = NewWalletManager(r, appIdTest); err != nil {
|
|
|
|
t.Fatalf("failed to get WalletManager '%v' for TestWallet: %v", appIdTest, err)
|
|
|
|
}
|
|
|
|
defer wm.Close()
|
|
|
|
|
2021-12-28 05:48:08 -05:00
|
|
|
if wm2, err = NewWalletManager(r, appIdTestAlt); err != nil {
|
|
|
|
t.Fatalf("failed to get WalletManager '%v' for TestWallet: %v", appIdTest, err)
|
|
|
|
}
|
|
|
|
defer wm2.Close()
|
|
|
|
|
2021-12-28 02:50:54 -05:00
|
|
|
if w, err = NewWallet(wm, walletTest.String(), r); err != nil {
|
|
|
|
t.Fatalf("failed to get Wallet '%v:%v' for TestWallet: %v", appIdTest, walletTest.String(), err)
|
|
|
|
}
|
2021-12-28 05:48:08 -05:00
|
|
|
defer w.Delete()
|
2021-12-28 02:50:54 -05:00
|
|
|
defer w.Disconnect()
|
|
|
|
|
|
|
|
// We test Disconnect above but we also need to test explicit disconnect by application name.
|
2021-12-28 05:48:08 -05:00
|
|
|
if w2, err = NewWallet(wm2, walletTestAlt.String(), r); err != nil {
|
|
|
|
t.Fatalf("failed to get Wallet '%v:%v' for TestWallet: %v", appIdTestAlt, walletTestAlt.String(), err)
|
|
|
|
}
|
|
|
|
defer w2.Delete()
|
|
|
|
|
|
|
|
if wallets, err = wm.WalletNames(); err != nil {
|
|
|
|
t.Errorf("failure when getting wallet names for '%v': %v", appIdTest, err)
|
|
|
|
} else {
|
|
|
|
t.Logf("wallet names found via %v: %#v", appIdTest, wallets)
|
|
|
|
}
|
|
|
|
|
|
|
|
if w2, err = NewWallet(wm, walletTestAlt.String(), r); err != nil {
|
|
|
|
t.Errorf("could not open '%v' in '%v': %v", walletTestAlt.String(), appIdTest, err)
|
2021-12-28 02:50:54 -05:00
|
|
|
}
|
2021-12-28 05:48:08 -05:00
|
|
|
if err = w2.DisconnectApplication(appIdTestAlt); err != nil {
|
2021-12-28 02:50:54 -05:00
|
|
|
t.Errorf(
|
2021-12-28 05:48:08 -05:00
|
|
|
"failed to execute DisconnectApplication for '%v:%v' successfully: %v", appIdTestAlt, walletTestAlt.String(), err,
|
2021-12-28 02:50:54 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = w.ChangePassword(); err != nil {
|
|
|
|
t.Errorf("failed to change password for wallet '%v:%v': %v", appIdTest, walletTest.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conns, err = w.Connections(); err != nil {
|
|
|
|
t.Errorf("failed to get Connections for '%v:%v': %v", appIdTest, walletTest.String(), err)
|
|
|
|
} else {
|
|
|
|
if conns == nil || len(conns) == 0 {
|
|
|
|
t.Errorf("failed to get at least one connection for '%v:%v'. Connections: %#v", appIdTest, walletTest.String(), conns)
|
|
|
|
} else {
|
|
|
|
t.Logf("Connections for '%v:%v': %#v", appIdTest, walletTest.String(), conns)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = w.CreateFolder(folderTest.String()); err != nil {
|
|
|
|
t.Errorf("error when creating folder '%v:%v:%v': %v", appIdTest, walletTest.String(), folderTest.String(), err)
|
|
|
|
} else {
|
|
|
|
t.Logf("created folder '%v:%v:%v'", appIdTest, walletTest.String(), folderTest.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if b, err = w.FolderExists(folderTest.String()); err != nil {
|
|
|
|
t.Errorf(
|
|
|
|
"error when running FolderExists for '%v:%v:%v': %v", appIdTest, walletTest.String(), folderTest.String(), err,
|
|
|
|
)
|
|
|
|
} else if !b {
|
|
|
|
t.Errorf(
|
|
|
|
"did not detecting existing folder '%v:%v:%v' in FolderExists", appIdTest, walletTest.String(), folderTest.String(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if b, err = w.HasFolder(folderTest.String()); err != nil {
|
|
|
|
t.Errorf(
|
|
|
|
"error when running HasFolder for '%v:%v:%v': %v", appIdTest, walletTest.String(), folderTest.String(), err,
|
|
|
|
)
|
|
|
|
} else if !b {
|
|
|
|
t.Errorf(
|
|
|
|
"did not detecting existing folder '%v:%v:%v' in HasFolder", appIdTest, walletTest.String(), folderTest.String(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if folders, err = w.ListFolders(); err != nil {
|
|
|
|
t.Errorf("error when running ListFolders for wallet '%v:%v': %v", appIdTest, walletTest.String(), err)
|
|
|
|
} else {
|
2021-12-28 05:48:08 -05:00
|
|
|
t.Logf("ListFolders returned for wallet '%v:%v': %#v", appIdTest, walletTest.String(), folders)
|
2021-12-28 02:50:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = w.RemoveFolder(folderTest.String()); err != nil {
|
|
|
|
t.Errorf("failed running RemoveFolder in Wallet for '%v:%v:%v': %v", appIdTest, walletTest.String(), folderTest.String(), err)
|
|
|
|
}
|
|
|
|
}
|