Commit 9854683d 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 1173c003
......@@ -10,13 +10,13 @@ type BlockGenerator struct {
seq int
}
func (bg *BlockGenerator) Next() blocks.Block {
func (bg *BlockGenerator) Next() *blocks.BasicBlock {
bg.seq++
return blocks.NewBlock([]byte(string(bg.seq)))
}
func (bg *BlockGenerator) Blocks(n int) []blocks.Block {
blocks := make([]blocks.Block, 0)
func (bg *BlockGenerator) Blocks(n int) []*blocks.BasicBlock {
blocks := make([]*blocks.BasicBlock, 0)
for i := 0; i < n; i++ {
b := bg.Next()
blocks = append(blocks, b)
......
......@@ -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