Documentation ¶
Overview ¶
Package utils provides useful standalone function for test and network, etc.
Index ¶
- Variables
- func ConcatAll(args ...[]byte) []byte
- func CopyFile(src, dst string) (int64, error)
- func DecodeMsgPack(buf []byte, out interface{}) error
- func DecodeMsgPackPlain(buf []byte, out interface{}) error
- func DupConf(confFile string, newConfFile string) (err error)
- func EncodeMsgPack(in interface{}) (*bytes.Buffer, error)
- func Exist(path string) bool
- func GetMsgPackClientCodec(c io.ReadWriteCloser) rpc.ClientCodec
- func GetMsgPackServerCodec(c io.ReadWriteCloser) rpc.ServerCodec
- func GetProjectSrcDir() string
- func GetRandomPorts(bindAddr string, minPort, maxPort, count int) (ports []int, err error)
- func HomeDirExpand(path string) string
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func RegisterInterfaceToMsgPack(intf, impl reflect.Type) (err error)
- func RemoveAll(pattern string)
- func RemoveDuplicatesUnordered(elements []string) []string
- func RunCommand(bin string, args []string, processName string, workingDir string, ...) (err error)
- func StartProfile(cpuprofile, memprofile string) error
- func StopProfile()
- func WaitForExit() <-chan os.Signal
- func WaitForPorts(ctx context.Context, bindAddr string, ports []int, interval time.Duration) (err error)
- func WaitToConnect(ctx context.Context, bindAddr string, ports []int, interval time.Duration) (err error)
- type CMD
- type Once
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotEnoughPorts defines error indicating random port allocation failure. ErrNotEnoughPorts = errors.New("not enough ports in port range") )
var FJ = filepath.Join
FJ is short for filepath.Join.
Functions ¶
func CopyFile ¶
CopyFile copies from src to dst until either EOF is reached on src or an error occurs. It verifies src exists and removes the dst if it exists.
func DecodeMsgPack ¶
DecodeMsgPack reverses the encode operation on a byte slice input.
func DecodeMsgPackPlain ¶
DecodeMsgPackPlain reverses the encode operation on a byte slice input without RawToString setting.
func DupConf ¶
DupConf duplicate conf file using random new listen addr to avoid failure on concurrent test cases.
func EncodeMsgPack ¶
EncodeMsgPack writes an encoded object to a new bytes buffer.
func GetMsgPackClientCodec ¶
func GetMsgPackClientCodec(c io.ReadWriteCloser) rpc.ClientCodec
GetMsgPackClientCodec returns msgpack client codec for connection.
func GetMsgPackServerCodec ¶
func GetMsgPackServerCodec(c io.ReadWriteCloser) rpc.ServerCodec
GetMsgPackServerCodec returns msgpack server codec for connection.
func GetRandomPorts ¶
GetRandomPorts returns available random ports, previously allocated ports will be ignored.
func HomeDirExpand ¶
HomeDirExpand tries to expand the tilde (~) in the front of a path to a fullpath directory.
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func RegisterInterfaceToMsgPack ¶
RegisterInterfaceToMsgPack binds interface decode/encode to specified implementation.
func RemoveDuplicatesUnordered ¶
RemoveDuplicatesUnordered de-duplicate elements in string slice.
func RunCommand ¶
func RunCommand(bin string, args []string, processName string, workingDir string, logDir string, toStd bool) (err error)
RunCommand runs a command and capture its output to a log file,
if toStd is true also output to stdout and stderr.
func StartProfile ¶
StartProfile initializes the CPU and memory profile, if specified.
func StopProfile ¶
func StopProfile()
StopProfile closes the CPU and memory profiles if they are running.
func WaitForExit ¶
WaitForExit waits for user cancellation signals: SIGINT/SIGTERM and ignore SIGHUP/SIGTTIN/SIGTTOU.