Commit 4a78a972 authored by Jeromy's avatar Jeromy Committed by Juan Batiz-Benet

remove testing imports from non testing code

rename bserv mock to mock_test

swap out testing.T for an interface
parent f39af41a
package blockservice package blockservice
import ( import (
"testing"
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap" bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet" tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
mockrouting "github.com/ipfs/go-ipfs/routing/mock" mockrouting "github.com/ipfs/go-ipfs/routing/mock"
delay "github.com/ipfs/go-ipfs/thirdparty/delay" delay "github.com/ipfs/go-ipfs/thirdparty/delay"
) )
type fataler interface {
Fatal(args ...interface{})
}
// Mocks returns |n| connected mock Blockservices // 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)) net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
sg := bitswap.NewTestSessionGenerator(net) sg := bitswap.NewTestSessionGenerator(net)
......
package core package coremock
import ( import (
ctxgroup "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup" ctxgroup "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/blocks/blockstore" "github.com/ipfs/go-ipfs/blocks/blockstore"
blockservice "github.com/ipfs/go-ipfs/blockservice" blockservice "github.com/ipfs/go-ipfs/blockservice"
core "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/exchange/offline" "github.com/ipfs/go-ipfs/exchange/offline"
mdag "github.com/ipfs/go-ipfs/merkledag" mdag "github.com/ipfs/go-ipfs/merkledag"
nsys "github.com/ipfs/go-ipfs/namesys" nsys "github.com/ipfs/go-ipfs/namesys"
...@@ -25,9 +26,9 @@ import ( ...@@ -25,9 +26,9 @@ import (
// Additionally, the context group isn't wired up. This is as good as broken. // Additionally, the context group isn't wired up. This is as good as broken.
// NewMockNode constructs an IpfsNode for use in tests. // NewMockNode constructs an IpfsNode for use in tests.
func NewMockNode() (*IpfsNode, error) { func NewMockNode() (*core.IpfsNode, error) {
ctx := context.TODO() ctx := context.TODO()
nd := new(IpfsNode) nd := new(core.IpfsNode)
// Generate Identity // Generate Identity
ident, err := testutil.RandIdentity() ident, err := testutil.RandIdentity()
......
package core package core_test
import ( import (
"testing" "testing"
core "github.com/ipfs/go-ipfs/core"
coremock "github.com/ipfs/go-ipfs/core/mock"
path "github.com/ipfs/go-ipfs/path" path "github.com/ipfs/go-ipfs/path"
) )
func TestResolveNoComponents(t *testing.T) { func TestResolveNoComponents(t *testing.T) {
n, err := NewMockNode() n, err := coremock.NewMockNode()
if n == nil || err != nil { if n == nil || err != nil {
t.Fatal("Should have constructed a mock node", err) 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 { if err != path.ErrNoComponents {
t.Fatal("Should error with no components (/ipns/).", err) 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 { if err != path.ErrNoComponents {
t.Fatal("Should error with no components (/ipfs/).", err) t.Fatal("Should error with no components (/ipfs/).", err)
} }
......
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
coremock "github.com/ipfs/go-ipfs/core/mock"
nsfs "github.com/ipfs/go-ipfs/ipnsfs" nsfs "github.com/ipfs/go-ipfs/ipnsfs"
ci "github.com/ipfs/go-ipfs/util/testutil/ci" 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 ...@@ -114,7 +115,7 @@ func setupIpnsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
var err error var err error
if node == nil { if node == nil {
node, err = core.NewMockNode() node, err = coremock.NewMockNode()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
coreunix "github.com/ipfs/go-ipfs/core/coreunix" coreunix "github.com/ipfs/go-ipfs/core/coreunix"
coremock "github.com/ipfs/go-ipfs/core/mock"
importer "github.com/ipfs/go-ipfs/importer" importer "github.com/ipfs/go-ipfs/importer"
chunk "github.com/ipfs/go-ipfs/importer/chunk" chunk "github.com/ipfs/go-ipfs/importer/chunk"
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
...@@ -47,7 +48,7 @@ func setupIpfsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M ...@@ -47,7 +48,7 @@ func setupIpfsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
var err error var err error
if node == nil { if node == nil {
node, err = core.NewMockNode() node, err = coremock.NewMockNode()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
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