gokwallet/utils_test.go

63 lines
1.2 KiB
Go
Raw Permalink Normal View History

package gokwallet
2021-12-25 02:54:18 -05:00
import (
"testing"
)
2021-12-28 02:50:54 -05:00
func getTestEnv(t *testing.T) (e *testEnv, err error) {
2021-12-25 02:54:18 -05:00
2021-12-28 02:50:54 -05:00
e = &testEnv{
wm: nil,
w: nil,
f: nil,
r: DefaultRecurseOpts,
}
2021-12-25 02:54:18 -05:00
2021-12-28 02:50:54 -05:00
e.r.AllWalletItems = true
2021-12-25 02:54:18 -05:00
2021-12-28 02:50:54 -05:00
if e.wm, err = NewWalletManager(e.r, appIdTest); err != nil {
2021-12-25 02:54:18 -05:00
t.Errorf("failure when getting WalletManager '%v': %v", appIdTest, err)
return
}
2021-12-28 02:50:54 -05:00
if e.w, err = NewWallet(e.wm, walletTest.String(), e.r); err != nil {
2021-12-25 02:54:18 -05:00
t.Errorf("failure when getting Wallet '%v:%v': %v", appIdTest, walletTest.String(), err)
return
}
2021-12-28 02:50:54 -05:00
if e.f, err = NewFolder(e.w, folderTest.String(), e.r); err != nil {
2021-12-25 02:54:18 -05:00
t.Errorf("failure when getting Folder '%v:%v:%v': %v", appIdTest, walletTest.String(), folderTest.String(), err)
return
}
return
}
2021-12-28 02:50:54 -05:00
// cleanup closes connections and deletes created folders/wallets in a testEnv.
func (e *testEnv) cleanup(t *testing.T) (err error) {
var errs []error = make([]error, 0)
if err = e.f.Delete(); err != nil {
errs = append(errs, err)
err = nil
}
if err = e.w.Delete(); err != nil {
errs = append(errs, err)
err = nil
}
if err = e.wm.Close(); err != nil {
errs = append(errs, err)
err = nil
}
if errs != nil && len(errs) > 0 {
err = NewErrors(errs...)
return
}
return
}