utils

package
v5.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 20 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

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
	// 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 (*ExitMatcher) FailureMessage

func (matcher *ExitMatcher) FailureMessage(_ interface{}) (message string)

func (*ExitMatcher) Match

func (matcher *ExitMatcher) Match(actual interface{}) (success bool, err error)

Match follows gexec.Matcher interface.

func (*ExitMatcher) MatchMayChangeInTheFuture

func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool

func (*ExitMatcher) NegatedFailureMessage

func (matcher *ExitMatcher) NegatedFailureMessage(_ interface{}) (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 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, noEvents, noCache bool) []string
	RemoteCommand      *exec.Cmd
	RemotePodmanBinary string
	RemoteSession      *os.Process
	RemoteSocket       string
	RemoteSocketLock   string // If not "", should be removed _after_ RemoteSocket is removed
	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, noEvents, noCache bool) []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) PodmanAsUserBase

func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string, noEvents, noCache bool, wrapper []string, extraFiles []*os.File) *PodmanSession

PodmanAsUserBase exec podman as user. uid and gid is set for credentials usage. env is used to record the env for debugging

func (*PodmanTest) PodmanBase

func (p *PodmanTest) PodmanBase(args []string, noEvents, noCache bool) *PodmanSession

PodmanBase exec podman with default env.

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, noEvents, noCache bool) []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 interface{}) (message string)

func (*ValidJSONMatcher) Match

func (matcher *ValidJSONMatcher) Match(actual interface{}) (success bool, err error)

func (*ValidJSONMatcher) NegatedFailureMessage

func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual interface{}) (message string)

Jump to

Keyboard shortcuts

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