Skip to content

Commit 619ba13

Browse files
committed
test: add a bunch of new tests and fixes
- do not expect specific filename, that's impl. detail - add new fixtures, rename some, delete others - fix byte range tests (limit is inclusive) - dag-cbor tests with links - content-type and content-disposition checks in all car tests - and much more
1 parent 8e0736b commit 619ba13

12 files changed

+364
-121
lines changed

fixtures/t0118-carv1-basic.car

-715 Bytes
Binary file not shown.

fixtures/t0118-deterministic.car

-127 Bytes
Binary file not shown.

fixtures/t0118-gateway-car.car

-127 Bytes
Binary file not shown.

fixtures/t0118-test-dag.car

-312 Bytes
Binary file not shown.
1.93 KB
Binary file not shown.
416 Bytes
Binary file not shown.

tests/t0118_gateway_car_test.go

Lines changed: 331 additions & 97 deletions
Large diffs are not rendered by default.

tooling/car/unixfs.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package car
66
import (
77
"bytes"
88
"context"
9+
"errors"
910
"fmt"
10-
dagpb "github.com/ipld/go-codec-dagpb"
1111
"io"
1212
"os"
1313
"path"
@@ -22,6 +22,7 @@ import (
2222
"github.com/ipfs/go-cid"
2323
format "github.com/ipfs/go-ipld-format"
2424
"github.com/ipfs/go-unixfsnode"
25+
dagpb "github.com/ipld/go-codec-dagpb"
2526
"github.com/ipld/go-ipld-prime"
2627
_ "github.com/ipld/go-ipld-prime/codec/cbor"
2728
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
@@ -78,15 +79,27 @@ func (d *UnixfsDag) loadLinks(node format.Node) (map[string]*UnixfsDag, error) {
7879
}
7980

8081
func (d *UnixfsDag) getNode(names ...string) (format.Node, error) {
81-
for _, name := range names {
82+
for i, name := range names {
8283
node, err := d.getNode()
8384
if err != nil {
8485
return nil, err
8586
}
8687

8788
if d.links == nil {
8889
d.links, err = d.loadLinks(node)
89-
if err != nil {
90+
if errors.Is(err, uio.ErrNotADir) {
91+
// Maybe it's an IPLD Link!
92+
lnk, _, err := node.ResolveLink(names[i:])
93+
if err != nil {
94+
return nil, fmt.Errorf("node is neither a unixfs directory, or includes an ipld link: %w", err)
95+
}
96+
n, err := lnk.GetNode(context.Background(), d.dsvc)
97+
if err != nil {
98+
return nil, fmt.Errorf("found link node could not be fetched: %w", err)
99+
}
100+
d.node = n
101+
return d.node, nil
102+
} else if err != nil {
90103
return nil, err
91104
}
92105
}
@@ -173,16 +186,6 @@ func (d *UnixfsDag) MustGetChildrenCids(names ...string) []string {
173186
return cids
174187
}
175188

176-
func (d *UnixfsDag) MustGetIPLDChildrenCids(names ...string) []string {
177-
node := d.MustGetNode(names...)
178-
lnks := node.node.Links()
179-
var cids []string
180-
for _, l := range lnks {
181-
cids = append(cids, l.Cid.String())
182-
}
183-
return cids
184-
}
185-
186189
// MustGetCidsInHAMT returns the cids in the HAMT at the given path. Does not include the CID of the HAMT root
187190
func (d *UnixfsDag) MustGetCidsInHAMT(names ...string) []string {
188191
node := d.MustGetNode(names...)

0 commit comments

Comments
 (0)