util

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanTestBrokerAdmin added in v1.0.0

func CanTestBrokerAdmin() bool

CanTestBrokerAdmin returns whether we can test the broker-only admin client.

func CopyInts

func CopyInts(input []int) []int

CopyInts copies a slice of ints.

func InTerminal

func InTerminal() bool

InTerminal determines whether we're running in a terminal or not.

Implementation from https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Go.

func PrettyDuration

func PrettyDuration(duration time.Duration) string

PrettyDuration returns a human-formatted duration string given an golang duration value.

func PrettyRate

func PrettyRate(count int64, duration time.Duration) string

PrettyRate returns a human-formatted rate from a count and a duration.

func RandomString

func RandomString(prefix string, length int) string

RandomString returns a random string with the argument length.

Adapted from the example in https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go.

func RetryUntil added in v1.0.0

func RetryUntil(t *testing.T, timeout time.Duration, f func() error)

RetryUntil is a helper that will re-run the argument function multiple times (up to a duration limit) until it no longer produces an error.

func SameElements

func SameElements(slice1 []int, slice2 []int) bool

SameElements determines whether two int slices have the same elements (in any order).

func ShuffledKeys

func ShuffledKeys(input map[int]int, seedStr string) []int

ShuffledKeys returns a shuffled version of the keys in the argument map. The provided seedStr is hashed and used to seed the random number generator.

func SortedKeys

func SortedKeys(input map[int]int) []int

SortedKeys returns the keys of the argument, sorted by value.

func SortedKeysByValue

func SortedKeysByValue(input map[int]int, asc bool, keySorter KeySorter) []int

SortedKeysByValue returns the keys in a map, sorted by the map values.

func TestKafkaAddr

func TestKafkaAddr() string

TestKafkaAddr returns a kafka bootstrap address for unit testing purposes.

func TestZKAddr

func TestZKAddr() string

TestZKAddr returns a zookeeper address for unit testing purposes.

func TruncateStringMiddle

func TruncateStringMiddle(input string, maxLen int, suffixLen int) (string, int)

TruncateStringMiddle truncates a string by replacing characters in the middle with "..." if needed.

func TruncateStringSuffix

func TruncateStringSuffix(input string, maxLen int) (string, int)

TruncateStringSuffix truncates a string by replacing the trailing characters with "..." if needed.

Types

type KeySorter

type KeySorter func(map[int]int) []int

KeySorter is a type for a function that sorts integer keys based on their values in a map.

Jump to

Keyboard shortcuts

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