framework

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Aufs         string = "aufs"
	Overlay      string = "overlay"
	Overlay2     string = "overlay2"
	DeviceMapper string = "devicemapper"
	Unknown      string = ""
)

Variables

This section is empty.

Functions

func ContainsLabelValue added in v0.57.0

func ContainsLabelValue(mf *dto.MetricFamily, labelName, substring string) bool

ContainsLabelValue checks if any metric in the family has the label containing the given substring.

func CountMetrics added in v0.57.0

func CountMetrics(mf *dto.MetricFamily) int

CountMetrics returns the number of metric samples in a metric family.

func FindMetricWithLabels added in v0.57.0

func FindMetricWithLabels(mf *dto.MetricFamily, labels map[string]string) *dto.Metric

FindMetricWithLabels finds a metric matching all specified labels. Returns nil if no matching metric is found.

func FindMetricsWithLabelSubstring added in v0.57.0

func FindMetricsWithLabelSubstring(mf *dto.MetricFamily, labelName, substring string) []*dto.Metric

FindMetricsWithLabelSubstring finds all metrics where the specified label contains the given substring.

func GetAllLabelValues added in v0.57.0

func GetAllLabelValues(mf *dto.MetricFamily, labelName string) []string

GetAllLabelValues returns all unique values for a given label name across all metrics in the family.

func GetCounterValue added in v0.57.0

func GetCounterValue(metric *dto.Metric) float64

GetCounterValue extracts the value from a counter metric.

func GetGaugeValue added in v0.57.0

func GetGaugeValue(metric *dto.Metric) float64

GetGaugeValue extracts the value from a gauge metric.

func GetLabelValue added in v0.57.0

func GetLabelValue(metric *dto.Metric, labelName string) string

GetLabelValue returns the value of a specific label from a metric. Returns empty string if label is not found.

func GetMetricFamily added in v0.57.0

func GetMetricFamily(families map[string]*dto.MetricFamily, name string) (*dto.MetricFamily, bool)

GetMetricFamily returns a specific metric family by name.

func GetMetricType added in v0.57.0

func GetMetricType(mf *dto.MetricFamily) string

GetMetricType returns the type of a metric family as a string.

func HasMetric added in v0.57.0

func HasMetric(families map[string]*dto.MetricFamily, name string) bool

HasMetric checks if a metric family exists by name.

func RetryForDuration

func RetryForDuration(retryFunc func() error, dur time.Duration) error

Runs retryFunc until no error is returned. After dur time the last error is returned. Note that the function does not timeout the execution of retryFunc when the limit is reached.

Types

type CadvisorActions

type CadvisorActions interface {
	// Returns a cAdvisor client to the machine being tested.
	Client() *client.Client
	ClientV2() *v2.Client
}

type ContainerdActions added in v0.57.0

type ContainerdActions interface {
	// Run the no-op pause containerd container and return its ID.
	RunPause() string

	// Run the specified command in a containerd busybox container and return its ID.
	RunBusybox(cmd ...string) string

	// Runs a containerd container in the background. Uses the specified ContainerdRunArgs and command.
	// Returns the ID of the new container.
	Run(args ContainerdRunArgs, cmd ...string) string
}

ContainerdActions provides methods for managing containerd containers in tests. Containerd containers are created directly using the ctr CLI tool.

type ContainerdRunArgs added in v0.57.0

type ContainerdRunArgs struct {
	// Image to use.
	Image string

	// Container name (optional, auto-generated if empty).
	Name string

	// Labels to add to the container.
	Labels map[string]string
}

ContainerdRunArgs contains arguments for running a containerd container.

type CrioActions added in v0.55.0

type CrioActions interface {
	// Run the no-op pause CRI-O container and return its ID.
	RunPause() string

	// Run the specified command in a CRI-O busybox container and return its ID.
	RunBusybox(cmd ...string) string

	// Runs a CRI-O container in the background. Uses the specified CrioRunArgs and command.
	// Returns the ID of the new container.
	Run(args CrioRunArgs, cmd ...string) string
}

