testutil

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: CC0-1.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testutil contains common datastructures and functions for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCaller

func GetCaller(level int) (string, string)

GetCaller returns the calling function of the function which called it and the code location which called the calling function. Can optionally go further back depending on the level parameter.

For example testfile.go:

20: foo() { 21: x := GetCaller(0) 22: } 23: 24: bar() { 25: foo() 26: }

In the example x would be set to "bar" and location would be testfile.go 25.

Types

type ErrorTestingBuffer

type ErrorTestingBuffer struct {
	RemainingSize int
	WrittenSize   int
}

ErrorTestingBuffer is a testing buffer to test error handling for writing operations.

func (ErrorTestingBuffer) Error

func (etb ErrorTestingBuffer) Error() string

Error returns buffer errors. For simplicity the buffer itself implements the error interface.

func (*ErrorTestingBuffer) Write

func (etb *ErrorTestingBuffer) Write(p []byte) (n int, err error)

Write simulates writing to the test buffer. Returns error if it is full.

type ErrorTestingConnection

type ErrorTestingConnection struct {
	In  bytes.Buffer
	Out bytes.Buffer

	InErr int

	OutErr   int
	OutClose bool
	// contains filtered or unexported fields
}

ErrorTestingConnection testing object for connection errors.

func (*ErrorTestingConnection) Close

func (c *ErrorTestingConnection) Close() error

Close is a method stub to satisfy the net.Conn interface.

func (*ErrorTestingConnection) LocalAddr

func (c *ErrorTestingConnection) LocalAddr() net.Addr

LocalAddr is a method stub to satisfy the net.Conn interface.

func (*ErrorTestingConnection) Read

func (c *ErrorTestingConnection) Read(b []byte) (n int, err error)

Read reads from the test connection in buffer.

func (*ErrorTestingConnection) RemoteAddr

func (c *ErrorTestingConnection) RemoteAddr() net.Addr

RemoteAddr is a method stub to satisfy the net.Conn interface.

func (*ErrorTestingConnection) SetDeadline

func (c *ErrorTestingConnection) SetDeadline(t time.Time) error

SetDeadline is a method stub to satisfy the net.Conn interface.

func (*ErrorTestingConnection) SetReadDeadline

func (c *ErrorTestingConnection) SetReadDeadline(t time.Time) error

SetReadDeadline is a method stub to satisfy the net.Conn interface.

func (*ErrorTestingConnection) SetWriteDeadline

func (c *ErrorTestingConnection) SetWriteDeadline(t time.Time) error

SetWriteDeadline is a method stub to satisfy the net.Conn interface.

func (*ErrorTestingConnection) Write

func (c *ErrorTestingConnection) Write(b []byte) (n int, err error)

Write write to the test connections buffer.

type ErrorTestingFile

type ErrorTestingFile struct {
	Buf *ErrorTestingBuffer
}

ErrorTestingFile is a testing buffer which can be used as an io.File like object.

func NewTestingFile

func NewTestingFile(size int) *ErrorTestingFile

NewTestingFile creates a new test file.

func (ErrorTestingFile) Close

func (etf ErrorTestingFile) Close() error

Close does nothing (there to satisfy interfaces)

func (ErrorTestingFile) Sync

func (etf ErrorTestingFile) Sync() error

Sync does nothing (there to satisfy interfaces)

func (ErrorTestingFile) Write

func (etf ErrorTestingFile) Write(p []byte) (n int, err error)

Write writes to the file.

type GobTestObject

type GobTestObject struct {
	Name   string
	EncErr bool
	DecErr bool
}

GobTestObject testing object for gob errors.

func (*GobTestObject) GobDecode

func (t *GobTestObject) GobDecode(b []byte) error

GobDecode decodes the given byte array are returns an error.

func (*GobTestObject) GobEncode

func (t *GobTestObject) GobEncode() ([]byte, error)

GobEncode returns a test encoded byte array or an error.

Jump to

Keyboard shortcuts

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