MCPcopy
hub / github.com/ipfs/kubo / TestPathUnixFSHAMTPartial

Function TestPathUnixFSHAMTPartial

core/coreapi/test/path_test.go:17–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestPathUnixFSHAMTPartial(t *testing.T) {
18 ctx := t.Context()
19
20 // Create a node
21 apis, err := NodeProvider{}.MakeAPISwarm(t, ctx, true, true, 1)
22 if err != nil {
23 t.Fatal(err)
24 }
25 a := apis[0]
26
27 // Setting this after instantiating the swarm so that it's not clobbered by loading the go-ipfs config
28 prevVal := uio.HAMTShardingSize
29 uio.HAMTShardingSize = 1
30 defer func() {
31 uio.HAMTShardingSize = prevVal
32 }()
33
34 // Create and add a sharded directory
35 dir := make(map[string]files.Node)
36 // Make sure we have at least two levels of sharding
37 for i := 0; i < uio.DefaultShardWidth+1; i++ {
38 dir[strconv.Itoa(i)] = files.NewBytesFile([]byte(strconv.Itoa(i)))
39 }
40
41 r, err := a.Unixfs().Add(ctx, files.NewMapDirectory(dir), options.Unixfs.Pin(false, ""))
42 if err != nil {
43 t.Fatal(err)
44 }
45
46 // Get the root of the directory
47 nd, err := a.Dag().Get(ctx, r.RootCid())
48 if err != nil {
49 t.Fatal(err)
50 }
51
52 // Make sure the root is a DagPB node (this API might change in the future to account for ADLs)
53 _ = nd.(ipld.Node)
54 pbNode := nd.(*merkledag.ProtoNode)
55
56 // Remove one of the sharded directory blocks
57 if err := a.Block().Rm(ctx, path.FromCid(pbNode.Links()[0].Cid)); err != nil {
58 t.Fatal(err)
59 }
60
61 // Try and resolve each of the entries in the sharded directory which will result in pathing over the missing block
62 //
63 // Note: we could just check a particular path here, but it would require either greater use of the HAMT internals
64 // or some hard coded values in the test both of which would be a pain to follow.
65 for k := range dir {
66 // The node will go out to the (non-existent) network looking for the missing block. Make sure we're erroring
67 // because we exceeded the timeout on our query
68 timeoutCtx, timeoutCancel := context.WithTimeout(ctx, time.Second*1)
69 newPath, err := path.Join(r, k)
70 if err != nil {
71 t.Fatal(err)
72 }
73
74 _, err = a.ResolveNode(timeoutCtx, newPath)

Callers

nothing calls this directly

Calls 12

FatalMethod · 0.80
ContextMethod · 0.65
MakeAPISwarmMethod · 0.65
AddMethod · 0.65
UnixfsMethod · 0.65
PinMethod · 0.65
GetMethod · 0.65
DagMethod · 0.65
RmMethod · 0.65
BlockMethod · 0.65
ResolveNodeMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected