Skip to content

Commit c9c75b0

Browse files
authored
Merge pull request ipfs/interface-go-ipfs-core#24 from ipfs/test/use-fatal
fix a bunch of small test "bugs" This commit was moved from ipfs/interface-go-ipfs-core@ccf9dac
2 parents a6129a8 + bbf450e commit c9c75b0

File tree

8 files changed

+113
-99
lines changed

8 files changed

+113
-99
lines changed

coreiface/tests/block.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (tp *provider) TestBlockPutFormat(t *testing.T) {
5252
defer cancel()
5353
api, err := tp.makeAPI(ctx)
5454
if err != nil {
55-
t.Error(err)
55+
t.Fatal(err)
5656
}
5757

5858
res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("cbor"))
@@ -70,7 +70,7 @@ func (tp *provider) TestBlockPutHash(t *testing.T) {
7070
defer cancel()
7171
api, err := tp.makeAPI(ctx)
7272
if err != nil {
73-
t.Error(err)
73+
t.Fatal(err)
7474
}
7575

7676
res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
@@ -88,7 +88,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
8888
defer cancel()
8989
api, err := tp.makeAPI(ctx)
9090
if err != nil {
91-
t.Error(err)
91+
t.Fatal(err)
9292
}
9393

9494
res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
@@ -98,12 +98,12 @@ func (tp *provider) TestBlockGet(t *testing.T) {
9898

9999
r, err := api.Block().Get(ctx, res.Path())
100100
if err != nil {
101-
t.Error(err)
101+
t.Fatal(err)
102102
}
103103

104104
d, err := ioutil.ReadAll(r)
105105
if err != nil {
106-
t.Error(err)
106+
t.Fatal(err)
107107
}
108108

109109
if string(d) != "Hello" {
@@ -112,7 +112,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
112112

113113
p, err := coreiface.ParsePath("/ipfs/" + res.Path().Cid().String())
114114
if err != nil {
115-
t.Error(err)
115+
t.Fatal(err)
116116
}
117117

118118
rp, err := api.ResolvePath(ctx, p)
@@ -129,7 +129,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
129129
defer cancel()
130130
api, err := tp.makeAPI(ctx)
131131
if err != nil {
132-
t.Error(err)
132+
t.Fatal(err)
133133
}
134134

135135
res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
@@ -139,12 +139,12 @@ func (tp *provider) TestBlockRm(t *testing.T) {
139139

140140
r, err := api.Block().Get(ctx, res.Path())
141141
if err != nil {
142-
t.Error(err)
142+
t.Fatal(err)
143143
}
144144

145145
d, err := ioutil.ReadAll(r)
146146
if err != nil {
147-
t.Error(err)
147+
t.Fatal(err)
148148
}
149149

150150
if string(d) != "Hello" {
@@ -153,7 +153,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
153153

154154
err = api.Block().Rm(ctx, res.Path())
155155
if err != nil {
156-
t.Error(err)
156+
t.Fatal(err)
157157
}
158158

159159
_, err = api.Block().Get(ctx, res.Path())
@@ -174,7 +174,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
174174

175175
err = api.Block().Rm(ctx, res.Path(), opt.Block.Force(true))
176176
if err != nil {
177-
t.Error(err)
177+
t.Fatal(err)
178178
}
179179
}
180180

@@ -183,7 +183,7 @@ func (tp *provider) TestBlockStat(t *testing.T) {
183183
defer cancel()
184184
api, err := tp.makeAPI(ctx)
185185
if err != nil {
186-
t.Error(err)
186+
t.Fatal(err)
187187
}
188188

189189
res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
@@ -193,7 +193,7 @@ func (tp *provider) TestBlockStat(t *testing.T) {
193193

194194
stat, err := api.Block().Stat(ctx, res.Path())
195195
if err != nil {
196-
t.Error(err)
196+
t.Fatal(err)
197197
}
198198

199199
if stat.Path().String() != res.Path().String() {
@@ -210,7 +210,7 @@ func (tp *provider) TestBlockPin(t *testing.T) {
210210
defer cancel()
211211
api, err := tp.makeAPI(ctx)
212212
if err != nil {
213-
t.Error(err)
213+
t.Fatal(err)
214214
}
215215

216216
_, err = api.Block().Put(ctx, strings.NewReader(`Hello`))

coreiface/tests/dag.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func (tp *provider) TestPut(t *testing.T) {
4444
defer cancel()
4545
api, err := tp.makeAPI(ctx)
4646
if err != nil {
47-
t.Error(err)
47+
t.Fatal(err)
4848
}
4949

5050
nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), math.MaxUint64, -1)
5151
if err != nil {
52-
t.Error(err)
52+
t.Fatal(err)
5353
}
5454

5555
err = api.Dag().Add(ctx, nd)
@@ -67,12 +67,12 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
6767
defer cancel()
6868
api, err := tp.makeAPI(ctx)
6969
if err != nil {
70-
t.Error(err)
70+
t.Fatal(err)
7171
}
7272

7373
nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), mh.ID, -1)
7474
if err != nil {
75-
t.Error(err)
75+
t.Fatal(err)
7676
}
7777

7878
err = api.Dag().Add(ctx, nd)
@@ -90,12 +90,12 @@ func (tp *provider) TestDagPath(t *testing.T) {
9090
defer cancel()
9191
api, err := tp.makeAPI(ctx)
9292
if err != nil {
93-
t.Error(err)
93+
t.Fatal(err)
9494
}
9595

9696
snd, err := ipldcbor.FromJSON(strings.NewReader(`"foo"`), math.MaxUint64, -1)
9797
if err != nil {
98-
t.Error(err)
98+
t.Fatal(err)
9999
}
100100

101101
err = api.Dag().Add(ctx, snd)
@@ -105,7 +105,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
105105

106106
nd, err := ipldcbor.FromJSON(strings.NewReader(`{"lnk": {"/": "`+snd.Cid().String()+`"}}`), math.MaxUint64, -1)
107107
if err != nil {
108-
t.Error(err)
108+
t.Fatal(err)
109109
}
110110

111111
err = api.Dag().Add(ctx, nd)
@@ -115,17 +115,17 @@ func (tp *provider) TestDagPath(t *testing.T) {
115115

116116
p, err := coreiface.ParsePath(path.Join(nd.Cid().String(), "lnk"))
117117
if err != nil {
118-
t.Error(err)
118+
t.Fatal(err)
119119
}
120120

121121
rp, err := api.ResolvePath(ctx, p)
122122
if err != nil {
123-
t.Error(err)
123+
t.Fatal(err)
124124
}
125125

126126
ndd, err := api.Dag().Get(ctx, rp.Cid())
127127
if err != nil {
128-
t.Error(err)
128+
t.Fatal(err)
129129
}
130130

131131
if ndd.Cid().String() != snd.Cid().String() {
@@ -138,12 +138,12 @@ func (tp *provider) TestTree(t *testing.T) {
138138
defer cancel()
139139
api, err := tp.makeAPI(ctx)
140140
if err != nil {
141-
t.Error(err)
141+
t.Fatal(err)
142142
}
143143

144144
nd, err := ipldcbor.FromJSON(strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`), math.MaxUint64, -1)
145145
if err != nil {
146-
t.Error(err)
146+
t.Fatal(err)
147147
}
148148

149149
err = api.Dag().Add(ctx, nd)
@@ -153,7 +153,7 @@ func (tp *provider) TestTree(t *testing.T) {
153153

154154
res, err := api.Dag().Get(ctx, nd.Cid())
155155
if err != nil {
156-
t.Error(err)
156+
t.Fatal(err)
157157
}
158158

159159
lst := res.Tree("", -1)
@@ -173,12 +173,12 @@ func (tp *provider) TestBatch(t *testing.T) {
173173
defer cancel()
174174
api, err := tp.makeAPI(ctx)
175175
if err != nil {
176-
t.Error(err)
176+
t.Fatal(err)
177177
}
178178

179179
nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), math.MaxUint64, -1)
180180
if err != nil {
181-
t.Error(err)
181+
t.Fatal(err)
182182
}
183183

184184
if nd.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
@@ -187,15 +187,15 @@ func (tp *provider) TestBatch(t *testing.T) {
187187

188188
_, err = api.Dag().Get(ctx, nd.Cid())
189189
if err == nil || !strings.Contains(err.Error(), "not found") {
190-
t.Error(err)
190+
t.Fatal(err)
191191
}
192192

193193
if err := api.Dag().AddMany(ctx, []ipld.Node{nd}); err != nil {
194-
t.Error(err)
194+
t.Fatal(err)
195195
}
196196

197197
_, err = api.Dag().Get(ctx, nd.Cid())
198198
if err != nil {
199-
t.Error(err)
199+
t.Fatal(err)
200200
}
201201
}

coreiface/tests/key.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (tp *provider) TestGenerate(t *testing.T) {
121121
defer cancel()
122122
api, err := tp.makeAPI(ctx)
123123
if err != nil {
124-
t.Error(err)
124+
t.Fatal(err)
125125
}
126126

127127
k, err := api.Key().Generate(ctx, "foo")
@@ -144,7 +144,7 @@ func (tp *provider) TestGenerateSize(t *testing.T) {
144144
defer cancel()
145145
api, err := tp.makeAPI(ctx)
146146
if err != nil {
147-
t.Error(err)
147+
t.Fatal(err)
148148
}
149149

150150
k, err := api.Key().Generate(ctx, "foo", opt.Key.Size(1024))
@@ -169,7 +169,7 @@ func (tp *provider) TestGenerateType(t *testing.T) {
169169

170170
api, err := tp.makeAPI(ctx)
171171
if err != nil {
172-
t.Error(err)
172+
t.Fatal(err)
173173
}
174174

175175
k, err := api.Key().Generate(ctx, "bar", opt.Key.Type(opt.Ed25519Key))
@@ -193,7 +193,7 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
193193
defer cancel()
194194
api, err := tp.makeAPI(ctx)
195195
if err != nil {
196-
t.Error(err)
196+
t.Fatal(err)
197197
}
198198

199199
_, err = api.Key().Generate(ctx, "foo")
@@ -226,7 +226,7 @@ func (tp *provider) TestList(t *testing.T) {
226226
defer cancel()
227227
api, err := tp.makeAPI(ctx)
228228
if err != nil {
229-
t.Error(err)
229+
t.Fatal(err)
230230
}
231231

232232
_, err = api.Key().Generate(ctx, "foo")
@@ -272,7 +272,7 @@ func (tp *provider) TestRename(t *testing.T) {
272272
defer cancel()
273273
api, err := tp.makeAPI(ctx)
274274
if err != nil {
275-
t.Error(err)
275+
t.Fatal(err)
276276
}
277277

278278
_, err = api.Key().Generate(ctx, "foo")
@@ -301,7 +301,7 @@ func (tp *provider) TestRenameToSelf(t *testing.T) {
301301
defer cancel()
302302
api, err := tp.makeAPI(ctx)
303303
if err != nil {
304-
t.Error(err)
304+
t.Fatal(err)
305305
}
306306

307307
_, err = api.Key().Generate(ctx, "foo")
@@ -325,7 +325,7 @@ func (tp *provider) TestRenameToSelfForce(t *testing.T) {
325325
defer cancel()
326326
api, err := tp.makeAPI(ctx)
327327
if err != nil {
328-
t.Error(err)
328+
t.Fatal(err)
329329
}
330330

331331
_, err = api.Key().Generate(ctx, "foo")
@@ -349,7 +349,7 @@ func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
349349
defer cancel()
350350
api, err := tp.makeAPI(ctx)
351351
if err != nil {
352-
t.Error(err)
352+
t.Fatal(err)
353353
}
354354

355355
_, err = api.Key().Generate(ctx, "foo")
@@ -379,7 +379,7 @@ func (tp *provider) TestRenameOverwrite(t *testing.T) {
379379
defer cancel()
380380
api, err := tp.makeAPI(ctx)
381381
if err != nil {
382-
t.Error(err)
382+
t.Fatal(err)
383383
}
384384

385385
kfoo, err := api.Key().Generate(ctx, "foo")
@@ -418,7 +418,7 @@ func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
418418
defer cancel()
419419
api, err := tp.makeAPI(ctx)
420420
if err != nil {
421-
t.Error(err)
421+
t.Fatal(err)
422422
}
423423

424424
_, err = api.Key().Generate(ctx, "foo")
@@ -447,7 +447,7 @@ func (tp *provider) TestRenameSameName(t *testing.T) {
447447
defer cancel()
448448
api, err := tp.makeAPI(ctx)
449449
if err != nil {
450-
t.Error(err)
450+
t.Fatal(err)
451451
}
452452

453453
_, err = api.Key().Generate(ctx, "foo")
@@ -476,7 +476,7 @@ func (tp *provider) TestRemove(t *testing.T) {
476476
defer cancel()
477477
api, err := tp.makeAPI(ctx)
478478
if err != nil {
479-
t.Error(err)
479+
t.Fatal(err)
480480
}
481481

482482
k, err := api.Key().Generate(ctx, "foo")

0 commit comments

Comments
 (0)