diff options
Diffstat (limited to 'swarm/storage/filestore_test.go')
-rw-r--r-- | swarm/storage/filestore_test.go | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/swarm/storage/filestore_test.go b/swarm/storage/filestore_test.go index 06c4be1d7..fe01eed9a 100644 --- a/swarm/storage/filestore_test.go +++ b/swarm/storage/filestore_test.go @@ -22,8 +22,10 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "testing" + "github.com/ethereum/go-ethereum/swarm/storage/localstore" "github.com/ethereum/go-ethereum/swarm/testutil" ) @@ -35,21 +37,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") slice := testutil.RandomBytes(1, testDataSize) ctx := context.TODO() @@ -76,9 +75,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,17 +102,17 @@ 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) } + defer localStore.Close() + fileStore := NewFileStore(localStore, NewFileStoreParams()) slice := testutil.RandomBytes(1, testDataSize) ctx := context.TODO() @@ -141,10 +139,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,17 +171,17 @@ 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) } + defer localStore.Close() + fileStore := NewFileStore(localStore, NewFileStoreParams()) // testRuns[i] and expectedLen[i] are dataSize and expected length respectively |