7179: Start a set of generic volume tests.
authorTom Clegg <tom@curoverse.com>
Tue, 8 Sep 2015 04:38:41 +0000 (00:38 -0400)
committerTom Clegg <tom@curoverse.com>
Tue, 8 Sep 2015 04:38:41 +0000 (00:38 -0400)
services/keepstore/volume_generic_test.go [new file with mode: 0644]
services/keepstore/volume_unix_test.go

diff --git a/services/keepstore/volume_generic_test.go b/services/keepstore/volume_generic_test.go
new file mode 100644 (file)
index 0000000..20faf8f
--- /dev/null
@@ -0,0 +1,46 @@
+package main
+
+import (
+       "bytes"
+       "os"
+       "testing"
+       "time"
+)
+
+type TestableVolumeFactory func(t *testing.T) TestableVolume
+
+func DoGenericVolumeTests(t *testing.T, factory TestableVolumeFactory) {
+       testDeleteNewBlock(t, factory)
+       testDeleteOldBlock(t, factory)
+}
+
+func testDeleteNewBlock(t *testing.T, factory TestableVolumeFactory) {
+       v := factory(t)
+       defer v.Teardown()
+       v.Put(TEST_HASH, TEST_BLOCK)
+
+       if err := v.Delete(TEST_HASH); err != nil {
+               t.Error(err)
+       }
+       // This isn't reported as an error, but the block should not
+       // have been deleted: it's newer than blob_signature_ttl.
+       if data, err := v.Get(TEST_HASH); err != nil {
+               t.Error(err)
+       } else if bytes.Compare(data, TEST_BLOCK) != 0 {
+               t.Error("Block still present, but content is incorrect: %+v != %+v", data, TEST_BLOCK)
+       }
+}
+
+func testDeleteOldBlock(t *testing.T, factory TestableVolumeFactory) {
+       v := factory(t)
+       defer v.Teardown()
+       v.Put(TEST_HASH, TEST_BLOCK)
+       v.TouchWithDate(TEST_HASH, time.Now().Add(-2*blob_signature_ttl*time.Second))
+
+       if err := v.Delete(TEST_HASH); err != nil {
+               t.Error(err)
+       }
+       if _, err := v.Get(TEST_HASH); err == nil || !os.IsNotExist(err) {
+               t.Errorf("os.IsNotExist(%v) should have been true", err.Error())
+       }
+}
index 83df9ce10bfd2baa75c9e3e0877b4f5a16b02636..b47bedbb885c23fc56e276fabf5151d4381a9164 100644 (file)
@@ -59,6 +59,12 @@ func (v *TestableUnixVolume) Teardown() {
        }
 }
 
+func TestUnixVolumeWithGenericTests(t *testing.T) {
+       DoGenericVolumeTests(t, func(t *testing.T) TestableVolume {
+               return NewTestableUnixVolume(t, false, false)
+       })
+}
+
 func TestGet(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
@@ -180,39 +186,6 @@ func TestUnixVolumeReadonly(t *testing.T) {
        }
 }
 
-func TestUnixVolumeDeleteNewBlock(t *testing.T) {
-       v := NewTestableUnixVolume(t, false, false)
-       defer v.Teardown()
-
-       v.Put(TEST_HASH, TEST_BLOCK)
-
-       if err := v.Delete(TEST_HASH); err != nil {
-               t.Error(err)
-       }
-       // This isn't reported as an error, but the block should not
-       // have been deleted: it's newer than blob_signature_ttl.
-       if data, err := v.Get(TEST_HASH); err != nil {
-               t.Error(err)
-       } else if bytes.Compare(data, TEST_BLOCK) != 0 {
-               t.Error("Content incorrect after delete failed")
-       }
-}
-
-func TestUnixVolumeDeleteOldBlock(t *testing.T) {
-       v := NewTestableUnixVolume(t, false, false)
-       defer v.Teardown()
-
-       v.Put(TEST_HASH, TEST_BLOCK)
-       v.TouchWithDate(TEST_HASH, time.Now().Add(-2*blob_signature_ttl*time.Second))
-
-       if err := v.Delete(TEST_HASH); err != nil {
-               t.Error(err)
-       }
-       if _, err := v.Get(TEST_HASH); !os.IsNotExist(err) {
-               t.Errorf("os.IsNotExist(%v) should have been true", err.Error())
-       }
-}
-
 // TestPutTouch
 //     Test that when applying PUT to a block that already exists,
 //     the block's modification time is updated.