[ARVADOS] updated: da3e84a0984d60a2f4bec00672eb766e2e978859

git at public.curoverse.com git at public.curoverse.com
Wed Apr 23 18:08:10 EDT 2014


Summary of changes:
 services/keep/src/keep/volume_test.go |  113 +++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)
 create mode 100644 services/keep/src/keep/volume_test.go

       via  da3e84a0984d60a2f4bec00672eb766e2e978859 (commit)
      from  eca0d3d0a6938e08dde6067c4565754c45f5ebb7 (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 da3e84a0984d60a2f4bec00672eb766e2e978859
Author: Tim Pierce <twp at curoverse.com>
Date:   Wed Apr 23 18:09:24 2014 -0400

    Added UnixVolume unit tests. (refs #2620)

diff --git a/services/keep/src/keep/volume_test.go b/services/keep/src/keep/volume_test.go
new file mode 100644
index 0000000..7e3a42e
--- /dev/null
+++ b/services/keep/src/keep/volume_test.go
@@ -0,0 +1,113 @@
+package main
+
+import (
+	"bytes"
+	"fmt"
+	"io/ioutil"
+	"os"
+	"testing"
+)
+
+func TempUnixVolume(t *testing.T) UnixVolume {
+	d, err := ioutil.TempDir("", "volume_test")
+	if err != nil {
+		t.Fatal(err)
+	}
+	return UnixVolume{d}
+}
+
+func _teardown(v UnixVolume) {
+	os.RemoveAll(v.root)
+}
+
+// store writes a Keep block directly into a UnixVolume, for testing
+// UnixVolume methods.
+//
+func _store(t *testing.T, vol UnixVolume, filename string, block []byte) {
+	blockdir := fmt.Sprintf("%s/%s", vol.root, filename[:3])
+	if err := os.MkdirAll(blockdir, 0755); err != nil {
+		t.Fatal(err)
+	}
+
+	blockpath := fmt.Sprintf("%s/%s", blockdir, filename)
+	if f, err := os.Create(blockpath); err == nil {
+		f.Write(block)
+		f.Close()
+	} else {
+		t.Fatal(err)
+	}
+}
+
+func TestRead(t *testing.T) {
+	v := TempUnixVolume(t)
+	defer _teardown(v)
+	_store(t, v, TEST_HASH, TEST_BLOCK)
+
+	buf, err := v.Read(TEST_HASH)
+	if err != nil {
+		t.Error(err)
+	}
+	if bytes.Compare(buf, TEST_BLOCK) != 0 {
+		t.Errorf("expected %s, got %s", string(TEST_BLOCK), string(buf))
+	}
+}
+
+func TestReadNotFound(t *testing.T) {
+	v := TempUnixVolume(t)
+	defer _teardown(v)
+	_store(t, v, TEST_HASH, TEST_BLOCK)
+
+	buf, err := v.Read(TEST_HASH_2)
+	switch {
+	case os.IsNotExist(err):
+		break
+	case err == nil:
+		t.Errorf("Read should have failed, returned %s", string(buf))
+	default:
+		t.Errorf("Read expected ErrNotExist, got: %s", err)
+	}
+}
+
+func TestReadCorrupt(t *testing.T) {
+	v := TempUnixVolume(t)
+	defer _teardown(v)
+	_store(t, v, TEST_HASH, BAD_BLOCK)
+
+	buf, err := v.Read(TEST_HASH)
+	switch err {
+	case CorruptError:
+		break
+	case nil:
+		t.Errorf("Read should have failed, returned %s", string(buf))
+	default:
+		t.Error(err)
+	}
+}
+
+func TestWrite(t *testing.T) {
+	v := TempUnixVolume(t)
+	defer _teardown(v)
+
+	err := v.Write(TEST_HASH, TEST_BLOCK)
+	if err != nil {
+		t.Error(err)
+	}
+	p := fmt.Sprintf("%s/%s/%s", v.root, TEST_HASH[:3], TEST_HASH)
+	if buf, err := ioutil.ReadFile(p); err != nil {
+		t.Error(err)
+	} else if bytes.Compare(buf, TEST_BLOCK) != 0 {
+		t.Errorf("Write should have stored %s, did store %s",
+			string(TEST_BLOCK), string(buf))
+	}
+}
+
+func TestWriteBadVolume(t *testing.T) {
+	v := TempUnixVolume(t)
+	defer _teardown(v)
+
+	os.Chmod(v.root, 000)
+	err := v.Write(TEST_HASH, TEST_BLOCK)
+	if err == nil {
+		t.Error("Write should have failed")
+	}
+}

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list