coreapi: Interface for external test providers
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Dec 20, 2018 at 21:01 UTC
94724fdaf89a24657fcec372e359ebbe78e25fd6
12 files changed
+341
-317
core/coreapi/interface/tests/api.go
+24
-110
@@ -2,128 +2,42 @@ package tests
2
3
import (
4
"context"
5
- "encoding/base64"
6
- "fmt"
5
"testing"
6
9
- "github.com/ipfs/go-ipfs/core"
10
- "github.com/ipfs/go-ipfs/core/coreapi"
7
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
12
- mock "github.com/ipfs/go-ipfs/core/mock"
13
- "github.com/ipfs/go-ipfs/keystore"
14
- "github.com/ipfs/go-ipfs/repo"
15
-
16
- ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
17
- "gx/ipfs/QmRBaUEQEeFWywfrZJ64QgsmvcqgLSK3VbvGMR2NM2Edpf/go-libp2p/p2p/net/mock"
18
- "gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
19
- pstore "gx/ipfs/QmZ9zH2FnLcxv1xyzFeUpDUeo55xEhZQHgveZijcxr7TLj/go-libp2p-peerstore"
20
- "gx/ipfs/QmcZfkbgwwwH5ZLTQRHkSQBDiDqd3skY2eU6MZRgWuXcse/go-ipfs-config"
21
- "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore"
22
- syncds "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore/sync"
8
)
9
25
-
26
-func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
27
- mn := mocknet.New(ctx)
28
-
29
- nodes := make([]*core.IpfsNode, n)
30
- apis := make([]coreiface.CoreAPI, n)
31
-
32
- for i := 0; i < n; i++ {
33
- var ident config.Identity
34
- if fullIdentity {
35
- sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
36
- if err != nil {
37
- return nil, err
38
- }
39
-
40
- id, err := peer.IDFromPublicKey(pk)
41
- if err != nil {
42
- return nil, err
43
- }
44
-
45
- kbytes, err := sk.Bytes()
46
- if err != nil {
47
- return nil, err
48
- }
49
-
50
- ident = config.Identity{
51
- PeerID: id.Pretty(),
52
- PrivKey: base64.StdEncoding.EncodeToString(kbytes),
53
- }
54
- } else {
55
- ident = config.Identity{
56
- PeerID: testPeerID,
57
- }
58
- }
59
-
60
- c := config.Config{}
61
- c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
62
- c.Identity = ident
63
-
64
- r := &repo.Mock{
65
- C: c,
66
- D: syncds.MutexWrap(datastore.NewMapDatastore()),
67
- K: keystore.NewMemKeystore(),
68
- }
69
-
70
- node, err := core.NewNode(ctx, &core.BuildCfg{
71
- Repo: r,
72
- Host: mock.MockHostOption(mn),
73
- Online: fullIdentity,
74
- ExtraOpts: map[string]bool{
75
- "pubsub": true,
76
- },
77
- })
78
- if err != nil {
79
- return nil, err
80
- }
81
- nodes[i] = node
82
- apis[i], err = coreapi.NewCoreAPI(node)
83
- if err != nil {
84
- return nil, err
85
- }
86
- }
87
-
88
- err := mn.LinkAll()
10
+func (tp *provider) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
11
+ api, err := tp.MakeAPISwarm(ctx, false, 1)
12
if err != nil {
13
return nil, err
14
}
15
93
- bsinf := core.BootstrapConfigWithPeers(
94
- []pstore.PeerInfo{
95
- nodes[0].Peerstore.PeerInfo(nodes[0].Identity),
96
- },
97
- )
98
-
99
- for _, n := range nodes[1:] {
100
- if err := n.Bootstrap(bsinf); err != nil {
101
- return nil, err
102
- }
103
- }
104
-
105
- return apis, nil
16
+ return api[0], nil
17
}
18
108
-func makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
109
- api, err := makeAPISwarm(ctx, false, 1)
110
- if err != nil {
111
- return nil, err
112
- }
113
-
114
- return api[0], nil
19
+type Provider interface {
20
+ // Make creates n nodes. fullIdentity set to false can be ignored
21
+ MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error)
22
}
23
24
+type provider struct {
25
+ Provider
26
+}
27
118
-func TestApi(t *testing.T) {
119
- t.Run("Block", TestBlock)
120
- t.Run("TestDag", TestDag)
121
- t.Run("TestDht", TestDht)
122
- t.Run("TestKey", TestKey)
123
- t.Run("TestName", TestName)
124
- t.Run("TestObject", TestObject)
125
- t.Run("TestPath", TestPath)
126
- t.Run("TestPin", TestPin)
127
- t.Run("TestPubSub", TestPubSub)
128
- t.Run("TestUnixfs", TestUnixfs)
28
+func TestApi(p Provider) func(t *testing.T) {
29
+ tp := &provider{p}
30
+
31
+ return func(t *testing.T) {
32
+ t.Run("Block", tp.TestBlock)
33
+ t.Run("Dag", tp.TestDag)
34
+ t.Run("Dht", tp.TestDht)
35
+ t.Run("Key", tp.TestKey)
36
+ t.Run("Name", tp.TestName)
37
+ t.Run("Object", tp.TestObject)
38
+ t.Run("Path", tp.TestPath)
39
+ t.Run("Pin", tp.TestPin)
40
+ t.Run("PubSub", tp.TestPubSub)
41
+ t.Run("Unixfs", tp.TestUnixfs)
42
+ }
43
}
core/coreapi/interface/tests/block.go
+19
-19
@@ -12,18 +12,18 @@ import (
12
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
13
)
14
15
-func TestBlock(t *testing.T) {
16
- t.Run("TestBlockPut", TestBlockPut)
17
- t.Run("TestBlockPutFormat", TestBlockPutFormat)
18
- t.Run("TestBlockPutHash", TestBlockPutHash)
19
- t.Run("TestBlockGet", TestBlockGet)
20
- t.Run("TestBlockRm", TestBlockRm)
21
- t.Run("TestBlockStat", TestBlockStat)
15
+func (tp *provider) TestBlock(t *testing.T) {
16
+ t.Run("TestBlockPut", tp.TestBlockPut)
17
+ t.Run("TestBlockPutFormat", tp.TestBlockPutFormat)
18
+ t.Run("TestBlockPutHash", tp.TestBlockPutHash)
19
+ t.Run("TestBlockGet", tp.TestBlockGet)
20
+ t.Run("TestBlockRm", tp.TestBlockRm)
21
+ t.Run("TestBlockStat", tp.TestBlockStat)
22
}
23
24
-func TestBlockPut(t *testing.T) {
24
+func (tp *provider) TestBlockPut(t *testing.T) {
25
ctx := context.Background()
26
- api, err := makeAPI(ctx)
26
+ api, err := tp.makeAPI(ctx)
27
if err != nil {
28
t.Error(err)
29
}
@@ -38,9 +38,9 @@ func TestBlockPut(t *testing.T) {
38
}
39
}
40
41
-func TestBlockPutFormat(t *testing.T) {
41
+func (tp *provider) TestBlockPutFormat(t *testing.T) {
42
ctx := context.Background()
43
- api, err := makeAPI(ctx)
43
+ api, err := tp.makeAPI(ctx)
44
if err != nil {
45
t.Error(err)
46
}
@@ -55,9 +55,9 @@ func TestBlockPutFormat(t *testing.T) {
55
}
56
}
57
58
-func TestBlockPutHash(t *testing.T) {
58
+func (tp *provider) TestBlockPutHash(t *testing.T) {
59
ctx := context.Background()
60
- api, err := makeAPI(ctx)
60
+ api, err := tp.makeAPI(ctx)
61
if err != nil {
62
t.Error(err)
63
}
@@ -72,9 +72,9 @@ func TestBlockPutHash(t *testing.T) {
72
}
73
}
74
75
-func TestBlockGet(t *testing.T) {
75
+func (tp *provider) TestBlockGet(t *testing.T) {
76
ctx := context.Background()
77
- api, err := makeAPI(ctx)
77
+ api, err := tp.makeAPI(ctx)
78
if err != nil {
79
t.Error(err)
80
}
@@ -112,9 +112,9 @@ func TestBlockGet(t *testing.T) {
112
}
113
}
114
115
-func TestBlockRm(t *testing.T) {
115
+func (tp *provider) TestBlockRm(t *testing.T) {
116
ctx := context.Background()
117
- api, err := makeAPI(ctx)
117
+ api, err := tp.makeAPI(ctx)
118
if err != nil {
119
t.Error(err)
120
}
@@ -165,9 +165,9 @@ func TestBlockRm(t *testing.T) {
165
}
166
}
167
168
-func TestBlockStat(t *testing.T) {
168
+func (tp *provider) TestBlockStat(t *testing.T) {
169
ctx := context.Background()
170
- api, err := makeAPI(ctx)
170
+ api, err := tp.makeAPI(ctx)
171
if err != nil {
172
t.Error(err)
173
}
core/coreapi/interface/tests/dag.go
+16
-16
@@ -12,12 +12,12 @@ import (
12
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
13
)
14
15
-func TestDag(t *testing.T) {
16
- t.Run("TestPut", TestPut)
17
- t.Run("TestPutWithHash", TestPutWithHash)
18
- t.Run("TestPath", TestDagPath)
19
- t.Run("TestTree", TestTree)
20
- t.Run("TestBatch", TestBatch)
15
+func (tp *provider) TestDag(t *testing.T) {
16
+ t.Run("TestPut", tp.TestPut)
17
+ t.Run("TestPutWithHash", tp.TestPutWithHash)
18
+ t.Run("TestPath", tp.TestDagPath)
19
+ t.Run("TestTree", tp.TestTree)
20
+ t.Run("TestBatch", tp.TestBatch)
21
}
22
23
var (
@@ -30,9 +30,9 @@ var (
30
}
31
)
32
33
-func TestPut(t *testing.T) {
33
+func (tp *provider) TestPut(t *testing.T) {
34
ctx := context.Background()
35
- api, err := makeAPI(ctx)
35
+ api, err := tp.makeAPI(ctx)
36
if err != nil {
37
t.Error(err)
38
}
@@ -47,9 +47,9 @@ func TestPut(t *testing.T) {
47
}
48
}
49
50
-func TestPutWithHash(t *testing.T) {
50
+func (tp *provider) TestPutWithHash(t *testing.T) {
51
ctx := context.Background()
52
- api, err := makeAPI(ctx)
52
+ api, err := tp.makeAPI(ctx)
53
if err != nil {
54
t.Error(err)
55
}
@@ -64,9 +64,9 @@ func TestPutWithHash(t *testing.T) {
64
}
65
}
66
67
-func TestDagPath(t *testing.T) {
67
+func (tp *provider) TestDagPath(t *testing.T) {
68
ctx := context.Background()
69
- api, err := makeAPI(ctx)
69
+ api, err := tp.makeAPI(ctx)
70
if err != nil {
71
t.Error(err)
72
}
@@ -96,9 +96,9 @@ func TestDagPath(t *testing.T) {
96
}
97
}
98
99
-func TestTree(t *testing.T) {
99
+func (tp *provider) TestTree(t *testing.T) {
100
ctx := context.Background()
101
- api, err := makeAPI(ctx)
101
+ api, err := tp.makeAPI(ctx)
102
if err != nil {
103
t.Error(err)
104
}
@@ -125,9 +125,9 @@ func TestTree(t *testing.T) {
125
}
126
}
127
128
-func TestBatch(t *testing.T) {
128
+func (tp *provider) TestBatch(t *testing.T) {
129
ctx := context.Background()
130
- api, err := makeAPI(ctx)
130
+ api, err := tp.makeAPI(ctx)
131
if err != nil {
132
t.Error(err)
133
}
core/coreapi/interface/tests/dht.go
+10
-10
@@ -8,15 +8,15 @@ import (
8
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9
)
10
11
-func TestDht(t *testing.T) {
12
- t.Run("TestDhtFindPeer", TestDhtFindPeer)
13
- t.Run("TestDhtFindProviders", TestDhtFindProviders)
14
- t.Run("TestDhtProvide", TestDhtProvide)
11
+func (tp *provider) TestDht(t *testing.T) {
12
+ t.Run("TestDhtFindPeer", tp.TestDhtFindPeer)
13
+ t.Run("TestDhtFindProviders", tp.TestDhtFindProviders)
14
+ t.Run("TestDhtProvide", tp.TestDhtProvide)
15
}
16
17
-func TestDhtFindPeer(t *testing.T) {
17
+func (tp *provider) TestDhtFindPeer(t *testing.T) {
18
ctx := context.Background()
19
- apis, err := makeAPISwarm(ctx, true, 5)
19
+ apis, err := tp.MakeAPISwarm(ctx, true, 5)
20
if err != nil {
21
t.Fatal(err)
22
}
@@ -50,9 +50,9 @@ func TestDhtFindPeer(t *testing.T) {
50
}
51
}
52
53
-func TestDhtFindProviders(t *testing.T) {
53
+func (tp *provider) TestDhtFindProviders(t *testing.T) {
54
ctx := context.Background()
55
- apis, err := makeAPISwarm(ctx, true, 5)
55
+ apis, err := tp.MakeAPISwarm(ctx, true, 5)
56
if err != nil {
57
t.Fatal(err)
58
}
@@ -79,9 +79,9 @@ func TestDhtFindProviders(t *testing.T) {
79
}
80
}
81
82
-func TestDhtProvide(t *testing.T) {
82
+func (tp *provider) TestDhtProvide(t *testing.T) {
83
ctx := context.Background()
84
- apis, err := makeAPISwarm(ctx, true, 5)
84
+ apis, err := tp.MakeAPISwarm(ctx, true, 5)
85
if err != nil {
86
t.Fatal(err)
87
}
core/coreapi/interface/tests/key.go
+56
-49
@@ -8,31 +8,38 @@ import (
8
opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9
)
10
11
-func TestKey(t *testing.T) {
12
- t.Run("TestListSelf", TestListSelf)
13
- t.Run("TestRenameSelf", TestRenameSelf)
14
- t.Run("TestRemoveSelf", TestRemoveSelf)
15
- t.Run("TestGenerateSize", TestGenerateSize)
16
- t.Run("TestGenerateExisting", TestGenerateExisting)
17
- t.Run("TestList", TestList)
18
- t.Run("TestRename", TestRename)
19
- t.Run("TestRenameToSelf", TestRenameToSelf)
20
- t.Run("TestRenameToSelfForce", TestRenameToSelfForce)
21
- t.Run("TestRenameOverwriteNoForce", TestRenameOverwriteNoForce)
22
- t.Run("TestRenameOverwrite", TestRenameOverwrite)
23
- t.Run("TestRenameSameNameNoForce", TestRenameSameNameNoForce)
24
- t.Run("TestRenameSameName", TestRenameSameName)
25
- t.Run("TestRemove", TestRemove)
11
+func (tp *provider) TestKey(t *testing.T) {
12
+ t.Run("TestListSelf", tp.TestListSelf)
13
+ t.Run("TestRenameSelf", tp.TestRenameSelf)
14
+ t.Run("TestRemoveSelf", tp.TestRemoveSelf)
15
+ t.Run("TestGenerate", tp.TestGenerate)
16
+ t.Run("TestGenerateSize", tp.TestGenerateSize)
17
+ t.Run("TestGenerateType", tp.TestGenerateType)
18
+ t.Run("TestGenerateExisting", tp.TestGenerateExisting)
19
+ t.Run("TestList", tp.TestList)
20
+ t.Run("TestRename", tp.TestRename)
21
+ t.Run("TestRenameToSelf", tp.TestRenameToSelf)
22
+ t.Run("TestRenameToSelfForce", tp.TestRenameToSelfForce)
23
+ t.Run("TestRenameOverwriteNoForce", tp.TestRenameOverwriteNoForce)
24
+ t.Run("TestRenameOverwrite", tp.TestRenameOverwrite)
25
+ t.Run("TestRenameSameNameNoForce", tp.TestRenameSameNameNoForce)
26
+ t.Run("TestRenameSameName", tp.TestRenameSameName)
27
+ t.Run("TestRemove", tp.TestRemove)
28
}
29
28
-func TestListSelf(t *testing.T) {
30
+func (tp *provider) TestListSelf(t *testing.T) {
31
ctx := context.Background()
30
- api, err := makeAPI(ctx)
32
+ api, err := tp.makeAPI(ctx)
33
if err != nil {
34
t.Fatal(err)
35
return
36
}
37
38
+ self, err := api.Key().Self(ctx)
39
+ if err != nil {
40
+ t.Fatal(err)
41
+ }
42
+
43
keys, err := api.Key().List(ctx)
44
if err != nil {
45
t.Fatalf("failed to list keys: %s", err)
@@ -48,14 +55,14 @@ func TestListSelf(t *testing.T) {
55
t.Errorf("expected the key to be called 'self', got '%s'", keys[0].Name())
56
}
57
51
- if keys[0].Path().String() != "/ipns/"+testPeerID {
52
- t.Errorf("expected the key to have path '/ipns/%s', got '%s'", testPeerID, keys[0].Path().String())
58
+ if keys[0].Path().String() != "/ipns/"+self.ID().Pretty() {
59
+ t.Errorf("expected the key to have path '/ipns/%s', got '%s'", self.ID().Pretty(), keys[0].Path().String())
60
}
61
}
62
56
-func TestRenameSelf(t *testing.T) {
63
+func (tp *provider) TestRenameSelf(t *testing.T) {
64
ctx := context.Background()
58
- api, err := makeAPI(ctx)
65
+ api, err := tp.makeAPI(ctx)
66
if err != nil {
67
t.Fatal(err)
68
return
@@ -80,9 +87,9 @@ func TestRenameSelf(t *testing.T) {
87
}
88
}
89
83
-func TestRemoveSelf(t *testing.T) {
90
+func (tp *provider) TestRemoveSelf(t *testing.T) {
91
ctx := context.Background()
85
- api, err := makeAPI(ctx)
92
+ api, err := tp.makeAPI(ctx)
93
if err != nil {
94
t.Fatal(err)
95
return
@@ -98,9 +105,9 @@ func TestRemoveSelf(t *testing.T) {
105
}
106
}
107
101
-func TestGenerate(t *testing.T) {
108
+func (tp *provider) TestGenerate(t *testing.T) {
109
ctx := context.Background()
103
- api, err := makeAPI(ctx)
110
+ api, err := tp.makeAPI(ctx)
111
if err != nil {
112
t.Error(err)
113
}
@@ -120,9 +127,9 @@ func TestGenerate(t *testing.T) {
127
}
128
}
129
123
-func TestGenerateSize(t *testing.T) {
130
+func (tp *provider) TestGenerateSize(t *testing.T) {
131
ctx := context.Background()
125
- api, err := makeAPI(ctx)
132
+ api, err := tp.makeAPI(ctx)
133
if err != nil {
134
t.Error(err)
135
}
@@ -142,11 +149,11 @@ func TestGenerateSize(t *testing.T) {
149
}
150
}
151
145
-func TestGenerateType(t *testing.T) {
152
+func (tp *provider) TestGenerateType(t *testing.T) {
153
ctx := context.Background()
154
t.Skip("disabled until libp2p/specs#111 is fixed")
155
149
- api, err := makeAPI(ctx)
156
+ api, err := tp.makeAPI(ctx)
157
if err != nil {
158
t.Error(err)
159
}
@@ -167,9 +174,9 @@ func TestGenerateType(t *testing.T) {
174
}
175
}
176
170
-func TestGenerateExisting(t *testing.T) {
177
+func (tp *provider) TestGenerateExisting(t *testing.T) {
178
ctx := context.Background()
172
- api, err := makeAPI(ctx)
179
+ api, err := tp.makeAPI(ctx)
180
if err != nil {
181
t.Error(err)
182
}
@@ -199,9 +206,9 @@ func TestGenerateExisting(t *testing.T) {
206
}
207
}
208
202
-func TestList(t *testing.T) {
209
+func (tp *provider) TestList(t *testing.T) {
210
ctx := context.Background()
204
- api, err := makeAPI(ctx)
211
+ api, err := tp.makeAPI(ctx)
212
if err != nil {
213
t.Error(err)
214
}
@@ -244,9 +251,9 @@ func TestList(t *testing.T) {
251
}
252
}
253
247
-func TestRename(t *testing.T) {
254
+func (tp *provider) TestRename(t *testing.T) {
255
ctx := context.Background()
249
- api, err := makeAPI(ctx)
256
+ api, err := tp.makeAPI(ctx)
257
if err != nil {
258
t.Error(err)
259
}
@@ -272,9 +279,9 @@ func TestRename(t *testing.T) {
279
}
280
}
281
275
-func TestRenameToSelf(t *testing.T) {
282
+func (tp *provider) TestRenameToSelf(t *testing.T) {
283
ctx := context.Background()
277
- api, err := makeAPI(ctx)
284
+ api, err := tp.makeAPI(ctx)
285
if err != nil {
286
t.Error(err)
287
}
@@ -295,9 +302,9 @@ func TestRenameToSelf(t *testing.T) {
302
}
303
}
304
298
-func TestRenameToSelfForce(t *testing.T) {
305
+func (tp *provider) TestRenameToSelfForce(t *testing.T) {
306
ctx := context.Background()
300
- api, err := makeAPI(ctx)
307
+ api, err := tp.makeAPI(ctx)
308
if err != nil {
309
t.Error(err)
310
}
@@ -318,9 +325,9 @@ func TestRenameToSelfForce(t *testing.T) {
325
}
326
}
327
321
-func TestRenameOverwriteNoForce(t *testing.T) {
328
+func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
329
ctx := context.Background()
323
- api, err := makeAPI(ctx)
330
+ api, err := tp.makeAPI(ctx)
331
if err != nil {
332
t.Error(err)
333
}
@@ -347,9 +354,9 @@ func TestRenameOverwriteNoForce(t *testing.T) {
354
}
355
}
356
350
-func TestRenameOverwrite(t *testing.T) {
357
+func (tp *provider) TestRenameOverwrite(t *testing.T) {
358
ctx := context.Background()
352
- api, err := makeAPI(ctx)
359
+ api, err := tp.makeAPI(ctx)
360
if err != nil {
361
t.Error(err)
362
}
@@ -385,9 +392,9 @@ func TestRenameOverwrite(t *testing.T) {
392
}
393
}
394
388
-func TestRenameSameNameNoForce(t *testing.T) {
395
+func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
396
ctx := context.Background()
390
- api, err := makeAPI(ctx)
397
+ api, err := tp.makeAPI(ctx)
398
if err != nil {
399
t.Error(err)
400
}
@@ -413,9 +420,9 @@ func TestRenameSameNameNoForce(t *testing.T) {
420
}
421
}
422
416
-func TestRenameSameName(t *testing.T) {
423
+func (tp *provider) TestRenameSameName(t *testing.T) {
424
ctx := context.Background()
418
- api, err := makeAPI(ctx)
425
+ api, err := tp.makeAPI(ctx)
426
if err != nil {
427
t.Error(err)
428
}
@@ -441,9 +448,9 @@ func TestRenameSameName(t *testing.T) {
448
}
449
}
450
444
-func TestRemove(t *testing.T) {
451
+func (tp *provider) TestRemove(t *testing.T) {
452
ctx := context.Background()
446
- api, err := makeAPI(ctx)
453
+ api, err := tp.makeAPI(ctx)
454
if err != nil {
455
t.Error(err)
456
}
core/coreapi/interface/tests/name.go
+10
-9
@@ -15,9 +15,10 @@ import (
15
opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
16
)
17
18
-func TestName(t *testing.T) {
19
- t.Run("TestPublishResolve", TestPublishResolve)
20
- t.Run("TestBasicPublishResolveKey", TestBasicPublishResolveKey)
18
+func (tp *provider) TestName(t *testing.T) {
19
+ t.Run("TestPublishResolve", tp.TestPublishResolve)
20
+ t.Run("TestBasicPublishResolveKey", tp.TestBasicPublishResolveKey)
21
+ t.Run("TestBasicPublishResolveTimeout", tp.TestBasicPublishResolveTimeout)
22
}
23
24
var rnd = rand.New(rand.NewSource(0x62796532303137))
@@ -34,10 +35,10 @@ func appendPath(p coreiface.Path, sub string) coreiface.Path {
35
return p
36
}
37
37
-func TestPublishResolve(t *testing.T) {
38
+func (tp *provider) TestPublishResolve(t *testing.T) {
39
ctx := context.Background()
40
init := func() (coreiface.CoreAPI, coreiface.Path) {
40
- apis, err := makeAPISwarm(ctx, true, 5)
41
+ apis, err := tp.MakeAPISwarm(ctx, true, 5)
42
if err != nil {
43
t.Fatal(err)
44
return nil, nil
@@ -183,9 +184,9 @@ func TestPublishResolve(t *testing.T) {
184
})
185
}
186
186
-func TestBasicPublishResolveKey(t *testing.T) {
187
+func (tp *provider) TestBasicPublishResolveKey(t *testing.T) {
188
ctx := context.Background()
188
- apis, err := makeAPISwarm(ctx, true, 5)
189
+ apis, err := tp.MakeAPISwarm(ctx, true, 5)
190
if err != nil {
191
t.Fatal(err)
192
}
@@ -224,11 +225,11 @@ func TestBasicPublishResolveKey(t *testing.T) {
225
}
226
}
227
227
-func TestBasicPublishResolveTimeout(t *testing.T) {
228
+func (tp *provider) TestBasicPublishResolveTimeout(t *testing.T) {
229
t.Skip("ValidTime doesn't appear to work at this time resolution")
230
231
ctx := context.Background()
231
- apis, err := makeAPISwarm(ctx, true, 5)
232
+ apis, err := tp.MakeAPISwarm(ctx, true, 5)
233
if err != nil {
234
t.Fatal(err)
235
}
core/coreapi/interface/tests/object.go
+37
-37
@@ -12,24 +12,24 @@ import (
12
opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
13
)
14
15
-func TestObject(t *testing.T) {
16
- t.Run("TestNew", TestNew)
17
- t.Run("TestObjectPut", TestObjectPut)
18
- t.Run("TestObjectGet", TestObjectGet)
19
- t.Run("TestObjectData", TestObjectData)
20
- t.Run("TestObjectLinks", TestObjectLinks)
21
- t.Run("TestObjectStat", TestObjectStat)
22
- t.Run("TestObjectAddLink", TestObjectAddLink)
23
- t.Run("TestObjectAddLinkCreate", TestObjectAddLinkCreate)
24
- t.Run("TestObjectRmLink", TestObjectRmLink)
25
- t.Run("TestObjectAddData", TestObjectAddData)
26
- t.Run("TestObjectSetData", TestObjectSetData)
27
- t.Run("TestDiffTest", TestDiffTest)
15
+func (tp *provider) TestObject(t *testing.T) {
16
+ t.Run("TestNew", tp.TestNew)
17
+ t.Run("TestObjectPut", tp.TestObjectPut)
18
+ t.Run("TestObjectGet", tp.TestObjectGet)
19
+ t.Run("TestObjectData", tp.TestObjectData)
20
+ t.Run("TestObjectLinks", tp.TestObjectLinks)
21
+ t.Run("TestObjectStat", tp.TestObjectStat)
22
+ t.Run("TestObjectAddLink", tp.TestObjectAddLink)
23
+ t.Run("TestObjectAddLinkCreate", tp.TestObjectAddLinkCreate)
24
+ t.Run("TestObjectRmLink", tp.TestObjectRmLink)
25
+ t.Run("TestObjectAddData", tp.TestObjectAddData)
26
+ t.Run("TestObjectSetData", tp.TestObjectSetData)
27
+ t.Run("TestDiffTest", tp.TestDiffTest)
28
}
29
30
-func TestNew(t *testing.T) {
30
+func (tp *provider) TestNew(t *testing.T) {
31
ctx := context.Background()
32
- api, err := makeAPI(ctx)
32
+ api, err := tp.makeAPI(ctx)
33
if err != nil {
34
t.Fatal(err)
35
}
@@ -53,9 +53,9 @@ func TestNew(t *testing.T) {
53
}
54
}
55
56
-func TestObjectPut(t *testing.T) {
56
+func (tp *provider) TestObjectPut(t *testing.T) {
57
ctx := context.Background()
58
- api, err := makeAPI(ctx)
58
+ api, err := tp.makeAPI(ctx)
59
if err != nil {
60
t.Fatal(err)
61
}
@@ -93,9 +93,9 @@ func TestObjectPut(t *testing.T) {
93
}
94
}
95
96
-func TestObjectGet(t *testing.T) {
96
+func (tp *provider) TestObjectGet(t *testing.T) {
97
ctx := context.Background()
98
- api, err := makeAPI(ctx)
98
+ api, err := tp.makeAPI(ctx)
99
if err != nil {
100
t.Fatal(err)
101
}
@@ -115,9 +115,9 @@ func TestObjectGet(t *testing.T) {
115
}
116
}
117
118
-func TestObjectData(t *testing.T) {
118
+func (tp *provider) TestObjectData(t *testing.T) {
119
ctx := context.Background()
120
- api, err := makeAPI(ctx)
120
+ api, err := tp.makeAPI(ctx)
121
if err != nil {
122
t.Fatal(err)
123
}
@@ -142,9 +142,9 @@ func TestObjectData(t *testing.T) {
142
}
143
}
144
145
-func TestObjectLinks(t *testing.T) {
145
+func (tp *provider) TestObjectLinks(t *testing.T) {
146
ctx := context.Background()
147
- api, err := makeAPI(ctx)
147
+ api, err := tp.makeAPI(ctx)
148
if err != nil {
149
t.Fatal(err)
150
}
@@ -177,9 +177,9 @@ func TestObjectLinks(t *testing.T) {
177
}
178
}
179
180
-func TestObjectStat(t *testing.T) {
180
+func (tp *provider) TestObjectStat(t *testing.T) {
181
ctx := context.Background()
182
- api, err := makeAPI(ctx)
182
+ api, err := tp.makeAPI(ctx)
183
if err != nil {
184
t.Fatal(err)
185
}
@@ -224,9 +224,9 @@ func TestObjectStat(t *testing.T) {
224
}
225
}
226
227
-func TestObjectAddLink(t *testing.T) {
227
+func (tp *provider) TestObjectAddLink(t *testing.T) {
228
ctx := context.Background()
229
- api, err := makeAPI(ctx)
229
+ api, err := tp.makeAPI(ctx)
230
if err != nil {
231
t.Fatal(err)
232
}
@@ -264,9 +264,9 @@ func TestObjectAddLink(t *testing.T) {
264
}
265
}
266
267
-func TestObjectAddLinkCreate(t *testing.T) {
267
+func (tp *provider) TestObjectAddLinkCreate(t *testing.T) {
268
ctx := context.Background()
269
- api, err := makeAPI(ctx)
269
+ api, err := tp.makeAPI(ctx)
270
if err != nil {
271
t.Fatal(err)
272
}
@@ -312,9 +312,9 @@ func TestObjectAddLinkCreate(t *testing.T) {
312
}
313
}
314
315
-func TestObjectRmLink(t *testing.T) {
315
+func (tp *provider) TestObjectRmLink(t *testing.T) {
316
ctx := context.Background()
317
- api, err := makeAPI(ctx)
317
+ api, err := tp.makeAPI(ctx)
318
if err != nil {
319
t.Fatal(err)
320
}
@@ -344,9 +344,9 @@ func TestObjectRmLink(t *testing.T) {
344
}
345
}
346
347
-func TestObjectAddData(t *testing.T) {
347
+func (tp *provider) TestObjectAddData(t *testing.T) {
348
ctx := context.Background()
349
- api, err := makeAPI(ctx)
349
+ api, err := tp.makeAPI(ctx)
350
if err != nil {
351
t.Fatal(err)
352
}
@@ -373,9 +373,9 @@ func TestObjectAddData(t *testing.T) {
373
}
374
}
375
376
-func TestObjectSetData(t *testing.T) {
376
+func (tp *provider) TestObjectSetData(t *testing.T) {
377
ctx := context.Background()
378
- api, err := makeAPI(ctx)
378
+ api, err := tp.makeAPI(ctx)
379
if err != nil {
380
t.Fatal(err)
381
}
@@ -402,9 +402,9 @@ func TestObjectSetData(t *testing.T) {
402
}
403
}
404
405
-func TestDiffTest(t *testing.T) {
405
+func (tp *provider) TestDiffTest(t *testing.T) {
406
ctx := context.Background()
407
- api, err := makeAPI(ctx)
407
+ api, err := tp.makeAPI(ctx)
408
if err != nil {
409
t.Fatal(err)
410
}
core/coreapi/interface/tests/path.go
+16
-16
@@ -9,17 +9,17 @@ import (
9
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
10
)
11
12
-func TestPath(t *testing.T) {
13
- t.Run("TestMutablePath", TestMutablePath)
14
- t.Run("TestPathRemainder", TestPathRemainder)
15
- t.Run("TestEmptyPathRemainder", TestEmptyPathRemainder)
16
- t.Run("TestInvalidPathRemainder", TestInvalidPathRemainder)
17
- t.Run("TestPathRoot", TestPathRoot)
12
+func (tp *provider) TestPath(t *testing.T) {
13
+ t.Run("TestMutablePath", tp.TestMutablePath)
14
+ t.Run("TestPathRemainder", tp.TestPathRemainder)
15
+ t.Run("TestEmptyPathRemainder", tp.TestEmptyPathRemainder)
16
+ t.Run("TestInvalidPathRemainder", tp.TestInvalidPathRemainder)
17
+ t.Run("TestPathRoot", tp.TestPathRoot)
18
}
19
20
-func TestMutablePath(t *testing.T) {
20
+func (tp *provider) TestMutablePath(t *testing.T) {
21
ctx := context.Background()
22
- api, err := makeAPI(ctx)
22
+ api, err := tp.makeAPI(ctx)
23
if err != nil {
24
t.Fatal(err)
25
}
@@ -44,9 +44,9 @@ func TestMutablePath(t *testing.T) {
44
}
45
}
46
47
-func TestPathRemainder(t *testing.T) {
47
+func (tp *provider) TestPathRemainder(t *testing.T) {
48
ctx := context.Background()
49
- api, err := makeAPI(ctx)
49
+ api, err := tp.makeAPI(ctx)
50
if err != nil {
51
t.Fatal(err)
52
}
@@ -71,9 +71,9 @@ func TestPathRemainder(t *testing.T) {
71
}
72
}
73
74
-func TestEmptyPathRemainder(t *testing.T) {
74
+func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
75
ctx := context.Background()
76
- api, err := makeAPI(ctx)
76
+ api, err := tp.makeAPI(ctx)
77
if err != nil {
78
t.Fatal(err)
79
}
@@ -102,9 +102,9 @@ func TestEmptyPathRemainder(t *testing.T) {
102
}
103
}
104
105
-func TestInvalidPathRemainder(t *testing.T) {
105
+func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
106
ctx := context.Background()
107
- api, err := makeAPI(ctx)
107
+ api, err := tp.makeAPI(ctx)
108
if err != nil {
109
t.Fatal(err)
110
}
@@ -125,9 +125,9 @@ func TestInvalidPathRemainder(t *testing.T) {
125
}
126
}
127
128
-func TestPathRoot(t *testing.T) {
128
+func (tp *provider) TestPathRoot(t *testing.T) {
129
ctx := context.Background()
130
- api, err := makeAPI(ctx)
130
+ api, err := tp.makeAPI(ctx)
131
if err != nil {
132
t.Fatal(err)
133
}
core/coreapi/interface/tests/pin.go
+10
-10
@@ -8,15 +8,15 @@ import (
8
opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9
)
10
11
-func TestPin(t *testing.T) {
12
- t.Run("TestPinAdd", TestPinAdd)
13
- t.Run("TestPinSimple", TestPinSimple)
14
- t.Run("TestPinRecursive", TestPinRecursive)
11
+func (tp *provider) TestPin(t *testing.T) {
12
+ t.Run("TestPinAdd", tp.TestPinAdd)
13
+ t.Run("TestPinSimple", tp.TestPinSimple)
14
+ t.Run("TestPinRecursive", tp.TestPinRecursive)
15
}
16
17
-func TestPinAdd(t *testing.T) {
17
+func (tp *provider) TestPinAdd(t *testing.T) {
18
ctx := context.Background()
19
- api, err := makeAPI(ctx)
19
+ api, err := tp.makeAPI(ctx)
20
if err != nil {
21
t.Error(err)
22
}
@@ -32,9 +32,9 @@ func TestPinAdd(t *testing.T) {
32
}
33
}
34
35
-func TestPinSimple(t *testing.T) {
35
+func (tp *provider) TestPinSimple(t *testing.T) {
36
ctx := context.Background()
37
- api, err := makeAPI(ctx)
37
+ api, err := tp.makeAPI(ctx)
38
if err != nil {
39
t.Error(err)
40
}
@@ -81,9 +81,9 @@ func TestPinSimple(t *testing.T) {
81
}
82
}
83
84
-func TestPinRecursive(t *testing.T) {
84
+func (tp *provider) TestPinRecursive(t *testing.T) {
85
ctx := context.Background()
86
- api, err := makeAPI(ctx)
86
+ api, err := tp.makeAPI(ctx)
87
if err != nil {
88
t.Error(err)
89
}
core/coreapi/interface/tests/pubsub.go
+4
-4
@@ -7,15 +7,15 @@ import (
7
"time"
8
)
9
10
-func TestPubSub(t *testing.T) {
11
- t.Run("TestBasicPubSub", TestBasicPubSub)
10
+func (tp *provider) TestPubSub(t *testing.T) {
11
+ t.Run("TestBasicPubSub", tp.TestBasicPubSub)
12
}
13
14
-func TestBasicPubSub(t *testing.T) {
14
+func (tp *provider) TestBasicPubSub(t *testing.T) {
15
ctx, cancel := context.WithCancel(context.Background())
16
defer cancel()
17
18
- apis, err := makeAPISwarm(ctx, true, 2)
18
+ apis, err := tp.MakeAPISwarm(ctx, true, 2)
19
if err != nil {
20
t.Fatal(err)
21
}
core/coreapi/interface/tests/unixfs.go
+34
-36
@@ -23,22 +23,20 @@ import (
23
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
24
)
25
26
-func TestUnixfs(t *testing.T) {
27
- t.Run("TestAdd", TestAdd)
28
- t.Run("TestAddPinned", TestAddPinned)
29
- t.Run("TestAddHashOnly", TestAddHashOnly)
30
- t.Run("TestGetEmptyFile", TestGetEmptyFile)
31
- t.Run("TestGetDir", TestGetDir)
32
- t.Run("TestGetNonUnixfs", TestGetNonUnixfs)
33
- t.Run("TestLs", TestLs)
34
- t.Run("TestEntriesExpired", TestEntriesExpired)
35
- t.Run("TestLsEmptyDir", TestLsEmptyDir)
36
- t.Run("TestLsNonUnixfs", TestLsNonUnixfs)
37
- t.Run("TestAddCloses", TestAddCloses)
26
+func (tp *provider) TestUnixfs(t *testing.T) {
27
+ t.Run("TestAdd", tp.TestAdd)
28
+ t.Run("TestAddPinned", tp.TestAddPinned)
29
+ t.Run("TestAddHashOnly", tp.TestAddHashOnly)
30
+ t.Run("TestGetEmptyFile", tp.TestGetEmptyFile)
31
+ t.Run("TestGetDir", tp.TestGetDir)
32
+ t.Run("TestGetNonUnixfs", tp.TestGetNonUnixfs)
33
+ t.Run("TestLs", tp.TestLs)
34
+ t.Run("TestEntriesExpired", tp.TestEntriesExpired)
35
+ t.Run("TestLsEmptyDir", tp.TestLsEmptyDir)
36
+ t.Run("TestLsNonUnixfs", tp.TestLsNonUnixfs)
37
+ t.Run("TestAddCloses", tp.TestAddCloses)
38
}
39
40
-const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
41
-
40
// `echo -n 'hello, world!' | ipfs add`
41
var hello = "/ipfs/QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk"
42
var helloStr = "hello, world!"
@@ -80,9 +78,9 @@ func wrapped(name string) func(f files.Node) files.Node {
78
}
79
}
80
83
-func TestAdd(t *testing.T) {
81
+func (tp *provider) TestAdd(t *testing.T) {
82
ctx := context.Background()
85
- api, err := makeAPI(ctx)
83
+ api, err := tp.makeAPI(ctx)
84
if err != nil {
85
t.Error(err)
86
}
@@ -537,9 +535,9 @@ func TestAdd(t *testing.T) {
535
}
536
}
537
540
-func TestAddPinned(t *testing.T) {
538
+func (tp *provider) TestAddPinned(t *testing.T) {
539
ctx := context.Background()
542
- api, err := makeAPI(ctx)
540
+ api, err := tp.makeAPI(ctx)
541
if err != nil {
542
t.Error(err)
543
}
@@ -559,9 +557,9 @@ func TestAddPinned(t *testing.T) {
557
}
558
}
559
562
-func TestAddHashOnly(t *testing.T) {
560
+func (tp *provider) TestAddHashOnly(t *testing.T) {
561
ctx := context.Background()
564
- api, err := makeAPI(ctx)
562
+ api, err := tp.makeAPI(ctx)
563
if err != nil {
564
t.Error(err)
565
}
@@ -584,9 +582,9 @@ func TestAddHashOnly(t *testing.T) {
582
}
583
}
584
587
-func TestGetEmptyFile(t *testing.T) {
585
+func (tp *provider) TestGetEmptyFile(t *testing.T) {
586
ctx := context.Background()
589
- api, err := makeAPI(ctx)
587
+ api, err := tp.makeAPI(ctx)
588
if err != nil {
589
t.Fatal(err)
590
}
@@ -616,9 +614,9 @@ func TestGetEmptyFile(t *testing.T) {
614
}
615
}
616
619
-func TestGetDir(t *testing.T) {
617
+func (tp *provider) TestGetDir(t *testing.T) {
618
ctx := context.Background()
621
- api, err := makeAPI(ctx)
619
+ api, err := tp.makeAPI(ctx)
620
if err != nil {
621
t.Error(err)
622
}
@@ -648,9 +646,9 @@ func TestGetDir(t *testing.T) {
646
}
647
}
648
651
-func TestGetNonUnixfs(t *testing.T) {
649
+func (tp *provider) TestGetNonUnixfs(t *testing.T) {
650
ctx := context.Background()
653
- api, err := makeAPI(ctx)
651
+ api, err := tp.makeAPI(ctx)
652
if err != nil {
653
t.Error(err)
654
}
@@ -667,9 +665,9 @@ func TestGetNonUnixfs(t *testing.T) {
665
}
666
}
667
670
-func TestLs(t *testing.T) {
668
+func (tp *provider) TestLs(t *testing.T) {
669
ctx := context.Background()
672
- api, err := makeAPI(ctx)
670
+ api, err := tp.makeAPI(ctx)
671
if err != nil {
672
t.Error(err)
673
}
@@ -703,9 +701,9 @@ func TestLs(t *testing.T) {
701
}
702
}
703
706
-func TestEntriesExpired(t *testing.T) {
704
+func (tp *provider) TestEntriesExpired(t *testing.T) {
705
ctx := context.Background()
708
- api, err := makeAPI(ctx)
706
+ api, err := tp.makeAPI(ctx)
707
if err != nil {
708
t.Error(err)
709
}
@@ -746,9 +744,9 @@ func TestEntriesExpired(t *testing.T) {
744
}
745
}
746
749
-func TestLsEmptyDir(t *testing.T) {
747
+func (tp *provider) TestLsEmptyDir(t *testing.T) {
748
ctx := context.Background()
751
- api, err := makeAPI(ctx)
749
+ api, err := tp.makeAPI(ctx)
750
if err != nil {
751
t.Error(err)
752
}
@@ -774,9 +772,9 @@ func TestLsEmptyDir(t *testing.T) {
772
}
773
774
// TODO(lgierth) this should test properly, with len(links) > 0
777
-func TestLsNonUnixfs(t *testing.T) {
775
+func (tp *provider) TestLsNonUnixfs(t *testing.T) {
776
ctx := context.Background()
779
- api, err := makeAPI(ctx)
777
+ api, err := tp.makeAPI(ctx)
778
if err != nil {
779
t.Error(err)
780
}
@@ -831,9 +829,9 @@ func (f *closeTestF) Close() error {
829
return nil
830
}
831
834
-func TestAddCloses(t *testing.T) {
832
+func (tp *provider) TestAddCloses(t *testing.T) {
833
ctx := context.Background()
836
- api, err := makeAPI(ctx)
834
+ api, err := tp.makeAPI(ctx)
835
if err != nil {
836
t.Error(err)
837
}
core/coreapi/test/api_test.go
+105
-1
@@ -1,10 +1,114 @@
1
package test
2
3
import (
4
+ "context"
5
+ "encoding/base64"
6
+ "fmt"
7
"github.com/ipfs/go-ipfs/core/coreapi/interface/tests"
8
"testing"
9
+
10
+ "github.com/ipfs/go-ipfs/core"
11
+ "github.com/ipfs/go-ipfs/core/coreapi"
12
+ coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
13
+ mock "github.com/ipfs/go-ipfs/core/mock"
14
+ "github.com/ipfs/go-ipfs/keystore"
15
+ "github.com/ipfs/go-ipfs/repo"
16
+
17
+ ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
18
+ "gx/ipfs/QmRBaUEQEeFWywfrZJ64QgsmvcqgLSK3VbvGMR2NM2Edpf/go-libp2p/p2p/net/mock"
19
+ "gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
20
+ pstore "gx/ipfs/QmZ9zH2FnLcxv1xyzFeUpDUeo55xEhZQHgveZijcxr7TLj/go-libp2p-peerstore"
21
+ "gx/ipfs/QmcZfkbgwwwH5ZLTQRHkSQBDiDqd3skY2eU6MZRgWuXcse/go-ipfs-config"
22
+ "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore"
23
+ syncds "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore/sync"
24
)
25
26
+const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
27
+
28
+type NodeProvider struct{}
29
+
30
+func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
31
+ mn := mocknet.New(ctx)
32
+
33
+ nodes := make([]*core.IpfsNode, n)
34
+ apis := make([]coreiface.CoreAPI, n)
35
+
36
+ for i := 0; i < n; i++ {
37
+ var ident config.Identity
38
+ if fullIdentity {
39
+ sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
40
+ if err != nil {
41
+ return nil, err
42
+ }
43
+
44
+ id, err := peer.IDFromPublicKey(pk)
45
+ if err != nil {
46
+ return nil, err
47
+ }
48
+
49
+ kbytes, err := sk.Bytes()
50
+ if err != nil {
51
+ return nil, err
52
+ }
53
+
54
+ ident = config.Identity{
55
+ PeerID: id.Pretty(),
56
+ PrivKey: base64.StdEncoding.EncodeToString(kbytes),
57
+ }
58
+ } else {
59
+ ident = config.Identity{
60
+ PeerID: testPeerID,
61
+ }
62
+ }
63
+
64
+ c := config.Config{}
65
+ c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
66
+ c.Identity = ident
67
+
68
+ r := &repo.Mock{
69
+ C: c,
70
+ D: syncds.MutexWrap(datastore.NewMapDatastore()),
71
+ K: keystore.NewMemKeystore(),
72
+ }
73
+
74
+ node, err := core.NewNode(ctx, &core.BuildCfg{
75
+ Repo: r,
76
+ Host: mock.MockHostOption(mn),
77
+ Online: fullIdentity,
78
+ ExtraOpts: map[string]bool{
79
+ "pubsub": true,
80
+ },
81
+ })
82
+ if err != nil {
83
+ return nil, err
84
+ }
85
+ nodes[i] = node
86
+ apis[i], err = coreapi.NewCoreAPI(node)
87
+ if err != nil {
88
+ return nil, err
89
+ }
90
+ }
91
+
92
+ err := mn.LinkAll()
93
+ if err != nil {
94
+ return nil, err
95
+ }
96
+
97
+ bsinf := core.BootstrapConfigWithPeers(
98
+ []pstore.PeerInfo{
99
+ nodes[0].Peerstore.PeerInfo(nodes[0].Identity),
100
+ },
101
+ )
102
+
103
+ for _, n := range nodes[1:] {
104
+ if err := n.Bootstrap(bsinf); err != nil {
105
+ return nil, err
106
+ }
107
+ }
108
+
109
+ return apis, nil
110
+}
111
+
112
func TestIface(t *testing.T) {
9
- tests.TestApi(t)
113
+ tests.TestApi(&NodeProvider{})(t)
114
}