CrioActions provides methods for managing CRI-O containers in tests. CRI-O containers run inside pod sandboxes, so each container requires a pod to be created first.

type CrioRunArgs added in v0.55.0

type CrioRunArgs struct {
	// Image to use.
	Image string

	// Container name (optional, auto-generated if empty).
	Name string
}

CrioRunArgs contains arguments for running a CRI-O container.

type DockerActions

type DockerActions interface {
	// Run the no-op pause Docker container and return its ID.
	RunPause() string

	// Run the specified command in a Docker busybox container and return its ID.
	RunBusybox(cmd ...string) string

	// Runs a Docker container in the background. Uses the specified DockerRunArgs and command.
	// Returns the ID of the new container.
	//
	// e.g.:
	// Run(DockerRunArgs{Image: "busybox"}, "ping", "www.google.com")
	//   -> docker run busybox ping www.google.com
	Run(args DockerRunArgs, cmd ...string) string
	RunStress(args DockerRunArgs, cmd ...string) string

	Version() []string
	StorageDriver() string
}

type DockerRunArgs

type DockerRunArgs struct {
	// Image to use.
	Image string

	// Arguments to the Docker CLI.
	Args []string

	InnerArgs []string
}

type Framework

type Framework interface {
	// Clean the framework state.
	Cleanup()

	// The testing.T used by the framework and the current test.
	T() *testing.T

	// Returns the hostname being tested.
	Hostname() HostnameInfo

	// Returns the Docker actions for the test framework.
	Docker() DockerActions

	// Returns the CRI-O actions for the test framework.
	Crio() CrioActions

	// Returns the containerd actions for the test framework.
	Containerd() ContainerdActions

	// Returns the shell actions for the test framework.
	Shell() ShellActions

	// Returns the cAdvisor actions for the test framework.
	Cadvisor() CadvisorActions
}

Integration test framework.

func New

func New(t *testing.T) Framework

Instantiates a Framework. Cleanup *must* be called. Class is thread-compatible. All framework actions report fatal errors on the t specified at creation time.

Typical use:

func TestFoo(t *testing.T) {
	fm := framework.New(t)
	defer fm.Cleanup()
     ... actual test ...
}

type HostnameInfo

type HostnameInfo struct {
	Host string
	Port int
}

func (HostnameInfo) FullHostname

func (h HostnameInfo) FullHostname() string

Returns: http://<host>:<port>/

type MetricsClient added in v0.57.0

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

MetricsClient provides methods for fetching and parsing Prometheus metrics from cAdvisor's /metrics endpoint.

func NewMetricsClient added in v0.57.0

func NewMetricsClient(hostname HostnameInfo) *MetricsClient

NewMetricsClient creates a new client for the /metrics endpoint.

func (*MetricsClient) Fetch added in v0.57.0

func (m *MetricsClient) Fetch() (string, error)

Fetch retrieves raw metrics text from the /metrics endpoint.

func (*MetricsClient) FetchAndParse added in v0.57.0

func (m *MetricsClient) FetchAndParse() (map[string]*dto.MetricFamily, error)

FetchAndParse combines Fetch and Parse into one call.

func (*MetricsClient) FetchWithParams added in v0.57.0

func (m *MetricsClient) FetchWithParams(params string) (string, error)

FetchWithParams retrieves metrics with optional query parameters. Parameters can be "type=docker" or "type=name" to filter containers.

func (*MetricsClient) Parse added in v0.57.0

func (m *MetricsClient) Parse(metricsText string) (map[string]*dto.MetricFamily, error)

Parse converts Prometheus text format to metric families.

type ShellActions

type ShellActions interface {
	// Runs a specified command and arguments. Returns the stdout and stderr.
	Run(cmd string, args ...string) (string, string)
	RunStress(cmd string, args ...string) (string, string)
}

Jump to

Keyboard shortcuts

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