utils

package
v6.0.0-...-53d976b Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultWaitTimeout   = 90
	OSReleasePath        = "/etc/os-release"
	ProcessOneCgroupPath = "/proc/1/cgroup"
)

Functions

func Containerized

func Containerized() bool

Containerized check the podman command run inside container

func ExitCleanly

func ExitCleanly() types.GomegaMatcher

ExitCleanly asserts that a PodmanSession exits 0 and with no stderr Consider using PodmanTestIntegration.PodmanExitCleanly instead of directly using this matcher.

func IsCommandAvailable

func IsCommandAvailable(command string) bool

IsCommandAvailable check if command exist

func RandomString

func RandomString(n int) string

RandomString returns a string of given length composed of random characters

func WaitContainerReady

func WaitContainerReady(p PodmanTestCommon, id string, expStr string, timeout int, step int) bool

WaitContainerReady is a wrapper function for accept inheritance PodmanTest struct.

func WaitForContainer

func WaitForContainer(p PodmanTestCommon) bool

WaitForContainer is a wrapper function for accept inheritance PodmanTest struct.

func WriteJSONFile

func WriteJSONFile(data []byte, filePath string) error

WriteJSONFile write json format data to a json file

func WriteRSAKeyPair

func WriteRSAKeyPair(fileName string, bitSize int) (string, string, error)

Generate RSA key pair of specified bit size and write them to files. Adds appropriate extension to the fileName, and returns the complete fileName of the files storing the public and private key respectively.

Types

type ExitMatcher

type ExitMatcher struct {
	types.GomegaMatcher
	ExpectedExitCode    int
	ExitCode            int
	ExpectedStderr      string
	ExpectedStderrRegex string
	// contains filtered or unexported fields
}

func ExitWithError

func ExitWithError(expectExitCode int, expectStderr string) *ExitMatcher

ExitWithError checks both exit code and stderr, fails if either does not match Modeled after the gomega Exit() matcher and also operates on sessions.

func ExitWithErrorRegex

func ExitWithErrorRegex(expectExitCode int, expectStderrRegex string) *ExitMatcher

ExitWithErrorRegex checks both exit code and the stderr regex, fails if either does not match Modeled after the gomega Exit() matcher and also operates on sessions.

func (*ExitMatcher) FailureMessage

func (matcher *ExitMatcher) FailureMessage(_ any) (message string)

func (*ExitMatcher) Match

func (matcher *ExitMatcher) Match(actual any) (success bool, err error)

Match follows gexec.Matcher interface.

func (*ExitMatcher) MatchMayChangeInTheFuture

func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual any) bool

func (*ExitMatcher) NegatedFailureMessage

func (matcher *ExitMatcher) NegatedFailureMessage(_ any) (message string)

type HostOS

type HostOS struct {
	Distribution string
	Version      string
	Arch         string
}

HostOS is a simple struct for the test os

func GetHostDistributionInfo

func GetHostDistributionInfo() HostOS

GetHostDistributionInfo returns a struct with its distribution Name and version

type NetworkBackend

type NetworkBackend int
const (
	// Container Networking backend
	CNI NetworkBackend = iota
	// Netavark network backend
	Netavark NetworkBackend = iota
	// Env variable for creating time files.
	EnvTimeDir = "_PODMAN_TIME_DIR"
)

func (NetworkBackend) ToString

func (n NetworkBackend) ToString() string

type PodmanExecOptions

type PodmanExecOptions struct {
	UID, GID         uint32   // default: inherited form the current process
	CWD              string   // default: inherited form the current process
	Env              []string // default: inherited form the current process
	NoEvents         bool
	NoCache          bool
	Wrapper          []string  // A command to run, receiving the Podman command line. default: none
	FullOutputWriter io.Writer // Receives the full output (stdout+stderr) of the command, in _approximately_ correct order. default: GinkgoWriter
	ExtraFiles       []*os.File
}

PodmanExecOptions modify behavior of PodmanTest.PodmanExecBaseWithOptions and its callers. Users should typically leave most fields default-initialized, and only set those that are relevant to them.

type PodmanSession

type PodmanSession struct {
	*Session
}

PodmanSession wraps the gexec.session so we can extend it

func StartSystemExec

func StartSystemExec(command string, args []string) *PodmanSession

StartSystemExec is used to start exec a system command

func SystemExec

func SystemExec(command string, args []string) *PodmanSession

SystemExec is used to exec a system command to check its exit code or output

func (*PodmanSession) ErrorGrepString

func (s *PodmanSession) ErrorGrepString(term string) (bool, []string)

ErrorGrepString takes session stderr output and behaves like grep. it returns a bool if successful and an array of strings on positive matches

func (*PodmanSession) ErrorToString

func (s *PodmanSession) ErrorToString() string

ErrorToString formats session stderr to string

func (*PodmanSession) ErrorToStringArray

func (s *PodmanSession) ErrorToStringArray() []string

ErrorToStringArray returns the stderr output as a []string where each array item is a line split by newline

func (*PodmanSession) GrepString

