utils

package
v0.0.0-...-143a0bd Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: GPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DockerContainerAddress

func DockerContainerAddress(ctx context.Context, client *client.Client, id string) (string, error)

func DockerExec

func DockerExec(
	ctx context.Context, client *client.Client, logger *zap.Logger, containerId string,
	cmd []string, stdin io.Reader, stdout io.Writer, stderr io.Writer,
) error

DockerExec runs a command in a container, forwards its stdin/stdout/stderr to/from the reader/writers passed as arguments and waits for the command to complete with exit code 0.

func DockerImagePull

func DockerImagePull(ctx context.Context, logger *zap.Logger, dockerClient *client.Client, image string, force bool) error

DockerImagePull pulls an image from the registry. If force=false, no pull is done if the image already exists.

func DockerNetworkName

func DockerNetworkName(ctx context.Context, client *client.Client, id string) (string, error)

func ForwardDockerContainerOutput

func ForwardDockerContainerOutput(
	ctx context.Context, client *client.Client, containerId string, logs bool, w io.Writer,
) error

ForwardDockerContainerOutput attaches to a docker container and forwards all its output to a writer.

func GetEnvDefault

func GetEnvDefault(key string, def string) string

GetEnvDefault returns the value of an environment variable or a default value if the variable is not set.

func MakeVariants

func MakeVariants(base interface{}) *variants

func MustString

func MustString(s string, err error) string

MustString panics if err != nil and returns s otherwise.

func MustT

func MustT(t testing.TB) mustT

MustT returns a struct with receiver functions that fail the given testing.TB on errors.

For example, MustT(t).String(fn()), where fn is of type func() (string, error), returns the string returned by fn if it did not return an error, or calls t.Fatal(err) otherwise.

func PrettySelect

func PrettySelect(db DB, query string, args ...interface{}) (string, error)

PrettySelect performs a query on the given database connection, retrieves the result set, pretty-prints it and returns the result as a string suitable for writing into a log for debugging.

Example usage:

t.Log(utils.MustT(t).String(utils.PrettySelect(db, "SELECT * FROM somewhere")))

func RandomString

func RandomString(len int) string

RandomString returns a string of length len consisting of random characters (alphanumeric).

func UniqueName

func UniqueName(t testing.TB, hint string) string

Types

type DB

type DB interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

DB is an interface that contains functions provided by *database/sql.DB and *github.com/jmoiron/sqlx.DB required by functions in this package so that in can be used with both.

type Icinga2Client

type Icinga2Client struct {
	http.Client
}

func NewIcinga2Client

func NewIcinga2Client(address string, username string, password string) *Icinga2Client

func (*Icinga2Client) CreateHost

func (c *Icinga2Client) CreateHost(t testing.TB, name string, body interface{})

func (*Icinga2Client) CreateObject

func (c *Icinga2Client) CreateObject(t testing.TB, typ string, name string, body interface{})

func (*Icinga2Client) CreateService

func (c *Icinga2Client) CreateService(t testing.TB, host string, service string, body interface{})

func (*Icinga2Client) DeleteHost

func (c *Icinga2Client) DeleteHost(t testing.TB, name string, cascade bool)

func (*Icinga2Client) DeleteJson

func (c *Icinga2Client) DeleteJson(url string) (*http.Response, error)

func (*Icinga2Client) DeleteObject

func (c *Icinga2Client) DeleteObject(t testing.TB, typ string, name string, cascade bool)

func (*Icinga2Client) DeleteService

func (c *Icinga2Client) DeleteService(t testing.TB, host string, service string, cascade bool)

func (*Icinga2Client) Do

func (c *Icinga2Client) Do(req *http.Request) (*http.Response, error)

func (*Icinga2Client) GetJson

func (c *Icinga2Client) GetJson(url string) (*http.Response, error)

func (*Icinga2Client) PostJson

func (c *Icinga2Client) PostJson(url string, body io.Reader) (*http.Response, error)

func (*Icinga2Client) PutJson

func (c *Icinga2Client) PutJson(url string, body io.Reader) (*http.Response, error)

func (*Icinga2Client) UpdateObject

func (c *Icinga2Client) UpdateObject(t testing.TB, typ string, name string, body interface{})

type LineWriter

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

LineWriter implements io.WriteCloser and calls the given callback for every line written to it.

func NewLineWriter

func NewLineWriter(callback func([]byte)) *LineWriter

func (*LineWriter) Close

func (l *LineWriter) Close() error

func (*LineWriter) Write

func (l *LineWriter) Write(in []byte) (int, error)

type VariantInfo

type VariantInfo struct {
	Field string
	Index int
	Value interface{}
}

func (*VariantInfo) SetVariantInfo

func (v *VariantInfo) SetVariantInfo(field string, index int, value interface{})

func (*VariantInfo) VariantInfoString

func (v *VariantInfo) VariantInfoString() string

type VariantInfoSetter

type VariantInfoSetter interface {
	SetVariantInfo(field string, index int, value interface{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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