utils

package
v0.0.0-...-a87cf6f Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	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 IsCommandAvailable

func IsCommandAvailable(command string) bool

IsCommandAvaible 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 StringInSlice

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

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

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 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 PodmanSession

type PodmanSession struct {
	*gexec.Session
}

PodmanSession wraps the gexec.session so we can extend it

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) LineInOuputStartsWith

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

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

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) 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

type PodmanTest

type PodmanTest struct {
	PodmanMakeOptions  func(args []string) []string
	PodmanBinary       string
	ArtifactPath       string
	TempDir            string
	RemoteTest         bool
	RemotePodmanBinary string
	VarlinkSession     *os.Process
}

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) []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) *PodmanSession

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

func (*PodmanTest) PodmanBase

func (p *PodmanTest) PodmanBase(args []string) *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) []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

Jump to

Keyboard shortcuts

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