6377: Fix crash if no asset pipeline.
[arvados.git] / services / keepstore / volume_test.go
index 379c8903a56a02b2499c2b08cd6c2b800d9a4860..261501992f8080110062cc7be7a1828052f24014 100644 (file)
@@ -3,6 +3,7 @@ package main
 import (
        "errors"
        "fmt"
+       "io"
        "os"
        "strings"
        "sync"
@@ -64,7 +65,9 @@ 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
+               buf := bufs.Get(len(block))
+               copy(buf, block)
+               return buf, nil
        }
        return nil, os.ErrNotExist
 }
@@ -107,16 +110,19 @@ func (v *MockVolume) Mtime(loc string) (time.Time, error) {
        return mtime, err
 }
 
-func (v *MockVolume) Index(prefix string) string {
-       v.gotCall("Index")
-       var result string
+func (v *MockVolume) IndexTo(prefix string, w io.Writer) error {
+       v.gotCall("IndexTo")
        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)
+               if !IsValidLocator(loc) || !strings.HasPrefix(loc, prefix) {
+                       continue
+               }
+               _, err := fmt.Fprintf(w, "%s+%d %d\n",
+                       loc, len(block), 123456789)
+               if err != nil {
+                       return err
                }
        }
-       return result
+       return nil
 }
 
 func (v *MockVolume) Delete(loc string) error {