github.com/ZuluSpl0it/Sia@v1.3.7/modules/wallet/database_test.go (about)

     1  package wallet
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/NebulousLabs/Sia/build"
     9  	"github.com/NebulousLabs/Sia/modules"
    10  
    11  	"github.com/coreos/bbolt"
    12  )
    13  
    14  // TestDBOpen tests the wallet.openDB method.
    15  func TestDBOpen(t *testing.T) {
    16  	if testing.Short() {
    17  		t.SkipNow()
    18  	}
    19  
    20  	w := new(Wallet)
    21  	err := w.openDB("")
    22  	if err == nil {
    23  		t.Fatal("expected error, got nil")
    24  	}
    25  
    26  	testdir := build.TempDir(modules.WalletDir, "TestDBOpen")
    27  	os.MkdirAll(testdir, 0700)
    28  	err = w.openDB(filepath.Join(testdir, dbFile))
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  	w.db.View(func(tx *bolt.Tx) error {
    33  		for _, b := range dbBuckets {
    34  			if tx.Bucket(b) == nil {
    35  				t.Error("bucket", string(b), "does not exist")
    36  			}
    37  		}
    38  		return nil
    39  	})
    40  	w.db.Close()
    41  }