+// TestPutBlockCorrupt
+// Check that PutBlock returns an error if passed a block and hash that
+// do not match.
+//
+func TestPutBlockCorrupt(t *testing.T) {
+ defer teardown()
+
+ // Create two test Keep volumes.
+ KeepVolumes = setup(t, 2)
+
+ // Check that PutBlock returns the expected error when the hash does
+ // not match the block.
+ if err := PutBlock(BAD_BLOCK, TEST_HASH); err == nil {
+ t.Error("PutBlock succeeded despite a block mismatch")
+ } else {
+ ke := err.(*KeepError)
+ if ke.HTTPCode != 401 || ke.Err.Error() != "MD5Fail" {
+ t.Errorf("PutBlock returned the wrong error (%v)", ke)
+ }
+ }
+
+ // Confirm that GetBlock fails to return anything.
+ if result, err := GetBlock(TEST_HASH); err == nil {
+ t.Errorf("GetBlock succeded after a corrupt block store, returned '%s'",
+ string(result))
+ }
+}
+