1
0
Fork 0
mirror of https://github.com/vbatts/dedupe-linker.git synced 2024-12-26 16:46:32 +00:00

base: fix test, minimize base root path

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-09-13 09:53:47 -04:00
parent aa4b5f4c39
commit c67d7baba3
2 changed files with 14 additions and 7 deletions

View file

@ -15,13 +15,12 @@ import (
) )
func NewBase(path string, hashName string) (*Base, error) { func NewBase(path string, hashName string) (*Base, error) {
root := filepath.Join(path, "dedup")
for _, p := range []string{"blobs/" + hashName, "state", "tmp"} { for _, p := range []string{"blobs/" + hashName, "state", "tmp"} {
if err := os.MkdirAll(filepath.Join(root, p), 0755); err != nil && !os.IsExist(err) { if err := os.MkdirAll(filepath.Join(path, p), 0755); err != nil && !os.IsExist(err) {
return nil, err return nil, err
} }
} }
return &Base{Path: root, HashName: hashName, Hash: cryptomap.DetermineHash(hashName)}, nil return &Base{Path: path, HashName: hashName, Hash: cryptomap.DetermineHash(hashName)}, nil
} }
type Base struct { type Base struct {

View file

@ -2,7 +2,6 @@ package base
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -50,7 +49,7 @@ func TestGetPut(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
rHash := "deadbeaf" rHash := "8f074e76e82ae6156c451019840a6f857bbe5157"
rMsg := "this is the dead beef" rMsg := "this is the dead beef"
r := bytes.NewReader([]byte(rMsg)) r := bytes.NewReader([]byte(rMsg))
@ -58,12 +57,18 @@ func TestGetPut(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if sum != rHash {
t.Errorf("expected %q; got %q", rHash, sum)
}
fi, err := b.Stat(rHash) fi, err := b.Stat(rHash)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
fmt.Printf("%#v\n", fi.Sys()) if fi == nil {
t.Fatal("did not find the blob " + rHash)
}
//fmt.Printf("%#v\n", fi.Sys())
if err = b.LinkTo(path.Join(srcDir, "beef1.txt"), rHash); err != nil { if err = b.LinkTo(path.Join(srcDir, "beef1.txt"), rHash); err != nil {
t.Error(err) t.Error(err)
@ -72,7 +77,10 @@ func TestGetPut(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
fmt.Printf("%#v\n", fi2.Sys()) if fi2 == nil {
t.Fatal("did not find the linked file " + path.Join(srcDir, "beef1.txt"))
}
//fmt.Printf("%#v\n", fi2.Sys())
if err = b.LinkTo(path.Join(srcDir, "beef1.txt"), rHash); err != nil && !os.IsExist(err) { if err = b.LinkTo(path.Join(srcDir, "beef1.txt"), rHash); err != nil && !os.IsExist(err) {
t.Error(err) t.Error(err)