test

package
v0.0.0-...-6646f2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 26 Imported by: 0

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

View Source
const (
	IpfsCustomHeaderName  = "X-Custom-Header"
	IpfsTimeHeaderName    = "X-Time-Now"
	IpfsCustomHeaderValue = "42"
	IpfsACAOrigin         = "myorigin"
)

Some values used by the ipfs mock

Variables

View Source
var (
	TestCid1     = "QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq"
	TestCid2     = "QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmma"
	TestCid3     = "QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmb"
	TestCid4     = "zb2rhiKhUepkTMw7oFfBUnChAN7ABAvg2hXUwmTBtZ6yxuc57"
	TestCid4Data = "Cid4Data" // Cid resulting from block put NOT ipfs add
	TestSlowCid1 = "QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmd"
	// ErrorCid is meant to be used as a Cid which causes errors. i.e. the
	// ipfs mock fails when pinning this CID.
	ErrorCid       = "QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmc"
	TestPeerID1, _ = peer.IDB58Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc")
	TestPeerID2, _ = peer.IDB58Decode("QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6")
	TestPeerID3, _ = peer.IDB58Decode("QmPGDFvBkgWhvzEK9qaTWrWurSwqXNmhnK3hgELPdZZNPa")
	TestPeerID4, _ = peer.IDB58Decode("QmZ8naDy5mEz4GLuQwjWt9MPYqHTBbsm8tQBrNSjiq6zBc")
	TestPeerID5, _ = peer.IDB58Decode("QmZVAo3wd8s5eTTy2kPYs34J9PvfxpKPuYsePPYGjgRRjg")
	TestPeerID6, _ = peer.IDB58Decode("QmR8Vu6kZk7JvAN2rWVWgiduHatgBq2bb15Yyq8RRhYSbx")

	TestPeerName1 = "TestPeer1"
	TestPeerName2 = "TestPeer2"
	TestPeerName3 = "TestPeer3"
	TestPeerName4 = "TestPeer4"
	TestPeerName5 = "TestPeer5"
	TestPeerName6 = "TestPeer6"
)

Common variables used all around tests.

View Source
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 wrap=true and default parameters). Then doing
	// `refs -r` on the result. It contains the wrapping folder hash.
	ShardingDirCids = [29]string{
		"QmbfGRPTUd7L1xsAZZ1A3kUFP1zkEZ9kHdb6AGaajBzGGX",
		"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
	TestShardCid     = "zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh"
	TestShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a")
)

Variables related to adding the testing directory generated by tests

View Source
var ErrBadCid = errors.New("this is an expected error when using ErrorCid")

ErrBadCid is returned when using ErrorCid. Operations with that CID always fail.

Functions

func MustDecodeCid

func MustDecodeCid(v string) cid.Cid

MustDecodeCid provides a test helper that ignores errors from cid.Decode.

func NewMockRPCClient

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

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

func NewMockRPCClientWithHost

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

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

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.

func NewIpfsMock

func NewIpfsMock() *IpfsMock

NewIpfsMock returns a new mock.

func (*IpfsMock) Close

func (m *IpfsMock) Close()

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

type ShardingTestHelper

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

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

func NewShardingTestHelper

func NewShardingTestHelper() *ShardingTestHelper

NewShardingTestHelper returns a new helper.

func (*ShardingTestHelper) Clean

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

Clean deletes any folder and file generated by this helper.

func (*ShardingTestHelper) GetRandFileMultiReader

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

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

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL