swarm/storage: Get all chunk references for a given file (#19002)

(cherry picked from commit 3eff652a7b)
This commit is contained in:
holisticode
2019-02-06 06:16:43 -05:00
committed by Rafael Matias
parent 607a1968e6
commit 034f65e9e8
2 changed files with 76 additions and 0 deletions

View File

@@ -173,3 +173,39 @@ func testFileStoreCapacity(toEncrypt bool, t *testing.T) {
t.Fatalf("Comparison error after clearing memStore.")
}
}
// 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()
if err != nil {
t.Fatalf("init dbStore failed: %v", err)
}
db := tdb.LDBStore
memStore := NewMemStore(NewDefaultStoreParams(), db)
localStore := &LocalStore{
memStore: memStore,
DbStore: db,
}
fileStore := NewFileStore(localStore, NewFileStoreParams())
checkRefs := func(dataSize int, expectedLen int) {
slice := testutil.RandomBytes(1, dataSize)
addrs, err := fileStore.GetAllReferences(context.Background(), bytes.NewReader(slice), false)
if err != nil {
t.Fatal(err)
}
if len(addrs) != expectedLen {
t.Fatalf("Expected reference array length to be %d, but is %d", expectedLen, len(addrs))
}
}
// testRuns[i] and expectedLen[i] are dataSize and expected length respectively
testRuns := []int{1024, 8192, 16000, 30000, 1000000}
expectedLens := []int{1, 3, 5, 9, 248}
for i, r := range testRuns {
checkRefs(r, expectedLens[i])
}
}