Documentation ¶
Overview ¶
Package testutil provides utilities for writing tests that require nontrivial UnixFS data of various forms
Index ¶
- func CompareDirEntries(t *testing.T, a, b DirEntry)
- type DirEntry
- func BuildDirectory(t *testing.T, linkSys *linking.LinkSystem, children []DirEntry, sharded bool) DirEntry
- func GenerateDirectory(t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, ...) DirEntry
- func GenerateDirectoryFrom(t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, ...) DirEntry
- func GenerateFile(t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, size int) DirEntry
- func ToDirEntry(t *testing.T, linkSys linking.LinkSystem, rootCid cid.Cid, expectFull bool) DirEntry
- func WrapContent(t *testing.T, rndReader io.Reader, lsys *ipld.LinkSystem, content DirEntry, ...) DirEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareDirEntries ¶
CompareDirEntries is a safe, recursive comparison between two DirEntry values. It doesn't strictly require child ordering to match, but it does require that all children exist and match, in some order.
Types ¶
type DirEntry ¶
type DirEntry struct { Path string Content []byte Root cid.Cid SelfCids []cid.Cid TSize uint64 Children []DirEntry }
DirEntry represents a flattened directory entry, where Path is from the root of the directory and Content is the file contents. It is intended that a DirEntry slice can be used to represent a full-depth directory without needing nesting.
func BuildDirectory ¶
func BuildDirectory(t *testing.T, linkSys *linking.LinkSystem, children []DirEntry, sharded bool) DirEntry
BuildDirectory builds a directory from the given children, storing the blocks in the provided LinkSystem and returns a DirEntry representation of the directory. If sharded is true, the root directory will be built as HAMT sharded (with a low "width" to maximise the chance of collisions and therefore greater depth for smaller number of files).
func GenerateDirectory ¶
func GenerateDirectory(t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, targetSize int, rootSharded bool) DirEntry
GenerateDirectory generates a random UnixFS directory that aims for the requested targetSize (in bytes, although it is likely to fall somewhere under this number), storing the blocks in the provided LinkSystem and returns a DirEntry representation of the directory. If rootSharded is true, the root directory will be built as HAMT sharded (with a low "width" to maximise the chance of collisions and therefore greater depth for smaller number of files).
func GenerateDirectoryFrom ¶
func GenerateDirectoryFrom( t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, targetSize int, dir string, sharded bool, ) DirEntry
GenerateDirectoryFrom is the same as GenerateDirectory but allows the caller to specify a directory path to start from. This is useful for generating nested directories.
func GenerateFile ¶
func GenerateFile(t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, size int) DirEntry
GenerateFile generates a random unixfs file of the given size, storing the blocks in the provided LinkSystem and returns a DirEntry representation of the file.
func ToDirEntry ¶
func ToDirEntry(t *testing.T, linkSys linking.LinkSystem, rootCid cid.Cid, expectFull bool) DirEntry
ToDirEntry takes a LinkSystem containing UnixFS data and builds a DirEntry tree representing the file and directory structure it finds starting at the rootCid. If expectFull is true, it will error if it encounters a UnixFS node that it cannot fully load. If expectFull is false, it will ignore errors and return nil for any node it cannot load.
func WrapContent ¶
func WrapContent(t *testing.T, rndReader io.Reader, lsys *ipld.LinkSystem, content DirEntry, wrapPath string, exclusive bool) DirEntry
WrapContent embeds the content we want in some random nested content such that it's fetchable under the provided path. If exclusive is true, the content will be the only thing under the path. If false, there will be content before and after the wrapped content at each point in the path.