func (s *PodmanSession) GrepString(term string) (bool, []string)

GrepString takes session output and behaves like grep. it returns a bool if successful and an array of strings on positive matches

func (*PodmanSession) IsJSONOutputValid

func (s *PodmanSession) IsJSONOutputValid() bool

IsJSONOutputValid attempts to unmarshal the session buffer and if successful, returns true, else false

func (*PodmanSession) LineInOutputContains

func (s *PodmanSession) LineInOutputContains(term string) bool

LineInOutputContains returns true if a line in a session output contains the supplied string

func (*PodmanSession) LineInOutputContainsTag

func (s *PodmanSession) LineInOutputContainsTag(repo, tag string) bool

LineInOutputContainsTag returns true if a line in the session's output contains the repo-tag pair as returned by podman-images(1).

func (*PodmanSession) LineInOutputStartsWith

func (s *PodmanSession) LineInOutputStartsWith(term string) bool

LineInOutputStartsWith returns true if a line in a session output starts with the supplied string

func (*PodmanSession) OutputToString

func (s *PodmanSession) OutputToString() string

OutputToString formats session output to string

func (*PodmanSession) OutputToStringArray

func (s *PodmanSession) OutputToStringArray() []string

OutputToStringArray returns the output as a []string where each array item is a line split by newline

func (*PodmanSession) WaitWithDefaultTimeout

func (s *PodmanSession) WaitWithDefaultTimeout()

WaitWithDefaultTimeout waits for process finished with DefaultWaitTimeout

func (*PodmanSession) WaitWithTimeout

func (s *PodmanSession) WaitWithTimeout(timeout int)

WaitWithTimeout waits for process finished with DefaultWaitTimeout

type PodmanTest

type PodmanTest struct {
	ImageCacheDir           string
	ImageCacheFS            string
	NetworkBackend          NetworkBackend
	DatabaseBackend         string
	PodmanBinary            string
	PodmanMakeOptions       func(args []string, options PodmanExecOptions) []string
	RemoteCommand           *exec.Cmd
	RemotePodmanBinary      string
	RemoteSession           *os.Process
	RemoteSocket            string
	RemoteSocketScheme      string
	RemoteSocketLock        string // If not "", should be removed _after_ RemoteSocket is removed
	RemoteTLSClientCAFile   string
	RemoteTLSClientCAPool   *x509.CertPool
	RemoteTLSClientCerts    []tls.Certificate
	RemoteTLSServerCertFile string
	RemoteTLSServerKeyFile  string
	RemoteTLSServerCAFile   string
	RemoteTLSServerCAPool   *x509.CertPool
	RemoteTLSClientCertFile string
	RemoteTLSClientKeyFile  string
	RemoteTest              bool
	TempDir                 string
}

PodmanTest struct for command line options

func (*PodmanTest) GetContainerStatus

func (p *PodmanTest) GetContainerStatus() string

GetContainerStatus returns the containers state. This function assumes only one container is active.

func (*PodmanTest) MakeOptions

func (p *PodmanTest) MakeOptions(args []string, options PodmanExecOptions) []string

MakeOptions assembles all podman options

func (*PodmanTest) NumberOfContainers

func (p *PodmanTest) NumberOfContainers() int

NumberOfContainers returns an int of how many containers are currently defined.

func (*PodmanTest) NumberOfContainersRunning

func (p *PodmanTest) NumberOfContainersRunning() int

NumberOfContainersRunning returns an int of how many containers are currently running.

func (*PodmanTest) NumberOfPods

func (p *PodmanTest) NumberOfPods() int

NumberOfPods returns an int of how many pods are currently defined.

func (*PodmanTest) PodmanExecBaseWithOptions

func (p *PodmanTest) PodmanExecBaseWithOptions(args []string, options PodmanExecOptions) *PodmanSession

PodmanExecBaseWithOptions execs podman with the specified args, and in an environment defined by options

func (*PodmanTest) WaitContainerReady

func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, step int) bool

WaitContainerReady waits process or service inside container start, and ready to be used.

func (*PodmanTest) WaitForContainer

func (p *PodmanTest) WaitForContainer() bool

WaitForContainer waits on a started container

type PodmanTestCommon

type PodmanTestCommon interface {
	MakeOptions(args []string, options PodmanExecOptions) []string
	WaitForContainer() bool
	WaitContainerReady(id string, expStr string, timeout int, step int) bool
}

PodmanTestCommon contains common functions will be updated later in the inheritance structs

type ValidJSONMatcher

type ValidJSONMatcher struct {
	types.GomegaMatcher
}

func BeValidJSON

func BeValidJSON() *ValidJSONMatcher

func (*ValidJSONMatcher) FailureMessage

func (matcher *ValidJSONMatcher) FailureMessage(actual any) (message string)

func (*ValidJSONMatcher) Match

func (matcher *ValidJSONMatcher) Match(actual any) (success bool, err error)

func (*ValidJSONMatcher) NegatedFailureMessage

func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual any) (message string)

Jump to

Keyboard shortcuts

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