Merge branch 'master' into 5538-close-idle-connections
[arvados.git] / services / keepstore / volume_generic_test.go
index 74c5b2a7ef7ea86538558b84ab976c142098f414..61088f10fa2d4ef30e969a77e107b824073684e6 100644 (file)
@@ -24,6 +24,7 @@ func DoGenericVolumeTests(t *testing.T, factory TestableVolumeFactory) {
        testGet(t, factory)
        testGetNoSuchBlock(t, factory)
 
+       testCompareNonexistent(t, factory)
        testCompareSameContent(t, factory, TestHash, TestBlock)
        testCompareSameContent(t, factory, EmptyHash, EmptyBlock)
        testCompareWithCollision(t, factory, TestHash, TestBlock, []byte("baddata"))
@@ -95,6 +96,19 @@ func testGetNoSuchBlock(t *testing.T, factory TestableVolumeFactory) {
        }
 }
 
+// Compare() should return os.ErrNotExist if the block does not exist.
+// Otherwise, writing new data causes CompareAndTouch() to generate
+// error logs even though everything is working fine.
+func testCompareNonexistent(t *testing.T, factory TestableVolumeFactory) {
+       v := factory(t)
+       defer v.Teardown()
+
+       err := v.Compare(TestHash, TestBlock)
+       if err != os.ErrNotExist {
+               t.Errorf("Got err %T %q, expected os.ErrNotExist", err, err)
+       }
+}
+
 // Put a test block and compare the locator with same content
 // Test should pass for both writable and read-only volumes
 func testCompareSameContent(t *testing.T, factory TestableVolumeFactory, testHash string, testData []byte) {
@@ -336,6 +350,13 @@ func testIndexTo(t *testing.T, factory TestableVolumeFactory) {
        v.PutRaw(TestHash2, TestBlock2)
        v.PutRaw(TestHash3, TestBlock3)
 
+       // Blocks whose names aren't Keep hashes should be omitted from
+       // index
+       v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
+       v.PutRaw("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", nil)
+       v.PutRaw("f0000000000000000000000000000000f", nil)
+       v.PutRaw("f00", nil)
+
        buf := new(bytes.Buffer)
        v.IndexTo("", buf)
        indexRows := strings.Split(string(buf.Bytes()), "\n")