mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 08:47:42 +08:00
Merge pull request #1269 from ipfs/rm-testing
move core mock into its own package
This commit is contained in:
@ -1,16 +1,18 @@
|
||||
package blockservice
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
|
||||
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
|
||||
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
)
|
||||
|
||||
type fataler interface {
|
||||
Fatal(args ...interface{})
|
||||
}
|
||||
|
||||
// Mocks returns |n| connected mock Blockservices
|
||||
func Mocks(t *testing.T, n int) []*BlockService {
|
||||
func Mocks(t fataler, n int) []*BlockService {
|
||||
net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
|
||||
sg := bitswap.NewTestSessionGenerator(net)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package coremock
|
||||
|
||||
import (
|
||||
ctxgroup "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
|
||||
@ -7,6 +7,7 @@ import (
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
"github.com/ipfs/go-ipfs/blocks/blockstore"
|
||||
blockservice "github.com/ipfs/go-ipfs/blockservice"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/exchange/offline"
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
nsys "github.com/ipfs/go-ipfs/namesys"
|
||||
@ -25,9 +26,9 @@ import (
|
||||
// Additionally, the context group isn't wired up. This is as good as broken.
|
||||
|
||||
// NewMockNode constructs an IpfsNode for use in tests.
|
||||
func NewMockNode() (*IpfsNode, error) {
|
||||
func NewMockNode() (*core.IpfsNode, error) {
|
||||
ctx := context.TODO()
|
||||
nd := new(IpfsNode)
|
||||
nd := new(core.IpfsNode)
|
||||
|
||||
// Generate Identity
|
||||
ident, err := testutil.RandIdentity()
|
@ -1,23 +1,25 @@
|
||||
package core
|
||||
package core_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coremock "github.com/ipfs/go-ipfs/core/mock"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
)
|
||||
|
||||
func TestResolveNoComponents(t *testing.T) {
|
||||
n, err := NewMockNode()
|
||||
n, err := coremock.NewMockNode()
|
||||
if n == nil || err != nil {
|
||||
t.Fatal("Should have constructed a mock node", err)
|
||||
}
|
||||
|
||||
_, err = Resolve(n.Context(), n, path.Path("/ipns/"))
|
||||
_, err = core.Resolve(n.Context(), n, path.Path("/ipns/"))
|
||||
if err != path.ErrNoComponents {
|
||||
t.Fatal("Should error with no components (/ipns/).", err)
|
||||
}
|
||||
|
||||
_, err = Resolve(n.Context(), n, path.Path("/ipfs/"))
|
||||
_, err = core.Resolve(n.Context(), n, path.Path("/ipfs/"))
|
||||
if err != path.ErrNoComponents {
|
||||
t.Fatal("Should error with no components (/ipfs/).", err)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coremock "github.com/ipfs/go-ipfs/core/mock"
|
||||
nsfs "github.com/ipfs/go-ipfs/ipnsfs"
|
||||
ci "github.com/ipfs/go-ipfs/util/testutil/ci"
|
||||
)
|
||||
@ -114,7 +115,7 @@ func setupIpnsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
|
||||
|
||||
var err error
|
||||
if node == nil {
|
||||
node, err = core.NewMockNode()
|
||||
node, err = coremock.NewMockNode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
coremock "github.com/ipfs/go-ipfs/core/mock"
|
||||
importer "github.com/ipfs/go-ipfs/importer"
|
||||
chunk "github.com/ipfs/go-ipfs/importer/chunk"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
@ -47,7 +48,7 @@ func setupIpfsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
|
||||
|
||||
var err error
|
||||
if node == nil {
|
||||
node, err = core.NewMockNode()
|
||||
node, err = coremock.NewMockNode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user