8555: Log statistics in EmptyTrash.
[arvados.git] / services / keepstore / volume_unix_test.go
index 4f1e84c0dd998d59f4ea2449c73d2d5d53a4074c..c95538bc4da380f7af5561984d7a069324cea970 100644 (file)
@@ -16,10 +16,10 @@ import (
 
 type TestableUnixVolume struct {
        UnixVolume
-       t *testing.T
+       t TB
 }
 
-func NewTestableUnixVolume(t *testing.T, serialize bool, readonly bool) *TestableUnixVolume {
+func NewTestableUnixVolume(t TB, serialize bool, readonly bool) *TestableUnixVolume {
        d, err := ioutil.TempDir("", "volume_test")
        if err != nil {
                t.Fatal(err)
@@ -66,36 +66,53 @@ func (v *TestableUnixVolume) Teardown() {
 
 // serialize = false; readonly = false
 func TestUnixVolumeWithGenericTests(t *testing.T) {
-       DoGenericVolumeTests(t, func(t *testing.T) TestableVolume {
+       DoGenericVolumeTests(t, func(t TB) TestableVolume {
                return NewTestableUnixVolume(t, false, false)
        })
 }
 
 // serialize = false; readonly = true
 func TestUnixVolumeWithGenericTestsReadOnly(t *testing.T) {
-       DoGenericVolumeTests(t, func(t *testing.T) TestableVolume {
+       DoGenericVolumeTests(t, func(t TB) TestableVolume {
                return NewTestableUnixVolume(t, false, true)
        })
 }
 
 // serialize = true; readonly = false
 func TestUnixVolumeWithGenericTestsSerialized(t *testing.T) {
-       DoGenericVolumeTests(t, func(t *testing.T) TestableVolume {
+       DoGenericVolumeTests(t, func(t TB) TestableVolume {
                return NewTestableUnixVolume(t, true, false)
        })
 }
 
+// serialize = false; readonly = false
+func TestUnixVolumeHandlersWithGenericVolumeTests(t *testing.T) {
+       DoHandlersWithGenericVolumeTests(t, func(t TB) (*RRVolumeManager, []TestableVolume) {
+               vols := make([]Volume, 2)
+               testableUnixVols := make([]TestableVolume, 2)
+
+               for i := range vols {
+                       v := NewTestableUnixVolume(t, false, false)
+                       vols[i] = v
+                       testableUnixVols[i] = v
+               }
+
+               return MakeRRVolumeManager(vols), testableUnixVols
+       })
+}
+
 func TestGetNotFound(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
        v.Put(TestHash, TestBlock)
 
-       buf, err := v.Get(TestHash2)
+       buf := make([]byte, BlockSize)
+       n, err := v.Get(TestHash2, buf)
        switch {
        case os.IsNotExist(err):
                break
        case err == nil:
-               t.Errorf("Read should have failed, returned %s", string(buf))
+               t.Errorf("Read should have failed, returned %+q", buf[:n])
        default:
                t.Errorf("Read expected ErrNotExist, got: %s", err)
        }
@@ -135,7 +152,8 @@ func TestUnixVolumeReadonly(t *testing.T) {
 
        v.PutRaw(TestHash, TestBlock)
 
-       _, err := v.Get(TestHash)
+       buf := make([]byte, BlockSize)
+       _, err := v.Get(TestHash, buf)
        if err != nil {
                t.Errorf("got err %v, expected nil", err)
        }
@@ -150,7 +168,7 @@ func TestUnixVolumeReadonly(t *testing.T) {
                t.Errorf("got err %v, expected MethodDisabledError", err)
        }
 
-       err = v.Delete(TestHash)
+       err = v.Trash(TestHash)
        if err != MethodDisabledError {
                t.Errorf("got err %v, expected MethodDisabledError", err)
        }