[ARVADOS] updated: 03ab8baef455f5eb9cde83c2b05d82b42c46e216

git at public.curoverse.com git at public.curoverse.com
Tue Mar 25 12:52:34 EDT 2014


Summary of changes:
 services/keep/keep_test.go |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)

       via  03ab8baef455f5eb9cde83c2b05d82b42c46e216 (commit)
      from  070332d12b114e0536ccc5025743bea854bd4c9e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 03ab8baef455f5eb9cde83c2b05d82b42c46e216
Author: Tim Pierce <twp at curoverse.com>
Date:   Tue Mar 25 12:53:40 2014 -0400

    Unit test TestGetBlockCorrupt. (refs #2291)

diff --git a/services/keep/keep_test.go b/services/keep/keep_test.go
index 5960d5f..fd36a5e 100644
--- a/services/keep/keep_test.go
+++ b/services/keep/keep_test.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"crypto/md5"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -11,11 +10,10 @@ import (
 
 var TEST_BLOCK = []byte("The quick brown fox jumps over the lazy dog.")
 var TEST_HASH = "e4d909c290d0fb1ca068ffaddf22cbd0"
+var BAD_BLOCK = []byte("The magic words are squeamish ossifrage.")
 
 // Test simple block reads.
 func TestGetBlockOK(t *testing.T) {
-	var err error
-
 	defer teardown()
 
 	// Create two test Keep volumes and store a block in each of them.
@@ -23,7 +21,7 @@ func TestGetBlockOK(t *testing.T) {
 		t.Fatal(err)
 	}
 	for _, vol := range KeepVolumes {
-		if err := storeTestBlock(vol, TEST_BLOCK); err != nil {
+		if err := storeTestBlock(vol, TEST_HASH, TEST_BLOCK); err != nil {
 			t.Fatal(err)
 		}
 	}
@@ -40,15 +38,13 @@ func TestGetBlockOK(t *testing.T) {
 
 // Test block reads when one Keep volume is missing.
 func TestGetBlockOneKeepOK(t *testing.T) {
-	var err error
-
 	defer teardown()
 
 	// Two test Keep volumes, only the second has a block.
 	if err := setup(2); err != nil {
 		t.Fatal(err)
 	}
-	if err := storeTestBlock(KeepVolumes[1], TEST_BLOCK); err != nil {
+	if err := storeTestBlock(KeepVolumes[1], TEST_HASH, TEST_BLOCK); err != nil {
 		t.Fatal(err)
 	}
 
@@ -64,8 +60,6 @@ func TestGetBlockOneKeepOK(t *testing.T) {
 
 // Test block read failure.
 func TestGetBlockFail(t *testing.T) {
-	var err error
-
 	defer teardown()
 
 	// Create two empty test Keep volumes.
@@ -80,6 +74,28 @@ func TestGetBlockFail(t *testing.T) {
 	}
 }
 
+// Test reading a corrupt block.
+func TestGetBlockCorrupt(t *testing.T) {
+	defer teardown()
+
+	// Create two test Keep volumes and store a block in each of them,
+	// but the hash of the block does not match the filename.
+	if err := setup(2); err != nil {
+		t.Fatal(err)
+	}
+	for _, vol := range KeepVolumes {
+		if err := storeTestBlock(vol, TEST_HASH, BAD_BLOCK); err != nil {
+			t.Fatal(err)
+		}
+	}
+
+	// Check that GetBlock returns failure.
+	result, err := GetBlock(TEST_HASH)
+	if err == nil {
+		t.Errorf("GetBlock incorrectly returned success: %s", result)
+	}
+}
+
 // setup
 //     Create KeepVolumes for testing.
 func setup(nkeeps int) error {
@@ -100,15 +116,13 @@ func teardown() {
 	}
 }
 
-func storeTestBlock(keepdir string, block []byte) error {
-	testhash := fmt.Sprintf("%x", md5.Sum(block))
-
-	blockdir := fmt.Sprintf("%s/%s", keepdir, testhash[:3])
+func storeTestBlock(keepdir string, filename string, block []byte) error {
+	blockdir := fmt.Sprintf("%s/%s", keepdir, filename[:3])
 	if err := os.MkdirAll(blockdir, 0755); err != nil {
 		return err
 	}
 
-	blockpath := fmt.Sprintf("%s/%s", blockdir, testhash)
+	blockpath := fmt.Sprintf("%s/%s", blockdir, filename)
 	if f, err := os.Create(blockpath); err == nil {
 		f.Write(block)
 		f.Close()

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list