X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/908261de15c98553a4200f01aff1f26ef57c8fb8..fd717a88835be62ae1b5c4b1ecd74c21cab0e744:/services/keepstore/handlers_with_generic_volume_test.go diff --git a/services/keepstore/handlers_with_generic_volume_test.go b/services/keepstore/handlers_with_generic_volume_test.go index c5349d399c..181e651d3b 100644 --- a/services/keepstore/handlers_with_generic_volume_test.go +++ b/services/keepstore/handlers_with_generic_volume_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" ) // A TestableVolumeManagerFactory creates a volume manager with at least two TestableVolume instances. @@ -45,12 +46,13 @@ func testGetBlock(t TB, factory TestableVolumeManagerFactory, testHash string, t testableVolumes[1].PutRaw(testHash, testBlock) // Get should pass - buf, err := GetBlock(testHash) + buf := make([]byte, len(testBlock)) + n, err := GetBlock(context.Background(), testHash, buf, nil) if err != nil { t.Fatalf("Error while getting block %s", err) } - if bytes.Compare(buf, testBlock) != 0 { - t.Errorf("Put succeeded but Get returned %+v, expected %+v", buf, testBlock) + if bytes.Compare(buf[:n], testBlock) != 0 { + t.Errorf("Put succeeded but Get returned %+v, expected %+v", buf[:n], testBlock) } } @@ -64,9 +66,10 @@ func testPutRawBadDataGetBlock(t TB, factory TestableVolumeManagerFactory, testableVolumes[1].PutRaw(testHash, badData) // Get should fail - _, err := GetBlock(testHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(context.Background(), testHash, buf, nil) if err == nil { - t.Fatalf("Expected error while getting corrupt block %v", testHash) + t.Fatalf("Got %+q, expected error while getting corrupt block %v", buf[:size], testHash) } } @@ -75,21 +78,22 @@ func testPutBlock(t TB, factory TestableVolumeManagerFactory, testHash string, t setupHandlersWithGenericVolumeTest(t, factory) // PutBlock - if _, err := PutBlock(testBlock, testHash); err != nil { + if _, err := PutBlock(context.Background(), testBlock, testHash); err != nil { t.Fatalf("Error during PutBlock: %s", err) } // Check that PutBlock succeeds again even after CompareAndTouch - if _, err := PutBlock(testBlock, testHash); err != nil { + if _, err := PutBlock(context.Background(), testBlock, testHash); err != nil { t.Fatalf("Error during PutBlock: %s", err) } // Check that PutBlock stored the data as expected - buf, err := GetBlock(testHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(context.Background(), testHash, buf, nil) if err != nil { t.Fatalf("Error during GetBlock for %q: %s", testHash, err) - } else if bytes.Compare(buf, testBlock) != 0 { - t.Errorf("Get response incorrect. Expected %q; found %q", testBlock, buf) + } else if bytes.Compare(buf[:size], testBlock) != 0 { + t.Errorf("Get response incorrect. Expected %q; found %q", testBlock, buf[:size]) } } @@ -103,16 +107,17 @@ func testPutBlockCorrupt(t TB, factory TestableVolumeManagerFactory, testableVolumes[1].PutRaw(testHash, badData) // Check that PutBlock with good data succeeds - if _, err := PutBlock(testBlock, testHash); err != nil { + if _, err := PutBlock(context.Background(), testBlock, testHash); err != nil { t.Fatalf("Error during PutBlock for %q: %s", testHash, err) } // Put succeeded and overwrote the badData in one volume, // and Get should return the testBlock now, ignoring the bad data. - buf, err := GetBlock(testHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(context.Background(), testHash, buf, nil) if err != nil { t.Fatalf("Error during GetBlock for %q: %s", testHash, err) - } else if bytes.Compare(buf, testBlock) != 0 { - t.Errorf("Get response incorrect. Expected %q; found %q", testBlock, buf) + } else if bytes.Compare(buf[:size], testBlock) != 0 { + t.Errorf("Get response incorrect. Expected %q; found %q", testBlock, buf[:size]) } }