testutil

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0, MIT Imports: 38 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnContextKey = &contextKey{"http-conn"}

Functions

func CreateDenseCARWith added in v1.5.1

func CreateDenseCARWith(dir, src string, chunksize int64, maxlinks int, caropts []car.Option) (cid.Cid, string, error)

CreateDenseCARv2 generates a "dense" UnixFS CARv2 from the supplied ordinary file. A dense UnixFS CARv2 is one storing leaf data. Contrast to CreateRefCARv2.

func CreateDenseCARv2

func CreateDenseCARv2(dir, src string) (cid.Cid, string, error)

func CreateRandomFile

func CreateRandomFile(dir string, rseed, size int) (string, error)

CreateRandomFile

func GenerateBlocksOfSize

func GenerateBlocksOfSize(n int, size int64) []blocks.Block

GenerateBlocksOfSize generates a series of blocks of the given byte size

func GenerateCid

func GenerateCid() cid.Cid

func GenerateCids

func GenerateCids(n int) []cid.Cid

GenerateCids produces n content identifiers.

func GeneratePeer

func GeneratePeer() peer.ID

func GeneratePeers

func GeneratePeers(n int) []peer.ID

GeneratePeers creates n peer ids.

func GetConn

func GetConn(r *http.Request) net.Conn

func HttpTestDisconnectingServer

func HttpTestDisconnectingServer(t *testing.T, dir string, afterEvery int64) *httptest.Server

HttpTestDisconnectingServer returns a test http server that serves files from the given directory but disconnects after sending `afterEvery` bytes starting at the start offset mentioned in the Range request.

func HttpTestFileServer

func HttpTestFileServer(t *testing.T, dir string) (*httptest.Server, error)

HttpTestFileServer returns a http server that serves files from the given directory with some latency

func RandomBytes

func RandomBytes(n int64) []byte

RandomBytes returns a byte array of the given size with random values.

func SaveConnInContext

func SaveConnInContext(ctx context.Context, c net.Conn) context.Context

func WriteUnixfsDAGTo

func WriteUnixfsDAGTo(path string, into ipldformat.DAGService, chunksize int64, maxlinks int) (cid.Cid, error)

Types

type BlockingHttpTestServer

type BlockingHttpTestServer struct {
	URL string
	// contains filtered or unexported fields
}

BlockingHttpTestServer returns an http server that blocks for a given file until the client unblocks the serving of the file.

func NewBlockingHttpTestServer

func NewBlockingHttpTestServer(t *testing.T, dir string) *BlockingHttpTestServer

func (*BlockingHttpTestServer) AddFile

func (b *BlockingHttpTestServer) AddFile(name string)

func (*BlockingHttpTestServer) Close

func (b *BlockingHttpTestServer) Close()

func (*BlockingHttpTestServer) Start

func (b *BlockingHttpTestServer) Start()

func (*BlockingHttpTestServer) UnblockFile

func (b *BlockingHttpTestServer) UnblockFile(name string)

type CarRes

type CarRes struct {
	CarFile    string
	OrigFile   string
	Root       cid.Cid
	Blockstore bstore.Blockstore
	CarSize    uint64
}

type HttpTestServer

type HttpTestServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

func HttpTestUnstartedFileServer

func HttpTestUnstartedFileServer(t *testing.T, dir string) *HttpTestServer

HttpTestUnstartedFileServer returns a http server that serves files from the given directory

func (*HttpTestServer) SetWorking

func (s *HttpTestServer) SetWorking(working bool)

type SlowFileOpener

type SlowFileOpener struct {
	Dir string
}

func (*SlowFileOpener) Open

func (s *SlowFileOpener) Open(name string) (http.File, error)

type SlowReader

type SlowReader struct {
	*os.File
}

func (*SlowReader) Read

func (r *SlowReader) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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