10 // A TestableVolumeFactory returns a new TestableVolume. The factory
11 // function, and the TestableVolume it returns, can use t to write
12 // logs, fail the current test, etc.
13 type TestableVolumeFactory func(t *testing.T) TestableVolume
15 // DoGenericVolumeTests runs a set of tests that every TestableVolume
16 // is expected to pass. It calls factory to create a new
17 // TestableVolume for each test case, to avoid leaking state between
19 func DoGenericVolumeTests(t *testing.T, factory TestableVolumeFactory) {
20 testDeleteNewBlock(t, factory)
21 testDeleteOldBlock(t, factory)
24 // Calling Delete() for a block immediately after writing it should
25 // neither delete the data nor return an error.
26 func testDeleteNewBlock(t *testing.T, factory TestableVolumeFactory) {
29 v.Put(TEST_HASH, TEST_BLOCK)
31 if err := v.Delete(TEST_HASH); err != nil {
34 if data, err := v.Get(TEST_HASH); err != nil {
36 } else if bytes.Compare(data, TEST_BLOCK) != 0 {
37 t.Error("Block still present, but content is incorrect: %+v != %+v", data, TEST_BLOCK)
41 // Calling Delete() for a block with a timestamp older than
42 // blob_signature_ttl seconds in the past should delete the data.
43 func testDeleteOldBlock(t *testing.T, factory TestableVolumeFactory) {
46 v.Put(TEST_HASH, TEST_BLOCK)
47 v.TouchWithDate(TEST_HASH, time.Now().Add(-2*blob_signature_ttl*time.Second))
49 if err := v.Delete(TEST_HASH); err != nil {
52 if _, err := v.Get(TEST_HASH); err == nil || !os.IsNotExist(err) {
53 t.Errorf("os.IsNotExist(%v) should have been true", err.Error())