Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit 103b645

Browse files
authored
Merge pull request #34 from ipfs/feat/expose-tests
tests: expose TestSuite
2 parents 5d8d216 + 6fe8577 commit 103b645

11 files changed

+90
-88
lines changed

tests/api.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
var apiNotImplemented = errors.New("api not implemented")
1313

14-
func (tp *provider) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
14+
func (tp *TestSuite) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
1515
api, err := tp.MakeAPISwarm(ctx, false, 1)
1616
if err != nil {
1717
return nil, err
@@ -25,17 +25,19 @@ type Provider interface {
2525
MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error)
2626
}
2727

28-
func (tp *provider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
29-
tp.apis <- 1
30-
go func() {
31-
<-ctx.Done()
32-
tp.apis <- -1
33-
}()
28+
func (tp *TestSuite) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
29+
if tp.apis != nil {
30+
tp.apis <- 1
31+
go func() {
32+
<-ctx.Done()
33+
tp.apis <- -1
34+
}()
35+
}
3436

3537
return tp.Provider.MakeAPISwarm(ctx, fullIdentity, n)
3638
}
3739

38-
type provider struct {
40+
type TestSuite struct {
3941
Provider
4042

4143
apis chan int
@@ -55,7 +57,7 @@ func TestApi(p Provider) func(t *testing.T) {
5557
}
5658
}()
5759

58-
tp := &provider{Provider: p, apis: apis}
60+
tp := &TestSuite{Provider: p, apis: apis}
5961

6062
return func(t *testing.T) {
6163
t.Run("Block", tp.TestBlock)
@@ -80,7 +82,7 @@ func TestApi(p Provider) func(t *testing.T) {
8082
}
8183
}
8284

83-
func (tp *provider) hasApi(t *testing.T, tf func(coreiface.CoreAPI) error) {
85+
func (tp *TestSuite) hasApi(t *testing.T, tf func(coreiface.CoreAPI) error) {
8486
ctx, cancel := context.WithCancel(context.Background())
8587
defer cancel()
8688
api, err := tp.makeAPI(ctx)

tests/block.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
mh "github.com/multiformats/go-multihash"
1414
)
1515

16-
func (tp *provider) TestBlock(t *testing.T) {
16+
func (tp *TestSuite) TestBlock(t *testing.T) {
1717
tp.hasApi(t, func(api coreiface.CoreAPI) error {
1818
if api.Block() == nil {
1919
return apiNotImplemented
@@ -30,7 +30,7 @@ func (tp *provider) TestBlock(t *testing.T) {
3030
t.Run("TestBlockPin", tp.TestBlockPin)
3131
}
3232

33-
func (tp *provider) TestBlockPut(t *testing.T) {
33+
func (tp *TestSuite) TestBlockPut(t *testing.T) {
3434
ctx, cancel := context.WithCancel(context.Background())
3535
defer cancel()
3636
api, err := tp.makeAPI(ctx)
@@ -48,7 +48,7 @@ func (tp *provider) TestBlockPut(t *testing.T) {
4848
}
4949
}
5050

51-
func (tp *provider) TestBlockPutFormat(t *testing.T) {
51+
func (tp *TestSuite) TestBlockPutFormat(t *testing.T) {
5252
ctx, cancel := context.WithCancel(context.Background())
5353
defer cancel()
5454
api, err := tp.makeAPI(ctx)
@@ -66,7 +66,7 @@ func (tp *provider) TestBlockPutFormat(t *testing.T) {
6666
}
6767
}
6868

69-
func (tp *provider) TestBlockPutHash(t *testing.T) {
69+
func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
7070
ctx, cancel := context.WithCancel(context.Background())
7171
defer cancel()
7272
api, err := tp.makeAPI(ctx)
@@ -84,7 +84,7 @@ func (tp *provider) TestBlockPutHash(t *testing.T) {
8484
}
8585
}
8686

87-
func (tp *provider) TestBlockGet(t *testing.T) {
87+
func (tp *TestSuite) TestBlockGet(t *testing.T) {
8888
ctx, cancel := context.WithCancel(context.Background())
8989
defer cancel()
9090
api, err := tp.makeAPI(ctx)
@@ -122,7 +122,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
122122
}
123123
}
124124

125-
func (tp *provider) TestBlockRm(t *testing.T) {
125+
func (tp *TestSuite) TestBlockRm(t *testing.T) {
126126
ctx, cancel := context.WithCancel(context.Background())
127127
defer cancel()
128128
api, err := tp.makeAPI(ctx)
@@ -176,7 +176,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
176176
}
177177
}
178178

179-
func (tp *provider) TestBlockStat(t *testing.T) {
179+
func (tp *TestSuite) TestBlockStat(t *testing.T) {
180180
ctx, cancel := context.WithCancel(context.Background())
181181
defer cancel()
182182
api, err := tp.makeAPI(ctx)
@@ -203,7 +203,7 @@ func (tp *provider) TestBlockStat(t *testing.T) {
203203
}
204204
}
205205

206-
func (tp *provider) TestBlockPin(t *testing.T) {
206+
func (tp *TestSuite) TestBlockPin(t *testing.T) {
207207
ctx, cancel := context.WithCancel(context.Background())
208208
defer cancel()
209209
api, err := tp.makeAPI(ctx)

tests/dag.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
mh "github.com/multiformats/go-multihash"
1616
)
1717

18-
func (tp *provider) TestDag(t *testing.T) {
18+
func (tp *TestSuite) TestDag(t *testing.T) {
1919
tp.hasApi(t, func(api coreiface.CoreAPI) error {
2020
if api.Dag() == nil {
2121
return apiNotImplemented
@@ -40,7 +40,7 @@ var (
4040
}
4141
)
4242

43-
func (tp *provider) TestPut(t *testing.T) {
43+
func (tp *TestSuite) TestPut(t *testing.T) {
4444
ctx, cancel := context.WithCancel(context.Background())
4545
defer cancel()
4646
api, err := tp.makeAPI(ctx)
@@ -63,7 +63,7 @@ func (tp *provider) TestPut(t *testing.T) {
6363
}
6464
}
6565

66-
func (tp *provider) TestPutWithHash(t *testing.T) {
66+
func (tp *TestSuite) TestPutWithHash(t *testing.T) {
6767
ctx, cancel := context.WithCancel(context.Background())
6868
defer cancel()
6969
api, err := tp.makeAPI(ctx)
@@ -86,7 +86,7 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
8686
}
8787
}
8888

89-
func (tp *provider) TestDagPath(t *testing.T) {
89+
func (tp *TestSuite) TestDagPath(t *testing.T) {
9090
ctx, cancel := context.WithCancel(context.Background())
9191
defer cancel()
9292
api, err := tp.makeAPI(ctx)
@@ -131,7 +131,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
131131
}
132132
}
133133

134-
func (tp *provider) TestTree(t *testing.T) {
134+
func (tp *TestSuite) TestTree(t *testing.T) {
135135
ctx, cancel := context.WithCancel(context.Background())
136136
defer cancel()
137137
api, err := tp.makeAPI(ctx)
@@ -166,7 +166,7 @@ func (tp *provider) TestTree(t *testing.T) {
166166
}
167167
}
168168

169-
func (tp *provider) TestBatch(t *testing.T) {
169+
func (tp *TestSuite) TestBatch(t *testing.T) {
170170
ctx, cancel := context.WithCancel(context.Background())
171171
defer cancel()
172172
api, err := tp.makeAPI(ctx)

tests/dht.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/ipfs/interface-go-ipfs-core/options"
1010
)
1111

12-
func (tp *provider) TestDht(t *testing.T) {
12+
func (tp *TestSuite) TestDht(t *testing.T) {
1313
tp.hasApi(t, func(api iface.CoreAPI) error {
1414
if api.Dht() == nil {
1515
return apiNotImplemented
@@ -22,7 +22,7 @@ func (tp *provider) TestDht(t *testing.T) {
2222
t.Run("TestDhtProvide", tp.TestDhtProvide)
2323
}
2424

25-
func (tp *provider) TestDhtFindPeer(t *testing.T) {
25+
func (tp *TestSuite) TestDhtFindPeer(t *testing.T) {
2626
ctx, cancel := context.WithCancel(context.Background())
2727
defer cancel()
2828
apis, err := tp.MakeAPISwarm(ctx, true, 5)
@@ -75,7 +75,7 @@ func (tp *provider) TestDhtFindPeer(t *testing.T) {
7575
}
7676
}
7777

78-
func (tp *provider) TestDhtFindProviders(t *testing.T) {
78+
func (tp *TestSuite) TestDhtFindProviders(t *testing.T) {
7979
ctx, cancel := context.WithCancel(context.Background())
8080
defer cancel()
8181
apis, err := tp.MakeAPISwarm(ctx, true, 5)
@@ -105,7 +105,7 @@ func (tp *provider) TestDhtFindProviders(t *testing.T) {
105105
}
106106
}
107107

108-
func (tp *provider) TestDhtProvide(t *testing.T) {
108+
func (tp *TestSuite) TestDhtProvide(t *testing.T) {
109109
ctx, cancel := context.WithCancel(context.Background())
110110
defer cancel()
111111
apis, err := tp.MakeAPISwarm(ctx, true, 5)

tests/key.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
opt "github.com/ipfs/interface-go-ipfs-core/options"
1010
)
1111

12-
func (tp *provider) TestKey(t *testing.T) {
12+
func (tp *TestSuite) TestKey(t *testing.T) {
1313
tp.hasApi(t, func(api iface.CoreAPI) error {
1414
if api.Key() == nil {
1515
return apiNotImplemented
@@ -35,7 +35,7 @@ func (tp *provider) TestKey(t *testing.T) {
3535
t.Run("TestRemove", tp.TestRemove)
3636
}
3737

38-
func (tp *provider) TestListSelf(t *testing.T) {
38+
func (tp *TestSuite) TestListSelf(t *testing.T) {
3939
ctx, cancel := context.WithCancel(context.Background())
4040
defer cancel()
4141
api, err := tp.makeAPI(ctx)
@@ -69,7 +69,7 @@ func (tp *provider) TestListSelf(t *testing.T) {
6969
}
7070
}
7171

72-
func (tp *provider) TestRenameSelf(t *testing.T) {
72+
func (tp *TestSuite) TestRenameSelf(t *testing.T) {
7373
ctx, cancel := context.WithCancel(context.Background())
7474
defer cancel()
7575
api, err := tp.makeAPI(ctx)
@@ -97,7 +97,7 @@ func (tp *provider) TestRenameSelf(t *testing.T) {
9797
}
9898
}
9999

100-
func (tp *provider) TestRemoveSelf(t *testing.T) {
100+
func (tp *TestSuite) TestRemoveSelf(t *testing.T) {
101101
ctx, cancel := context.WithCancel(context.Background())
102102
defer cancel()
103103
api, err := tp.makeAPI(ctx)
@@ -116,7 +116,7 @@ func (tp *provider) TestRemoveSelf(t *testing.T) {
116116
}
117117
}
118118

119-
func (tp *provider) TestGenerate(t *testing.T) {
119+
func (tp *TestSuite) TestGenerate(t *testing.T) {
120120
ctx, cancel := context.WithCancel(context.Background())
121121
defer cancel()
122122
api, err := tp.makeAPI(ctx)
@@ -139,7 +139,7 @@ func (tp *provider) TestGenerate(t *testing.T) {
139139
}
140140
}
141141

142-
func (tp *provider) TestGenerateSize(t *testing.T) {
142+
func (tp *TestSuite) TestGenerateSize(t *testing.T) {
143143
ctx, cancel := context.WithCancel(context.Background())
144144
defer cancel()
145145
api, err := tp.makeAPI(ctx)
@@ -162,7 +162,7 @@ func (tp *provider) TestGenerateSize(t *testing.T) {
162162
}
163163
}
164164

165-
func (tp *provider) TestGenerateType(t *testing.T) {
165+
func (tp *TestSuite) TestGenerateType(t *testing.T) {
166166
ctx, cancel := context.WithCancel(context.Background())
167167
defer cancel()
168168
t.Skip("disabled until libp2p/specs#111 is fixed")
@@ -188,7 +188,7 @@ func (tp *provider) TestGenerateType(t *testing.T) {
188188
}
189189
}
190190

191-
func (tp *provider) TestGenerateExisting(t *testing.T) {
191+
func (tp *TestSuite) TestGenerateExisting(t *testing.T) {
192192
ctx, cancel := context.WithCancel(context.Background())
193193
defer cancel()
194194
api, err := tp.makeAPI(ctx)
@@ -221,7 +221,7 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
221221
}
222222
}
223223

224-
func (tp *provider) TestList(t *testing.T) {
224+
func (tp *TestSuite) TestList(t *testing.T) {
225225
ctx, cancel := context.WithCancel(context.Background())
226226
defer cancel()
227227
api, err := tp.makeAPI(ctx)
@@ -267,7 +267,7 @@ func (tp *provider) TestList(t *testing.T) {
267267
}
268268
}
269269

270-
func (tp *provider) TestRename(t *testing.T) {
270+
func (tp *TestSuite) TestRename(t *testing.T) {
271271
ctx, cancel := context.WithCancel(context.Background())
272272
defer cancel()
273273
api, err := tp.makeAPI(ctx)
@@ -296,7 +296,7 @@ func (tp *provider) TestRename(t *testing.T) {
296296
}
297297
}
298298

299-
func (tp *provider) TestRenameToSelf(t *testing.T) {
299+
func (tp *TestSuite) TestRenameToSelf(t *testing.T) {
300300
ctx, cancel := context.WithCancel(context.Background())
301301
defer cancel()
302302
api, err := tp.makeAPI(ctx)
@@ -320,7 +320,7 @@ func (tp *provider) TestRenameToSelf(t *testing.T) {
320320
}
321321
}
322322

323-
func (tp *provider) TestRenameToSelfForce(t *testing.T) {
323+
func (tp *TestSuite) TestRenameToSelfForce(t *testing.T) {
324324
ctx, cancel := context.WithCancel(context.Background())
325325
defer cancel()
326326
api, err := tp.makeAPI(ctx)
@@ -344,7 +344,7 @@ func (tp *provider) TestRenameToSelfForce(t *testing.T) {
344344
}
345345
}
346346

347-
func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
347+
func (tp *TestSuite) TestRenameOverwriteNoForce(t *testing.T) {
348348
ctx, cancel := context.WithCancel(context.Background())
349349
defer cancel()
350350
api, err := tp.makeAPI(ctx)
@@ -374,7 +374,7 @@ func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
374374
}
375375
}
376376

377-
func (tp *provider) TestRenameOverwrite(t *testing.T) {
377+
func (tp *TestSuite) TestRenameOverwrite(t *testing.T) {
378378
ctx, cancel := context.WithCancel(context.Background())
379379
defer cancel()
380380
api, err := tp.makeAPI(ctx)
@@ -413,7 +413,7 @@ func (tp *provider) TestRenameOverwrite(t *testing.T) {
413413
}
414414
}
415415

416-
func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
416+
func (tp *TestSuite) TestRenameSameNameNoForce(t *testing.T) {
417417
ctx, cancel := context.WithCancel(context.Background())
418418
defer cancel()
419419
api, err := tp.makeAPI(ctx)
@@ -442,7 +442,7 @@ func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
442442
}
443443
}
444444

445-
func (tp *provider) TestRenameSameName(t *testing.T) {
445+
func (tp *TestSuite) TestRenameSameName(t *testing.T) {
446446
ctx, cancel := context.WithCancel(context.Background())
447447
defer cancel()
448448
api, err := tp.makeAPI(ctx)
@@ -471,7 +471,7 @@ func (tp *provider) TestRenameSameName(t *testing.T) {
471471
}
472472
}
473473

474-
func (tp *provider) TestRemove(t *testing.T) {
474+
func (tp *TestSuite) TestRemove(t *testing.T) {
475475
ctx, cancel := context.WithCancel(context.Background())
476476
defer cancel()
477477
api, err := tp.makeAPI(ctx)

0 commit comments

Comments
 (0)