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) {
21 testGetBlock(t, factory)
22 testGetNoSuchBlock(t, factory)
23 testGetSystemError(t, factory)
25 testCompareSameContent(t, factory)
26 testCompareWithCollisionError(t, factory)
27 testCompareWithCorruptError(t, factory)
28 testCompareSystemError(t, factory)
30 testPutBlock(t, factory)
31 testPutMultipleBlocks(t, factory)
32 testPutBlockWithSameContent(t, factory)
33 testPutBlockWithDifferentContent(t, factory)
34 testPutBlockSystemError(t, factory)
37 testTouchNoSuchBlock(t, factory)
38 testTouchSystemError(t, factory)
41 testMtimeNoSuchBlock(t, factory)
42 testMtimeSystemError(t, factory)
44 testIndexToWithNoPrefix(t, factory)
45 testIndexToWithPrefix(t, factory)
46 testIndexToWithNoSuchPrefix(t, factory)
47 testIndexToOnEmptyVolume(t, factory)
48 testIndexToSystemError(t, factory)
50 testDeleteNewBlock(t, factory)
51 testDeleteOldWithOnlyBlockInVol(t, factory)
52 testDeleteOldWithOtherBlocksInVol(t, factory)
53 testDeleteNoSuchBlock(t, factory)
54 testDeleteSystemError(t, factory)
56 testStatus(t, factory)
57 testStatusWithError(t, factory)
58 testStatusSystemError(t, factory)
60 testString(t, factory)
61 testStringSystemError(t, factory)
63 testWritableTrue(t, factory)
64 testWritableFalse(t, factory)
65 testWritableSystemError(t, factory)
68 testDeleteNewBlock(t, factory)
69 testDeleteOldBlock(t, factory)
72 // Calling Delete() for a block immediately after writing it should
73 // neither delete the data nor return an error.
74 func testDeleteNewBlock(t *testing.T, factory TestableVolumeFactory) {
77 v.Put(TEST_HASH, TEST_BLOCK)
79 if err := v.Delete(TEST_HASH); err != nil {
82 if data, err := v.Get(TEST_HASH); err != nil {
84 } else if bytes.Compare(data, TEST_BLOCK) != 0 {
85 t.Error("Block still present, but content is incorrect: %+v != %+v", data, TEST_BLOCK)
89 // Calling Delete() for a block with a timestamp older than
90 // blob_signature_ttl seconds in the past should delete the data.
91 func testDeleteOldBlock(t *testing.T, factory TestableVolumeFactory) {
94 v.Put(TEST_HASH, TEST_BLOCK)
95 v.TouchWithDate(TEST_HASH, time.Now().Add(-2*blob_signature_ttl*time.Second))
97 if err := v.Delete(TEST_HASH); err != nil {
100 if _, err := v.Get(TEST_HASH); err == nil || !os.IsNotExist(err) {
101 t.Errorf("os.IsNotExist(%v) should have been true", err.Error())