utils

package
v4.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 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 CreateTempDirInTempDir

func CreateTempDirInTempDir() (string, error)

CreateTempDirInTempDir create a temp dir with prefix podman_test

func HaveActiveService

func HaveActiveService(name interface{}) OmegaMatcher

HaveActiveService verifies the given service is the active service.

func IsCommandAvailable

func IsCommandAvailable(command string) bool

IsCommandAvailable check if command exist

func IsKernelNewerThan

func IsKernelNewerThan(version string) (bool, error)

IsKernelNewerThan compares the current kernel version to one provided. If the kernel is equal to or greater, returns true

func RandomString

func RandomString(n int) string

RandomString returns a string of given length composed of random characters

func StringInSlice

func StringInSlice(s string, sl []string) bool

StringInSlice determines if a string is in a string slice, returns bool

func VerifyService

func VerifyService(name, uri, identity interface{}) OmegaMatcher

func VerifyURL

func VerifyURL(uri interface{}) OmegaMatcher

VerifyURL matches when actual is a valid URL and matches expected.

func WaitContainerReady

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

WaitForContainerReady 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

Types

type ExitMatcher

type ExitMatcher struct {
	types.GomegaMatcher
	Expected int
	Actual   int
}

func ExitWithError

func ExitWithError(optionalExitCode ...int) *ExitMatcher

ExitWithError matches when assertion is > argument. Default 0 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
	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 ServiceMatcher

type ServiceMatcher struct {
	types.GomegaMatcher
	Name     interface{}
	URI      interface{}
	Identity interface{}
	// contains filtered or unexported fields
}

func (*ServiceMatcher) FailureMessage

func (matcher *ServiceMatcher) FailureMessage(_ interface{}) string

func (*ServiceMatcher) Match

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

func (*ServiceMatcher) NegatedFailureMessage

func (matcher *ServiceMatcher) NegatedFailureMessage(_ interface{}) string

type URLMatcher

type URLMatcher struct {
	matchers.EqualMatcher
}

func (*URLMatcher) Match

func (matcher *URLMatcher) Match(actual interface{}) (bool, error)

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