@cryptotaxi247 / kubo / commits / e5059d9e1

fix(tests): put valid blocks

This commit was moved from ipfs/interface-go-ipfs-core@16127b291793c593b78fb2909bbaf106612ffc30 This commit was moved from ipfs/boxo@b1c5044d1541aa39ed8e6fff8f47c71bf012a7eb

Steven Allen committed Dec 2, 2019 at 15:04 UTC e5059d9e1de51229ce49b275665903d9511adffb
1 file changed +39 -13
core/coreiface/tests/block.go
+39 -13
@@ -1,18 +1,34 @@
1 package tests
2
3 import (
4 + "bytes"
5 "context"
5 - "github.com/ipfs/interface-go-ipfs-core/path"
6 + "io"
7 "io/ioutil"
8 "strings"
9 "testing"
10
11 coreiface "github.com/ipfs/interface-go-ipfs-core"
12 opt "github.com/ipfs/interface-go-ipfs-core/options"
13 + "github.com/ipfs/interface-go-ipfs-core/path"
14
15 mh "github.com/multiformats/go-multihash"
16 )
17
18 +var (
19 + pbCid = "QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN"
20 + cborCid = "bafyreicnga62zhxnmnlt6ymq5hcbsg7gdhqdu6z4ehu3wpjhvqnflfy6nm"
21 + cborKCid = "bafyr2qgsohbwdlk7ajmmbb4lhoytmest4wdbe5xnexfvtxeatuyqqmwv3fgxp3pmhpc27gwey2cct56gloqefoqwcf3yqiqzsaqb7p4jefhcw"
22 +)
23 +
24 +func pbBlock() io.Reader {
25 + return bytes.NewReader([]byte{10, 12, 8, 2, 18, 6, 104, 101, 108, 108, 111, 10, 24, 6})
26 +}
27 +
28 +func cborBlock() io.Reader {
29 + return bytes.NewReader([]byte{101, 72, 101, 108, 108, 111})
30 +}
31 +
32 func (tp *TestSuite) TestBlock(t *testing.T) {
33 tp.hasApi(t, func(api coreiface.CoreAPI) error {
34 if api.Block() == nil {
@@ -38,12 +54,12 @@ func (tp *TestSuite) TestBlockPut(t *testing.T) {
54 t.Fatal(err)
55 }
56
41 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
57 + res, err := api.Block().Put(ctx, pbBlock())
58 if err != nil {
59 t.Fatal(err)
60 }
61
46 - if res.Path().Cid().String() != "QmPyo15ynbVrSTVdJL9th7JysHaAbXt9dM9tXk1bMHbRtk" {
62 + if res.Path().Cid().String() != pbCid {
63 t.Errorf("got wrong cid: %s", res.Path().Cid().String())
64 }
65 }
@@ -56,12 +72,12 @@ func (tp *TestSuite) TestBlockPutFormat(t *testing.T) {
72 t.Fatal(err)
73 }
74
59 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("cbor"))
75 + res, err := api.Block().Put(ctx, cborBlock(), opt.Block.Format("cbor"))
76 if err != nil {
77 t.Fatal(err)
78 }
79
64 - if res.Path().Cid().String() != "bafyreiayl6g3gitr7ys7kyng7sjywlrgimdoymco3jiyab6rozecmoazne" {
80 + if res.Path().Cid().String() != cborCid {
81 t.Errorf("got wrong cid: %s", res.Path().Cid().String())
82 }
83 }
@@ -74,12 +90,17 @@ func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
90 t.Fatal(err)
91 }
92
77 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
93 + res, err := api.Block().Put(
94 + ctx,
95 + cborBlock(),
96 + opt.Block.Hash(mh.KECCAK_512, -1),
97 + opt.Block.Format("cbor"),
98 + )
99 if err != nil {
100 t.Fatal(err)
101 }
102
82 - if res.Path().Cid().String() != "bafyb2qgdh7w6dcq24u65xbtdoehyavegnpvxcqce7ttvs6ielgmwdfxrahmu37d33atik57x5y6s7d7qz32aasuwgirh3ocn6ywswqdifvu6e" {
103 + if res.Path().Cid().String() != cborKCid {
104 t.Errorf("got wrong cid: %s", res.Path().Cid().String())
105 }
106 }
@@ -92,7 +113,7 @@ func (tp *TestSuite) TestBlockGet(t *testing.T) {
113 t.Fatal(err)
114 }
115
95 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
116 + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("raw"))
117 if err != nil {
118 t.Fatal(err)
119 }
@@ -130,7 +151,7 @@ func (tp *TestSuite) TestBlockRm(t *testing.T) {
151 t.Fatal(err)
152 }
153
133 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
154 + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("raw"))
155 if err != nil {
156 t.Fatal(err)
157 }
@@ -184,7 +205,7 @@ func (tp *TestSuite) TestBlockStat(t *testing.T) {
205 t.Fatal(err)
206 }
207
187 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
208 + res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("raw"))
209 if err != nil {
210 t.Fatal(err)
211 }
@@ -211,7 +232,7 @@ func (tp *TestSuite) TestBlockPin(t *testing.T) {
232 t.Fatal(err)
233 }
234
214 - _, err = api.Block().Put(ctx, strings.NewReader(`Hello`))
235 + _, err = api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("raw"))
236 if err != nil {
237 t.Fatal(err)
238 }
@@ -220,14 +241,19 @@ func (tp *TestSuite) TestBlockPin(t *testing.T) {
241 t.Fatal("expected 0 pins")
242 }
243
223 - res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Pin(true))
244 + res, err := api.Block().Put(
245 + ctx,
246 + strings.NewReader(`Hello`),
247 + opt.Block.Pin(true),
248 + opt.Block.Format("raw"),
249 + )
250 if err != nil {
251 t.Fatal(err)
252 }
253
254 pins, err := accPins(api.Pin().Ls(ctx))
255 if err != nil {
230 - t.Skip(err)
256 + t.Fatal(err)
257 }
258 if len(pins) != 1 {
259 t.Fatal("expected 1 pin")