Documentation ¶
Overview ¶
Package test offers testing utilities for all the IPFS Cluster codebase, like IPFS daemon and RPC mocks and pre-defined testing CIDs.
Index ¶
- Constants
- Variables
- func NewMockRPCClient(t testing.TB) *rpc.Client
- func NewMockRPCClientWithHost(t testing.TB, h host.Host) *rpc.Client
- type IpfsMock
- type MockDAGService
- func (d *MockDAGService) Add(ctx context.Context, node format.Node) error
- func (d *MockDAGService) AddMany(ctx context.Context, nodes []format.Node) error
- func (d *MockDAGService) Get(ctx context.Context, cid cid.Cid) (format.Node, error)
- func (d *MockDAGService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *format.NodeOption
- func (d *MockDAGService) Remove(ctx context.Context, c cid.Cid) error
- func (d *MockDAGService) RemoveMany(ctx context.Context, cids []cid.Cid) error
- type ShardingTestHelper
- func (sth *ShardingTestHelper) Clean(t *testing.T)
- func (sth *ShardingTestHelper) GetRandFileMultiReader(t *testing.T, kbs int) (*files.MultiFileReader, io.Closer)
- func (sth *ShardingTestHelper) GetRandFileReader(t *testing.T, kbs int) (files.Directory, io.Closer)
- func (sth *ShardingTestHelper) GetTreeMultiReader(t *testing.T) (*files.MultiFileReader, io.Closer)
- func (sth *ShardingTestHelper) GetTreeSerialFile(t *testing.T) files.Directory
Constants ¶
const ( IpfsCustomHeaderName = "X-Custom-Header" IpfsTimeHeaderName = "X-Time-Now" IpfsCustomHeaderValue = "42" IpfsACAOrigin = "myorigin" IpfsErrFromNotPinned = "'from' cid was not recursively pinned already" )
Some values used by the ipfs mock
Variables ¶
var (
Cid1, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq")
Cid2, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmma")
Cid3, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmb")
Cid4Data = "Cid4Data"
// Cid resulting from block put using blake2b-256 and raw format
Cid4, _ = api.DecodeCid("bafk2bzaceawsyhsnrwwy5mtit2emnjfalkxsyq2p2ptd6fuliolzwwjbs42fq")
// Cid resulting from block put using format "v0" defaults
Cid5, _ = api.DecodeCid("QmbgmXgsFjxAJ7cEaziL2NDSptHAkPwkEGMmKMpfyYeFXL")
Cid5Data = "Cid5Data"
SlowCid1, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmd")
CidResolved, _ = api.DecodeCid("zb2rhiKhUepkTMw7oFfBUnChAN7ABAvg2hXUwmTBtZ6yxuabc")
// ErrorCid is meant to be used as a Cid which causes errors. i.e. the
// ipfs mock fails when pinning this CID.
ErrorCid, _ = api.DecodeCid("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmc")
// NotFoundCid is meant to be used as a CID that doesn't exist in the
// pinset.
NotFoundCid, _ = api.DecodeCid("bafyreiay3jpjk74dkckv2r74eyvf3lfnxujefay2rtuluintasq2zlapv4")
PeerID1, _ = peer.Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc")
PeerID2, _ = peer.Decode("QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6")
PeerID3, _ = peer.Decode("QmPGDFvBkgWhvzEK9qaTWrWurSwqXNmhnK3hgELPdZZNPa")
PeerID4, _ = peer.Decode("QmZ8naDy5mEz4GLuQwjWt9MPYqHTBbsm8tQBrNSjiq6zBc")
PeerID5, _ = peer.Decode("QmZVAo3wd8s5eTTy2kPYs34J9PvfxpKPuYsePPYGjgRRjg")
PeerID6, _ = peer.Decode("QmR8Vu6kZk7JvAN2rWVWgiduHatgBq2bb15Yyq8RRhYSbx")
PeerID7, _ = peer.Decode("12D3KooWGHTKzeT4KaLGLrbKKyT8zKrBPXAUBRzCAN6ZMDMo4M6M")
PeerID8, _ = peer.Decode("12D3KooWFBFCDQzAkQSwPZLV883pKdsmb6urQ3sMjfJHUxn5GCVv")
PeerID9, _ = peer.Decode("12D3KooWKuJ8LPTyHbyX4nt4C7uWmUobzFsiceTVoFw7HpmoNakM")
PeerName1 = "TestPeer1"
PeerName2 = "TestPeer2"
PeerName3 = "TestPeer3"
PeerName4 = "TestPeer4"
PeerName5 = "TestPeer5"
PeerName6 = "TestPeer6"
PathIPFS1 = "/ipfs/QmaNJ5acV31sx8jq626qTpAWW4DXKw34aGhx53dECLvXbY"
PathIPFS2 = "/ipfs/QmbUNM297ZwxB8CfFAznK7H9YMesDoY6Tt5bPgt5MSCB2u/im.gif"
PathIPFS3 = "/ipfs/QmbUNM297ZwxB8CfFAznK7H9YMesDoY6Tt5bPgt5MSCB2u/im.gif/"
PathIPNS1 = "/ipns/QmbmSAQNnfGcBAB8M8AsSPxd1TY7cpT9hZ398kXAScn2Ka"
PathIPNS2 = "/ipns/QmbmSAQNnfGcBAB8M8AsSPxd1TY7cpT9hZ398kXAScn2Ka/"
PathIPLD1 = "/ipld/QmaNJ5acV31sx8jq626qTpAWW4DXKw34aGhx53dECLvXbY"
PathIPLD2 = "/ipld/QmaNJ5acV31sx8jq626qTpAWW4DXKw34aGhx53dECLvXbY/"
// NotFoundPath is meant to be used as a path that resolves into a CID that doesn't exist in the
// pinset.
NotFoundPath = "/ipfs/bafyreiay3jpjk74dkckv2r74eyvf3lfnxujefay2rtuluintasq2zlapv4"
InvalidPath1 = "/invalidkeytype/QmaNJ5acV31sx8jq626qTpAWW4DXKw34aGhx53dECLvXbY/"
InvalidPath2 = "/ipfs/invalidhash"
InvalidPath3 = "/ipfs/"
)
Common variables used all around tests.
var ( // ErrBadCid is returned when using ErrorCid. Operations with that CID always // fail. ErrBadCid = errors.New("this is an expected error when using ErrorCid") // ErrLinkNotFound is error returned when no link is found ErrLinkNotFound = errors.New("no link by that name") )
var ( ShardingDirBalancedRootCID = "QmdHXJgxeCFf6qDZqYYmMesV2DbZCVPEdEhj2oVTxP1y7Y" ShardingDirBalancedRootCIDWrapped = "QmbfGRPTUd7L1xsAZZ1A3kUFP1zkEZ9kHdb6AGaajBzGGX" ShardingDirTrickleRootCID = "QmYMbx56GFNBDAaAMchtjmWjDTdqNKCSGuFxtRosiPgJL6" // These hashes should match all the blocks produced when adding // the files resulting from GetShardingDir* // They have been obtained by adding the "shardTesting" folder // to go-ipfs (with default parameters). Then doing // `refs -r` on the result. It contains the folder hash. ShardingDirCids = [28]string{ "QmdHXJgxeCFf6qDZqYYmMesV2DbZCVPEdEhj2oVTxP1y7Y", "QmSpZcKTgfsxyL7nyjzTNB1gAWmGYC2t8kRPpZSG1ZbTkY", "QmSijPKAE61CUs57wWU2M4YxkSaRogQxYRtHoEzP2uRaQt", "QmYr6r514Pt8HbsFjwompLrHMyZEYg6aXfsv59Ys8uzLpr", "QmfEeHL3iwDE8XjeFq9HDu2B8Dfu8L94y7HUB5sh5vN9TB", "QmTz2gUzUNQnH3i818MAJPMLjBfRXZxoZbdNYT1K66LnZN", "QmPZLJ3CZYgxH4K1w5jdbAdxJynXn5TCB4kHy7u8uHC3fy", "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn", "QmY6PArrjY66Nb4qEKWF7RUHCToRFyTsrM6cH8D6vJMSnk", "QmYXgh47x4gr1iL6YRqAA8RcE3XNWPfB5VJTt9dBfRnRHX", "QmXqkKUxgWsgXEUsxDJcs2hUrSrFnPkKyGnGdxpm1cb2me", "Qmbne4XHMAiZwoFYdnGrdcW3UBYA7UnFE9WoDwEjG3deZH", "Qmdz4kLZUjfGBSvfMxTQpcxjz2aZqupnF9KjKGpAuaZ4nT", "QmavW3cdGuSfYMEQiBDfobwVtPEjUnML2Ry1q8w8X3Q8Wj", "QmfPHRbeerRWgbu5BzxwK7UhmJGqGvZNxuFoMCUFTuhG3H", "QmaYNfhw7L7KWX7LYpwWt1bh6Gq2p7z1tic35PnDRnqyBf", "QmWWwH1GKMh6GmFQunjq7CHjr4g4z6Q4xHyDVfuZGX7MyU", "QmVpHQGMF5PLsvfgj8bGo9q2YyLRPMvfu1uTb3DgREFtUc", "QmUrdAn4Mx4kNioX9juLgwQotwFfxeo5doUNnLJrQynBEN", "QmdJ86B7J8mfGq6SjQy8Jz7r5x1cLcXc9M2a7T7NmSMVZx", "QmS77cTMdyx8P7rP2Gij6azgYPpjp2J34EVYuhB6mfjrQh", "QmbsBsDspFcqi7xJ4xPxcNYnduzQ5UQDw9y6trQWZGoEHq", "QmakAXHMeyE6fHHaeqicSKVMM2QyuGbS2g8dgUA7ns8gSY", "QmTC6vGbH9ABkpXfrMmYkXbxEqH12jEVGpvGzibGZEDVHK", "QmebQW6nfE5cPb85ZUGrSyqbFsVYwfuKsX8Ur3NWwfmnYk", "QmSCcsb4mNMz3CXvVjPdc7kxrx4PbitrcRN8ocmyg62oit", "QmZ2iUT3W7jh8QNnpWSiMZ1QYgpommCSQFZiPY5VdoCHyv", "QmdmUbN9JS3BK3nvcycyzFUBJqXip5zf7bdKbYM3p14e9h", } // Used for testing blockput/blockget ShardCid, _ = api.DecodeCid("zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh") ShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a") )
Variables related to adding the testing directory generated by tests
Functions ¶
func NewMockRPCClient ¶
NewMockRPCClient creates a mock ipfs-cluster RPC server and returns a client to it.
Types ¶
type IpfsMock ¶
type IpfsMock struct { Addr string Port int BlockStore map[string][]byte // contains filtered or unexported fields }
IpfsMock is an ipfs daemon mock which should sustain the functionality used by ipfscluster.
type MockDAGService ¶ added in v0.13.3
type MockDAGService struct { Nodes map[cid.Cid]format.Node // contains filtered or unexported fields }
MockDAGService implements an in-memory DAGService. The stored nodes are inspectable via the Nodes map.
func NewMockDAGService ¶ added in v0.13.3
func NewMockDAGService() *MockDAGService
NewMockDAGService returns an in-memory DAG Service.
func (*MockDAGService) GetMany ¶ added in v0.13.3
func (d *MockDAGService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *format.NodeOption
GetMany reads many nodes.
func (*MockDAGService) RemoveMany ¶ added in v0.13.3
RemoveMany removes many nodes.
type ShardingTestHelper ¶ added in v0.5.0
type ShardingTestHelper struct {
// contains filtered or unexported fields
}
ShardingTestHelper helps generating files and folders to test adding and sharding in IPFS Cluster
func NewShardingTestHelper ¶ added in v0.5.0
func NewShardingTestHelper() *ShardingTestHelper
NewShardingTestHelper returns a new helper.
func (*ShardingTestHelper) Clean ¶ added in v0.5.0
func (sth *ShardingTestHelper) Clean(t *testing.T)
Clean deletes any folder and file generated by this helper.
func (*ShardingTestHelper) GetRandFileMultiReader ¶ added in v0.5.0
func (sth *ShardingTestHelper) GetRandFileMultiReader(t *testing.T, kbs int) (*files.MultiFileReader, io.Closer)
GetRandFileMultiReader creates and returns a MultiFileReader for a testing random file of the given size (in kbs). The random file is different every time.
func (*ShardingTestHelper) GetRandFileReader ¶ added in v0.8.0
func (sth *ShardingTestHelper) GetRandFileReader(t *testing.T, kbs int) (files.Directory, io.Closer)
GetRandFileReader creates and returns a directory containing a testing random file of the given size (in kbs)
func (*ShardingTestHelper) GetTreeMultiReader ¶ added in v0.5.0
func (sth *ShardingTestHelper) GetTreeMultiReader(t *testing.T) (*files.MultiFileReader, io.Closer)
GetTreeMultiReader creates and returns a MultiFileReader for a testing directory tree. Files are pseudo-randomly generated and are always the same. Directory structure:
- testingTree
- A
- alpha
- small_file_0 (< 5 kB)
- beta
- small_file_1 (< 5 kB)
- delta
- empty
- small_file_2 (< 5 kB)
- gamma
- small_file_3 (< 5 kB)
- B
- medium_file (~.3 MB)
- big_file (3 MB)
The total size in ext4 is ~3420160 Bytes = ~3340 kB = ~3.4MB
func (*ShardingTestHelper) GetTreeSerialFile ¶ added in v0.5.0
func (sth *ShardingTestHelper) GetTreeSerialFile(t *testing.T) files.Directory
GetTreeSerialFile returns a files.Directory pointing to the testing directory tree (see GetTreeMultiReader).