ipfs-cluster: github.com/ipfs/ipfs-cluster/test Index | Files

package test

import "github.com/ipfs/ipfs-cluster/test"

Package test offers testing utilities for all the IPFS Cluster codebase, like IPFS daemon and RPC mocks and pre-defined testing CIDs.

Index

Package Files

cids.go ipfs_mock.go rpc_api_mock.go sharding.go test.go

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, _  = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq")
    Cid2, _  = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmma")
    Cid3, _  = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmb")
    Cid4Data = "Cid4Data"
    // Cid resulting from block put using blake2b-256 and raw format
    Cid4, _ = cid.Decode("bafk2bzaceawsyhsnrwwy5mtit2emnjfalkxsyq2p2ptd6fuliolzwwjbs42fq")

    // Cid resulting from block put using format "v0" defaults
    Cid5, _        = cid.Decode("QmbgmXgsFjxAJ7cEaziL2NDSptHAkPwkEGMmKMpfyYeFXL")
    Cid5Data       = "Cid5Data"
    SlowCid1, _    = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmd")
    CidResolved, _ = cid.Decode("zb2rhiKhUepkTMw7oFfBUnChAN7ABAvg2hXUwmTBtZ6yxuabc")
    // ErrorCid is meant to be used as a Cid which causes errors. i.e. the
    // ipfs mock fails when pinning this CID.
    ErrorCid, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmc")
    // NotFoundCid is meant to be used as a CID that doesn't exist in the
    // pinset.
    NotFoundCid, _ = cid.Decode("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")

    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, _  = cid.Decode("zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh")
    ShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a")
)

Variables related to adding the testing directory generated by tests

func NewMockRPCClient Uses

func NewMockRPCClient(t testing.TB) *rpc.Client

NewMockRPCClient creates a mock ipfs-cluster RPC server and returns a client to it.

func NewMockRPCClientWithHost Uses

func NewMockRPCClientWithHost(t testing.TB, h host.Host) *rpc.Client

NewMockRPCClientWithHost returns a mock ipfs-cluster RPC server initialized with a given host.

type IpfsMock Uses

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.

func NewIpfsMock Uses

func NewIpfsMock(t *testing.T) *IpfsMock

NewIpfsMock returns a new mock.

func (*IpfsMock) Close Uses

func (m *IpfsMock) Close()

Close closes the mock server. It's important to call after each test or the listeners are left hanging around.

func (*IpfsMock) GetCount Uses

func (m *IpfsMock) GetCount(path string) int

GetCount allows to get the number of times and endpoint was called. Do not use concurrently to requests happening.

type ShardingTestHelper Uses

type ShardingTestHelper struct {
    // contains filtered or unexported fields
}

ShardingTestHelper helps generating files and folders to test adding and sharding in IPFS Cluster

func NewShardingTestHelper Uses

func NewShardingTestHelper() *ShardingTestHelper

NewShardingTestHelper returns a new helper.

func (*ShardingTestHelper) Clean Uses

func (sth *ShardingTestHelper) Clean(t *testing.T)

Clean deletes any folder and file generated by this helper.

func (*ShardingTestHelper) GetRandFileMultiReader Uses

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 Uses

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 Uses

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 Uses

func (sth *ShardingTestHelper) GetTreeSerialFile(t *testing.T) files.Directory

GetTreeSerialFile returns a files.Directory pointing to the testing directory tree (see GetTreeMultiReader).

Package test imports 30 packages (graph). Updated 2020-06-07. Refresh now. Tools for package owners.