[ARVADOS] updated: b836fb6c2d2fb439787b68ecca278e1f8c868d50

git at public.curoverse.com git at public.curoverse.com
Wed Mar 26 17:00:11 EDT 2014


Summary of changes:
 services/keep/keep_test.go |   45 +++++++++++++++++--------------------------
 1 files changed, 18 insertions(+), 27 deletions(-)

       via  b836fb6c2d2fb439787b68ecca278e1f8c868d50 (commit)
      from  e23961a316dc64068a6cc9b799d618f021f85ddb (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 b836fb6c2d2fb439787b68ecca278e1f8c868d50
Author: Tim Pierce <twp at curoverse.com>
Date:   Wed Mar 26 16:58:49 2014 -0400

    Improve readability of unit tests. (refs #2291)
    
    Pass *testing.T object into setup/store functions to reduce
    error-checking overhead.

diff --git a/services/keep/keep_test.go b/services/keep/keep_test.go
index b583c55..5e3b763 100644
--- a/services/keep/keep_test.go
+++ b/services/keep/keep_test.go
@@ -17,13 +17,9 @@ func TestGetBlockOK(t *testing.T) {
 	defer teardown()
 
 	// Create two test Keep volumes and store a block in each of them.
-	if err := setup(2); err != nil {
-		t.Fatal(err)
-	}
+	setup(t, 2)
 	for _, vol := range KeepVolumes {
-		if err := storeTestBlock(vol, TEST_HASH, TEST_BLOCK); err != nil {
-			t.Fatal(err)
-		}
+		store(t, vol, TEST_HASH, TEST_BLOCK)
 	}
 
 	// Check that GetBlock returns success.
@@ -41,12 +37,8 @@ func TestGetBlockOneKeepOK(t *testing.T) {
 	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_HASH, TEST_BLOCK); err != nil {
-		t.Fatal(err)
-	}
+	setup(t, 2)
+	store(t, KeepVolumes[1], TEST_HASH, TEST_BLOCK)
 
 	// Check that GetBlock returns success.
 	result, err := GetBlock(TEST_HASH)
@@ -63,9 +55,7 @@ func TestGetBlockFail(t *testing.T) {
 	defer teardown()
 
 	// Create two empty test Keep volumes.
-	if err := setup(2); err != nil {
-		t.Fatal(err)
-	}
+	setup(t, 2)
 
 	// Check that GetBlock returns failure.
 	result, err := GetBlock(TEST_HASH)
@@ -80,13 +70,9 @@ func TestGetBlockCorrupt(t *testing.T) {
 
 	// 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)
-	}
+	setup(t, 2)
 	for _, vol := range KeepVolumes {
-		if err := storeTestBlock(vol, TEST_HASH, BAD_BLOCK); err != nil {
-			t.Fatal(err)
-		}
+		store(t, vol, TEST_HASH, BAD_BLOCK)
 	}
 
 	// Check that GetBlock returns failure.
@@ -98,28 +84,33 @@ func TestGetBlockCorrupt(t *testing.T) {
 
 // setup
 //     Create KeepVolumes for testing.
-func setup(num_volumes int) error {
+//
+func setup(t *testing.T, num_volumes int) {
 	KeepVolumes = make([]string, num_volumes)
 	for i := range KeepVolumes {
 		if dir, err := ioutil.TempDir(os.TempDir(), "keeptest"); err == nil {
 			KeepVolumes[i] = dir + "/keep"
 		} else {
-			return err
+			t.Fatal(err)
 		}
 	}
-	return nil
 }
 
+// teardown
+//     Cleanup to perform after each test.
+//
 func teardown() {
 	for _, vol := range KeepVolumes {
 		os.RemoveAll(path.Dir(vol))
 	}
 }
 
-func storeTestBlock(keepdir string, filename string, block []byte) error {
+// store
+//
+func store(t *testing.T, 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
+		t.Fatal(err)
 	}
 
 	blockpath := fmt.Sprintf("%s/%s", blockdir, filename)
@@ -127,7 +118,7 @@ func storeTestBlock(keepdir string, filename string, block []byte) error {
 		f.Write(block)
 		f.Close()
 	} else {
-		return err
+		t.Fatal(err)
 	}
 
 	return nil

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list