Commit 73bdeb2a authored by Steven Allen's avatar Steven Allen

Merge branch 'feat/ds-bytes'

parents 906a90d3 16d0a2ac
1.2.8: QmRogGwHVEuYgirWvnjVxYXVMsBoJb74QHXT2rTA2Z7vFb
1.3.0: QmU8mLmWDS1SKmqrRUiiedxkFE9gUuST6ggpWM8jAon27d
......@@ -228,7 +228,7 @@ func checkKeys(t *testing.T, dir string, keys []datastore.Key, blocks [][]byte)
if err != nil {
t.Fatalf("Get fail: %v\n", err)
}
if !bytes.Equal(data.([]byte), blocks[i]) {
if !bytes.Equal(data, blocks[i]) {
t.Fatalf("block context differ for key %s\n", key.String())
}
}
......
......@@ -354,18 +354,13 @@ var putMaxRetries = 6
// one arrived slightly later than the other. In the case of a
// concurrent Put and a Delete operation, we cannot guarantee which one
// will win.
func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
val, ok := value.([]byte)
if !ok {
return datastore.ErrInvalidType
}
func (fs *Datastore) Put(key datastore.Key, value []byte) error {
var err error
for i := 1; i <= putMaxRetries; i++ {
err = fs.doWriteOp(&op{
typ: opPut,
key: key,
v: val,
v: value,
})
if err == nil {
break
......@@ -557,7 +552,7 @@ func (fs *Datastore) putMany(data map[datastore.Key]interface{}) error {
return nil
}
func (fs *Datastore) Get(key datastore.Key) (value interface{}, err error) {
func (fs *Datastore) Get(key datastore.Key) (value []byte, err error) {
_, path := fs.encode(key)
data, err := ioutil.ReadFile(path)
if err != nil {
......@@ -1025,7 +1020,7 @@ func (fs *Datastore) Batch() (datastore.Batch, error) {
}, nil
}
func (bt *flatfsBatch) Put(key datastore.Key, val interface{}) error {
func (bt *flatfsBatch) Put(key datastore.Key, val []byte) error {
bt.puts[key] = val
return nil
}
......
......@@ -42,22 +42,6 @@ func tryAllShardFuncs(t *testing.T, testFunc func(mkShardFunc, *testing.T)) {
t.Run("next-to-last", func(t *testing.T) { testFunc(flatfs.NextToLast, t) })
}
func TestPutBadValueType(t *testing.T) {
temp, cleanup := tempdir(t)
defer cleanup()
fs, err := flatfs.CreateOrOpen(temp, flatfs.Prefix(2), false)
if err != nil {
t.Fatalf("New fail: %v\n", err)
}
defer fs.Close()
err = fs.Put(datastore.NewKey("quux"), 22)
if g, e := err, datastore.ErrInvalidType; g != e {
t.Fatalf("expected ErrInvalidType, got: %v\n", g)
}
}
type mkShardFunc func(int) *flatfs.ShardIdV1
func testPut(dirFunc mkShardFunc, t *testing.T) {
......@@ -94,14 +78,10 @@ func testGet(dirFunc mkShardFunc, t *testing.T) {
t.Fatalf("Put fail: %v\n", err)
}
data, err := fs.Get(datastore.NewKey("quux"))
buf, err := fs.Get(datastore.NewKey("quux"))
if err != nil {
t.Fatalf("Get failed: %v", err)
}
buf, ok := data.([]byte)
if !ok {
t.Fatalf("expected []byte from Get, got %T: %v", data, data)
}
if g, e := string(buf), input; g != e {
t.Fatalf("Get gave wrong content: %q != %q", g, e)
}
......@@ -137,7 +117,7 @@ func testPutOverwrite(dirFunc mkShardFunc, t *testing.T) {
if err != nil {
t.Fatalf("Get failed: %v", err)
}
if g, e := string(data.([]byte)), winner; g != e {
if g, e := string(data), winner; g != e {
t.Fatalf("Get gave wrong content: %q != %q", g, e)
}
}
......@@ -732,7 +712,7 @@ func testDiskUsageEstimation(dirFunc mkShardFunc, t *testing.T) {
maxDiff := int(0.05 * float64(duReopen)) // %5 of actual
if diff > maxDiff {
t.Fatal("expected a better estimation within 5%")
t.Fatalf("expected a better estimation within 5%%")
}
// Make sure the accuracy value is correct
......
......@@ -14,9 +14,9 @@
},
{
"author": "jbenet",
"hash": "QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i",
"hash": "QmVG5gxteQNEMhrS8prJSmU2C9rebtFuTd3SYZ5kE3YZ5k",
"name": "go-datastore",
"version": "2.4.1"
"version": "3.0.0"
}
],
"gxVersion": "0.8.0",
......@@ -24,6 +24,6 @@
"license": "",
"name": "go-ds-flatfs",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.2.8"
"version": "1.3.0"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment