7179: list out the potential tests
[arvados.git] / services / keepstore / volume_generic_test.go
1 package main
2
3 import (
4         "bytes"
5         "os"
6         "testing"
7         "time"
8 )
9
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
14
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
18 // tests.
19 func DoGenericVolumeTests(t *testing.T, factory TestableVolumeFactory) {
20         /*
21                 testGetBlock(t, factory)
22                 testGetNoSuchBlock(t, factory)
23                 testGetSystemError(t, factory)
24
25                 testCompareSameContent(t, factory)
26                 testCompareWithCollisionError(t, factory)
27                 testCompareWithCorruptError(t, factory)
28                 testCompareSystemError(t, factory)
29
30                 testPutBlock(t, factory)
31                 testPutMultipleBlocks(t, factory)
32                 testPutBlockWithSameContent(t, factory)
33                 testPutBlockWithDifferentContent(t, factory)
34                 testPutBlockSystemError(t, factory)
35
36                 testTouch(t, factory)
37                 testTouchNoSuchBlock(t, factory)
38                 testTouchSystemError(t, factory)
39
40                 testMtime(t, factory)
41                 testMtimeNoSuchBlock(t, factory)
42                 testMtimeSystemError(t, factory)
43
44                 testIndexToWithNoPrefix(t, factory)
45                 testIndexToWithPrefix(t, factory)
46                 testIndexToWithNoSuchPrefix(t, factory)
47                 testIndexToOnEmptyVolume(t, factory)
48                 testIndexToSystemError(t, factory)
49
50                 testDeleteNewBlock(t, factory)
51                 testDeleteOldWithOnlyBlockInVol(t, factory)
52                 testDeleteOldWithOtherBlocksInVol(t, factory)
53                 testDeleteNoSuchBlock(t, factory)
54                 testDeleteSystemError(t, factory)
55
56                 testStatus(t, factory)
57                 testStatusWithError(t, factory)
58                 testStatusSystemError(t, factory)
59
60                 testString(t, factory)
61                 testStringSystemError(t, factory)
62
63                 testWritableTrue(t, factory)
64                 testWritableFalse(t, factory)
65                 testWritableSystemError(t, factory)
66         */
67
68         testDeleteNewBlock(t, factory)
69         testDeleteOldBlock(t, factory)
70 }
71
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) {
75         v := factory(t)
76         defer v.Teardown()
77         v.Put(TEST_HASH, TEST_BLOCK)
78
79         if err := v.Delete(TEST_HASH); err != nil {
80                 t.Error(err)
81         }
82         if data, err := v.Get(TEST_HASH); err != nil {
83                 t.Error(err)
84         } else if bytes.Compare(data, TEST_BLOCK) != 0 {
85                 t.Error("Block still present, but content is incorrect: %+v != %+v", data, TEST_BLOCK)
86         }
87 }
88
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) {
92         v := factory(t)
93         defer v.Teardown()
94         v.Put(TEST_HASH, TEST_BLOCK)
95         v.TouchWithDate(TEST_HASH, time.Now().Add(-2*blob_signature_ttl*time.Second))
96
97         if err := v.Delete(TEST_HASH); err != nil {
98                 t.Error(err)
99         }
100         if _, err := v.Get(TEST_HASH); err == nil || !os.IsNotExist(err) {
101                 t.Errorf("os.IsNotExist(%v) should have been true", err.Error())
102         }
103 }