diff options
Diffstat (limited to 'swarm/storage/filestore_test.go')
-rw-r--r-- | swarm/storage/filestore_test.go | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/swarm/storage/filestore_test.go b/swarm/storage/filestore_test.go index 06c4be1d7..d0a167a24 100644 --- a/swarm/storage/filestore_test.go +++ b/swarm/storage/filestore_test.go @@ -22,8 +22,11 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "testing" + "github.com/ethereum/go-ethereum/swarm/chunk" + "github.com/ethereum/go-ethereum/swarm/storage/localstore" "github.com/ethereum/go-ethereum/swarm/testutil" ) @@ -35,21 +38,18 @@ func TestFileStorerandom(t *testing.T) { } func testFileStoreRandom(toEncrypt bool, t *testing.T) { - tdb, cleanup, err := newTestDbStore(false, false) - defer cleanup() + dir, err := ioutil.TempDir("", "swarm-storage-") if err != nil { - t.Fatalf("init dbStore failed: %v", err) + t.Fatal(err) } - db := tdb.LDBStore - db.setCapacity(50000) - memStore := NewMemStore(NewDefaultStoreParams(), db) - localStore := &LocalStore{ - memStore: memStore, - DbStore: db, + defer os.RemoveAll(dir) + localStore, err := localstore.New(dir, make([]byte, 32), nil) + if err != nil { + t.Fatal(err) } + defer localStore.Close() - fileStore := NewFileStore(localStore, NewFileStoreParams()) - defer os.RemoveAll("/tmp/bzz") + fileStore := NewFileStore(localStore, NewFileStoreParams(), chunk.NewTags()) slice := testutil.RandomBytes(1, testDataSize) ctx := context.TODO() @@ -76,9 +76,8 @@ func testFileStoreRandom(toEncrypt bool, t *testing.T) { if !bytes.Equal(slice, resultSlice) { t.Fatalf("Comparison error.") } - ioutil.WriteFile("/tmp/slice.bzz.16M", slice, 0666) - ioutil.WriteFile("/tmp/result.bzz.16M", resultSlice, 0666) - localStore.memStore = NewMemStore(NewDefaultStoreParams(), db) + ioutil.WriteFile(filepath.Join(dir, "slice.bzz.16M"), slice, 0666) + ioutil.WriteFile(filepath.Join(dir, "result.bzz.16M"), resultSlice, 0666) resultReader, isEncrypted = fileStore.Retrieve(context.TODO(), key) if isEncrypted != toEncrypt { t.Fatalf("isEncrypted expected %v got %v", toEncrypt, isEncrypted) @@ -104,18 +103,18 @@ func TestFileStoreCapacity(t *testing.T) { } func testFileStoreCapacity(toEncrypt bool, t *testing.T) { - tdb, cleanup, err := newTestDbStore(false, false) - defer cleanup() + dir, err := ioutil.TempDir("", "swarm-storage-") if err != nil { - t.Fatalf("init dbStore failed: %v", err) + t.Fatal(err) } - db := tdb.LDBStore - memStore := NewMemStore(NewDefaultStoreParams(), db) - localStore := &LocalStore{ - memStore: memStore, - DbStore: db, + defer os.RemoveAll(dir) + localStore, err := localstore.New(dir, make([]byte, 32), nil) + if err != nil { + t.Fatal(err) } - fileStore := NewFileStore(localStore, NewFileStoreParams()) + defer localStore.Close() + + fileStore := NewFileStore(localStore, NewFileStoreParams(), chunk.NewTags()) slice := testutil.RandomBytes(1, testDataSize) ctx := context.TODO() key, wait, err := fileStore.Store(ctx, bytes.NewReader(slice), testDataSize, toEncrypt) @@ -141,10 +140,6 @@ func testFileStoreCapacity(toEncrypt bool, t *testing.T) { if !bytes.Equal(slice, resultSlice) { t.Fatalf("Comparison error.") } - // Clear memStore - memStore.setCapacity(0) - // check whether it is, indeed, empty - fileStore.ChunkStore = memStore resultReader, isEncrypted = fileStore.Retrieve(context.TODO(), key) if isEncrypted != toEncrypt { t.Fatalf("isEncrypted expected %v got %v", toEncrypt, isEncrypted) @@ -177,18 +172,18 @@ func testFileStoreCapacity(toEncrypt bool, t *testing.T) { // TestGetAllReferences only tests that GetAllReferences returns an expected // number of references for a given file func TestGetAllReferences(t *testing.T) { - tdb, cleanup, err := newTestDbStore(false, false) - defer cleanup() + dir, err := ioutil.TempDir("", "swarm-storage-") if err != nil { - t.Fatalf("init dbStore failed: %v", err) + t.Fatal(err) } - db := tdb.LDBStore - memStore := NewMemStore(NewDefaultStoreParams(), db) - localStore := &LocalStore{ - memStore: memStore, - DbStore: db, + defer os.RemoveAll(dir) + localStore, err := localstore.New(dir, make([]byte, 32), nil) + if err != nil { + t.Fatal(err) } - fileStore := NewFileStore(localStore, NewFileStoreParams()) + defer localStore.Close() + + fileStore := NewFileStore(localStore, NewFileStoreParams(), chunk.NewTags()) // testRuns[i] and expectedLen[i] are dataSize and expected length respectively testRuns := []int{1024, 8192, 16000, 30000, 1000000} |