Commit 06c5dbf8 authored by Jakub Sztandera's avatar Jakub Sztandera Committed by Kevin Atkinson

test: check if NewWriteThrough is not calling Has

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protonmail.ch>
parent 2645e2bd
......@@ -4,6 +4,7 @@
package blockservice
import (
"context"
"errors"
"fmt"
......@@ -11,7 +12,6 @@ import (
"github.com/ipfs/go-ipfs/blocks/blockstore"
exchange "github.com/ipfs/go-ipfs/exchange"
context "context"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid"
)
......
package blockservice
import (
"testing"
"github.com/ipfs/go-ipfs/blocks/blockstore"
butil "github.com/ipfs/go-ipfs/blocks/blocksutil"
offline "github.com/ipfs/go-ipfs/exchange/offline"
cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid"
ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync"
)
func TestWriteThroughWorks(t *testing.T) {
dstore := dssync.MutexWrap(ds.NewMapDatastore())
bstore := HasFailingBlockstore{
blockstore.NewBlockstore(dstore),
t,
true,
}
exch := offline.Exchange(bstore)
bserv := NewWriteThrough(bstore, exch)
bgen := butil.NewBlockGenerator()
bserv.AddBlock(bgen.Next())
}
var _ blockstore.GCBlockstore = (*HasFailingBlockstore)(nil)
type HasFailingBlockstore struct {
blockstore.GCBlockstore
t *testing.T
Fail bool
}
func (bs HasFailingBlockstore) Has(k *cid.Cid) (bool, error) {
if bs.Fail {
bs.t.Fatal("Has shouldn't be called")
return false, nil
}
return bs.GCBlockstore.Has(k)
}
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