-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet_funcs_test.go
108 lines (92 loc) · 3.65 KB
/
wallet_funcs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package gokwallet
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
var wallets []string
var r *RecurseOpts = DefaultRecurseOpts
var wm *WalletManager
var wm2 *WalletManager
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()
if wm2, err = NewWalletManager(r, appIdTestAlt); err != nil {
t.Fatalf("failed to get WalletManager '%v' for TestWallet: %v", appIdTest, err)
}
defer wm2.Close()
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)
}
defer w.Delete()
defer w.Disconnect()
// We test Disconnect above but we also need to test explicit disconnect by application name.
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)
}
if err = w2.DisconnectApplication(appIdTestAlt); err != nil {
t.Errorf(
"failed to execute DisconnectApplication for '%v:%v' successfully: %v", appIdTestAlt, walletTestAlt.String(), err,
)
}
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 {
t.Logf("ListFolders returned for wallet '%v:%v': %#v", appIdTest, walletTest.String(), folders)
}
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)
}
}