From 4a78a9729dcd7fa7df6b6dae508bb63e81f499e8 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 20 May 2015 22:32:56 -0700 Subject: [PATCH] remove testing imports from non testing code rename bserv mock to mock_test swap out testing.T for an interface --- blockservice/mock.go | 8 +++++--- core/{ => mock}/mock.go | 7 ++++--- core/pathresolver_test.go | 10 ++++++---- fuse/ipns/ipns_test.go | 3 ++- fuse/readonly/ipfs_test.go | 3 ++- 5 files changed, 19 insertions(+), 12 deletions(-) rename core/{ => mock}/mock.go (94%) diff --git a/blockservice/mock.go b/blockservice/mock.go index 45b440b3e..293d11f16 100644 --- a/blockservice/mock.go +++ b/blockservice/mock.go @@ -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) diff --git a/core/mock.go b/core/mock/mock.go similarity index 94% rename from core/mock.go rename to core/mock/mock.go index f337aa9b3..d3be2c1da 100644 --- a/core/mock.go +++ b/core/mock/mock.go @@ -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() diff --git a/core/pathresolver_test.go b/core/pathresolver_test.go index 2b694fc4b..489af4eb5 100644 --- a/core/pathresolver_test.go +++ b/core/pathresolver_test.go @@ -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) } diff --git a/fuse/ipns/ipns_test.go b/fuse/ipns/ipns_test.go index 8ac2c403a..6d51ec46e 100644 --- a/fuse/ipns/ipns_test.go +++ b/fuse/ipns/ipns_test.go @@ -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) } diff --git a/fuse/readonly/ipfs_test.go b/fuse/readonly/ipfs_test.go index 2f4765681..1026db1c2 100644 --- a/fuse/readonly/ipfs_test.go +++ b/fuse/readonly/ipfs_test.go @@ -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) }