7329: add generic volume based keepstore tests to have better functional test coverage.
[arvados.git] / services / keepstore / keepstore_test.go
index 380731770dc7e28dd2b6963b833d2fdeaf3dcd32..7a882e0eec2d8f2d65cc2a70fa81bf98f4b7832f 100644 (file)
@@ -26,6 +26,10 @@ var TestHash3 = "eed29bbffbc2dbe5e5ee0bb71888e61f"
 // It must not match any test hashes.
 var BadBlock = []byte("The magic words are squeamish ossifrage.")
 
+// Empty block
+var EmptyHash = "d41d8cd98f00b204e9800998ecf8427e"
+var EmptyBlock = []byte("")
+
 // TODO(twp): Tests still to be written
 //
 //   * TestPutBlockFull
@@ -414,6 +418,44 @@ func TestIndex(t *testing.T) {
        }
 }
 
+// TestKeepStoreGetEmptyBlock
+func TestKeepStoreGetEmptyBlock(t *testing.T) {
+       defer teardown()
+
+       // Prepare two mock volumes
+       KeepVM = MakeTestVolumeManager(2)
+       defer KeepVM.Close()
+
+       vols := KeepVM.AllWritable()
+       if err := vols[0].Put(EmptyHash, EmptyBlock); err != nil {
+               t.Error("Error putting empty block: %s", err)
+       }
+
+       // Check that GetBlock returns success.
+       result, err := GetBlock(EmptyHash)
+       if err != nil {
+               t.Errorf("Get error for empty hash: %s", err)
+       }
+       if bytes.Compare(result, EmptyBlock) != 0 {
+               t.Errorf("Get response incorrect. Expected %q; found %q", EmptyBlock, result)
+       }
+}
+
+// TestKeepStoreGetEmptyBlockNotExists that does not exist
+func TestKeepStoreGetEmptyBlockNotExists(t *testing.T) {
+       defer teardown()
+
+       // Prepare two mock volumes
+       KeepVM = MakeTestVolumeManager(2)
+       defer KeepVM.Close()
+
+       // Check that GetBlock returns error.
+       _, err := GetBlock(EmptyHash)
+       if err == nil {
+               t.Errorf("Expected error when getting non-existing empty block")
+       }
+}
+
 // ========================================
 // Helper functions for unit tests.
 // ========================================