Skip to content

Commit 4ee8c74

Browse files
committed
fix: add cross-impl shard test
Ref: ipfs/js-ipfs-unixfs#358
1 parent e27c473 commit 4ee8c74

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

data/builder/dir_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
dagpb "github.com/ipld/go-codec-dagpb"
1616
"github.com/ipld/go-ipld-prime"
1717
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
18+
"github.com/multiformats/go-multihash"
1819
"github.com/stretchr/testify/require"
1920
)
2021

@@ -67,6 +68,40 @@ func TestBuildUnixFSFileWrappedInDirectory_Reference(t *testing.T) {
6768
}
6869
}
6970

71+
// Cross-impl reference test: directory of files with single character
72+
// names, starting from ' ' and ending with '~', but excluding the special
73+
// characters '/' and '.'. Each file should contain a single byte with the
74+
// same value as the character in its name. Files are added to a sharded
75+
// directory with a fanout of 16, using CIDv1 throughout, and should result
76+
// in the root CID of:
77+
//
78+
// bafybeihnipspiyy3dctpcx7lv655qpiuy52d7b2fzs52dtrjqwmvbiux44
79+
func TestBuildUnixFSDirectoryShardAltFanout_Reference(t *testing.T) {
80+
ls := cidlink.DefaultLinkSystem()
81+
storage := cidlink.Memory{}
82+
ls.StorageReadOpener = storage.OpenRead
83+
ls.StorageWriteOpener = storage.OpenWrite
84+
entries := make([]dagpb.PBLink, 0)
85+
for ch := ' '; ch <= '~'; ch++ {
86+
if ch == '/' || ch == '.' {
87+
continue
88+
}
89+
s := string(ch)
90+
r := bytes.NewBuffer([]byte(s))
91+
e, err := mkEntry(r, s, &ls)
92+
require.NoError(t, err)
93+
entries = append(entries, e)
94+
}
95+
lnk, sz, err := BuildUnixFSShardedDirectory(16, multihash.MURMUR3X64_64, entries, &ls)
96+
require.NoError(t, err)
97+
var totStored int
98+
for _, blk := range storage.Bag {
99+
totStored += len(blk)
100+
}
101+
require.Equal(t, totStored, int(sz))
102+
require.Equal(t, "bafybeihnipspiyy3dctpcx7lv655qpiuy52d7b2fzs52dtrjqwmvbiux44", lnk.String())
103+
}
104+
70105
func TestBuildUnixFSDirectory(t *testing.T) {
71106
ls := cidlink.DefaultLinkSystem()
72107
storage := cidlink.Memory{}

0 commit comments

Comments
 (0)