mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
swarm/storage: Comment test functions and improve error handling
This commit is contained in:
parent
4e6ffd64f5
commit
51adbcde39
6 changed files with 21 additions and 8 deletions
|
|
@ -205,6 +205,8 @@ func initMockDbStore(t *testing.T, mockStore *mock.NodeStore) *DbStore {
|
|||
return m
|
||||
}
|
||||
|
||||
// testMockDbStore runs the same tests as testDbStore but with mock store configured.
|
||||
// It also verifies if mock global store is storing the chunk data.
|
||||
func testMockDbStore(l int64, branches int64, t *testing.T) {
|
||||
globalStore := mem.NewGlobalStore()
|
||||
addr := common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func (s *GlobalStore) NewNodeStore(addr common.Address) *mock.NodeStore {
|
|||
func (s *GlobalStore) Get(addr common.Address, key []byte) (data []byte, err error) {
|
||||
has, err := s.db.Has(nodeDBKey(addr, key), nil)
|
||||
if err != nil {
|
||||
has = false
|
||||
return nil, mock.ErrNotFound
|
||||
}
|
||||
if !has {
|
||||
return nil, mock.ErrNotFound
|
||||
|
|
@ -102,10 +102,10 @@ func (s *GlobalStore) Import(r io.Reader) (n int, err error) {
|
|||
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/swarm/storage/mock/test"
|
||||
)
|
||||
|
||||
// TestDBStore is running a test.MockStore tests
|
||||
// using test.MockStore function.
|
||||
func TestDBStore(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "mock_"+t.Name())
|
||||
if err != nil {
|
||||
|
|
@ -40,6 +42,8 @@ func TestDBStore(t *testing.T) {
|
|||
test.MockStore(t, store, 100)
|
||||
}
|
||||
|
||||
// TestImportExport is running a test.ImportExport tests
|
||||
// using test.MockStore function.
|
||||
func TestImportExport(t *testing.T) {
|
||||
dir1, err := ioutil.TempDir("", "mock_"+t.Name()+"_exporter")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -102,10 +102,10 @@ func (s *GlobalStore) Import(r io.Reader) (n int, err error) {
|
|||
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ func (s *GlobalStore) Import(r io.Reader) (n int, err error) {
|
|||
}
|
||||
|
||||
// Export writes to a writer a tar archive with all chunk data from
|
||||
// the store. It returns the number fo chunks exported and an error.
|
||||
// the store. It returns the number of chunks exported and an error.
|
||||
func (s *GlobalStore) Export(w io.Writer) (n int, err error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
|
|
|||
|
|
@ -22,10 +22,15 @@ import (
|
|||
"github.com/ethereum/go-ethereum/swarm/storage/mock/test"
|
||||
)
|
||||
|
||||
// TestDBStore is running test for a GlobalStore
|
||||
// using test.MockStore function.
|
||||
func TestMemStore(t *testing.T) {
|
||||
test.MockStore(t, NewGlobalStore(), 100)
|
||||
}
|
||||
|
||||
// TestImportExport is running tests for importing and
|
||||
// exporting data between two GlobalStores
|
||||
// using test.ImportExport function.
|
||||
func TestImportExport(t *testing.T) {
|
||||
test.ImportExport(t, NewGlobalStore(), NewGlobalStore(), 100)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/swarm/storage/mock/test"
|
||||
)
|
||||
|
||||
// TestDBStore is running test for a GlobalStore
|
||||
// using test.MockStore function.
|
||||
func TestRPCStore(t *testing.T) {
|
||||
serverStore := mem.NewGlobalStore()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue