remove testing imports from non testing code
rename bserv mock to mock_test swap out testing.T for an interface
Jeromy committed
May 20, 2015 at 22:32 UTC
4a78a9729dcd7fa7df6b6dae508bb63e81f499e8
5 files changed
+19
-12
blockservice/mock.go
+5
-3
@@ -1,16 +1,18 @@
1
package blockservice
2
3
import (
4
- "testing"
5
-
4
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
5
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
6
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
7
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
8
)
9
10
+type fataler interface {
11
+ Fatal(args ...interface{})
12
+}
13
+
14
// Mocks returns |n| connected mock Blockservices
13
-func Mocks(t *testing.T, n int) []*BlockService {
15
+func Mocks(t fataler, n int) []*BlockService {
16
net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
17
sg := bitswap.NewTestSessionGenerator(net)
18
core/mock/mock.go
renamed
+4
-3
@@ -1,4 +1,4 @@
1
-package core
1
+package coremock
2
3
import (
4
ctxgroup "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
@@ -7,6 +7,7 @@ import (
7
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
8
"github.com/ipfs/go-ipfs/blocks/blockstore"
9
blockservice "github.com/ipfs/go-ipfs/blockservice"
10
+ core "github.com/ipfs/go-ipfs/core"
11
"github.com/ipfs/go-ipfs/exchange/offline"
12
mdag "github.com/ipfs/go-ipfs/merkledag"
13
nsys "github.com/ipfs/go-ipfs/namesys"
@@ -25,9 +26,9 @@ import (
26
// Additionally, the context group isn't wired up. This is as good as broken.
27
28
// NewMockNode constructs an IpfsNode for use in tests.
28
-func NewMockNode() (*IpfsNode, error) {
29
+func NewMockNode() (*core.IpfsNode, error) {
30
ctx := context.TODO()
30
- nd := new(IpfsNode)
31
+ nd := new(core.IpfsNode)
32
33
// Generate Identity
34
ident, err := testutil.RandIdentity()
core/pathresolver_test.go
+6
-4
@@ -1,23 +1,25 @@
1
-package core
1
+package core_test
2
3
import (
4
"testing"
5
6
+ core "github.com/ipfs/go-ipfs/core"
7
+ coremock "github.com/ipfs/go-ipfs/core/mock"
8
path "github.com/ipfs/go-ipfs/path"
9
)
10
11
func TestResolveNoComponents(t *testing.T) {
10
- n, err := NewMockNode()
12
+ n, err := coremock.NewMockNode()
13
if n == nil || err != nil {
14
t.Fatal("Should have constructed a mock node", err)
15
}
16
15
- _, err = Resolve(n.Context(), n, path.Path("/ipns/"))
17
+ _, err = core.Resolve(n.Context(), n, path.Path("/ipns/"))
18
if err != path.ErrNoComponents {
19
t.Fatal("Should error with no components (/ipns/).", err)
20
}
21
20
- _, err = Resolve(n.Context(), n, path.Path("/ipfs/"))
22
+ _, err = core.Resolve(n.Context(), n, path.Path("/ipfs/"))
23
if err != path.ErrNoComponents {
24
t.Fatal("Should error with no components (/ipfs/).", err)
25
}
fuse/ipns/ipns_test.go
+2
-1
@@ -17,6 +17,7 @@ import (
17
18
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
19
core "github.com/ipfs/go-ipfs/core"
20
+ coremock "github.com/ipfs/go-ipfs/core/mock"
21
nsfs "github.com/ipfs/go-ipfs/ipnsfs"
22
ci "github.com/ipfs/go-ipfs/util/testutil/ci"
23
)
@@ -114,7 +115,7 @@ func setupIpnsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
115
116
var err error
117
if node == nil {
117
- node, err = core.NewMockNode()
118
+ node, err = coremock.NewMockNode()
119
if err != nil {
120
t.Fatal(err)
121
}
fuse/readonly/ipfs_test.go
+2
-1
@@ -16,6 +16,7 @@ import (
16
17
core "github.com/ipfs/go-ipfs/core"
18
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
19
+ coremock "github.com/ipfs/go-ipfs/core/mock"
20
importer "github.com/ipfs/go-ipfs/importer"
21
chunk "github.com/ipfs/go-ipfs/importer/chunk"
22
dag "github.com/ipfs/go-ipfs/merkledag"
@@ -47,7 +48,7 @@ func setupIpfsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
48
49
var err error
50
if node == nil {
50
- node, err = core.NewMockNode()
51
+ node, err = coremock.NewMockNode()
52
if err != nil {
53
t.Fatal(err)
54
}