[ARVADOS] updated: b860994fa83b9f11b7243220efb8f2fe9b2e2917

git at public.curoverse.com git at public.curoverse.com
Fri Apr 25 16:59:25 EDT 2014


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

       via  b860994fa83b9f11b7243220efb8f2fe9b2e2917 (commit)
      from  dbce533271fca5a106ab8a00ad2621177445131f (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 b860994fa83b9f11b7243220efb8f2fe9b2e2917
Author: Tim Pierce <twp at curoverse.com>
Date:   Fri Apr 25 16:58:32 2014 -0400

    Cleaned up unit tests. (refs #2620)
    
    Added a MockVolume implementation to use in unit tests for the
    Keep front-end handlers.
    
    Simplified IsValidLocator and keep_test.go:setup code.

diff --git a/services/keep/src/keep/volume_mock.go b/services/keep/src/keep/volume_mock.go
new file mode 100644
index 0000000..ec9a3a7
--- /dev/null
+++ b/services/keep/src/keep/volume_mock.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+	"errors"
+	"fmt"
+	"strings"
+)
+
+// MockVolumes are Volumes used to test the Keep front end.
+//
+// If the Bad field is true, this volume should return an error
+// on all writes and puts.
+//
+type MockVolume struct {
+	Store map[string][]byte
+	Bad   bool
+}
+
+func CreateMockVolume() *MockVolume {
+	return &MockVolume{make(map[string][]byte), false}
+}
+
+func (v *MockVolume) Get(loc string) ([]byte, error) {
+	if v.Bad {
+		return nil, errors.New("Bad volume")
+	} else if block, ok := v.Store[loc]; ok {
+		return block, nil
+	}
+	return nil, errors.New("not found")
+}
+
+func (v *MockVolume) Put(loc string, block []byte) error {
+	if v.Bad {
+		return errors.New("Bad volume")
+	}
+	v.Store[loc] = block
+	return nil
+}
+
+func (v *MockVolume) Index(prefix string) string {
+	var result string
+	for loc, block := range v.Store {
+		if IsValidLocator(loc) && strings.HasPrefix(loc, prefix) {
+			result = result + fmt.Sprintf("%s+%d %d\n",
+				loc, len(block), 123456789)
+		}
+	}
+	return result
+}
+
+func (v *MockVolume) Status() *VolumeStatus {
+	var used uint64
+	for _, block := range v.Store {
+		used = used + uint64(len(block))
+	}
+	return &VolumeStatus{"/bogo", 123, 1000000 - used, used}
+}
+
+func (v *MockVolume) String() string {
+	return "[MockVolume]"
+}

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list