e2e

package
v1.0.0-rc.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: BSD-3-Clause Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultUsername is the default E2E username.
	DefaultUsername = "e2e"
	// DefaultPassword is the default E2E password.
	DefaultPassword = "e2e"
)
View Source
const (
	// Passphrase used for passphrase-based encryption tests
	Passphrase = "e2e-passphrase"
)

Variables

View Source
var (
	// UserProfile is the execution profile for a regular user.
	UserProfile = Profiles[userProfile]
	// RootProfile is the execution profile for root.
	RootProfile = Profiles[rootProfile]
	// FakerootProfile is the execution profile for fakeroot.
	FakerootProfile = Profiles[fakerootProfile]
	// UserNamespaceProfile is the execution profile for a regular user and a user namespace.
	UserNamespaceProfile = Profiles[userNamespaceProfile]
	// RootUserNamespaceProfile is the execution profile for root and a user namespace.
	RootUserNamespaceProfile = Profiles[rootUserNamespaceProfile]
)
View Source
var Profiles = map[string]Profile{
	// contains filtered or unexported fields
}

Profiles defines all available profiles.

Functions

func CheckCryptsetupVersion

func CheckCryptsetupVersion() error

CheckCryptsetupVersion checks the version of cryptsetup and returns an error if the version is not compatible; nil otherwise

func CurrentUser

func CurrentUser(t *testing.T) *user.User

CurrentUser returns the current user account information. Use of user.Current is not safe with e2e tests as the user information is cached after the first call, so it will always return the same user information which could be wrong if user.Current was first called in unprivileged context and called after in a privileged context as it will return information of unprivileged user.

func DefinitionImageVerify

func DefinitionImageVerify(t *testing.T, cmdPath, imagePath string, dfd DefFileDetails)

DefinitionImageVerify checks for image correctness based off off supplied DefFileDetail

func EnsureImage

func EnsureImage(t *testing.T, env TestEnv)

EnsureImage checks if e2e test image is already built or built it otherwise.

func EnsureRegistry

func EnsureRegistry(t *testing.T)

EnsureRegistry fails the current test if the e2e docker registry is not up

func EnsureSingularityImage added in v1.0.0

func EnsureSingularityImage(t *testing.T, env TestEnv)

EnsureSingularityImage checks if e2e test singularity image is already built or built it otherwise.

func GeneratePemFiles

func GeneratePemFiles(t *testing.T, basedir string) (string, string)

GeneratePemFiles creates a new PEM file for testing purposes.

func KillRegistry

func KillRegistry(t *testing.T, env TestEnv)

KillRegistry stop and cleanup docker registry.

func MakeCacheDir

func MakeCacheDir(t *testing.T, baseDir string) (string, func(t *testing.T))

MakeCacheDir creates a temporary image cache directory that can then be used for the execution of a e2e test.

This function shall not set the environment variable to specify the image cache location since it would create thread safety problems.

func MakeKeysDir added in v1.0.0

func MakeKeysDir(t *testing.T, baseDir string) (string, func(t *testing.T))

MakeKeysDir creates a temporary directory that will be used to store the PGP keyring for the execution of a e2e test.

This function shall not set the environment variable to specify the keys directory since it would create thread safety problems.

func MakeTempDir

func MakeTempDir(t *testing.T, baseDir string, prefix string, context string) (string, func(t *testing.T))

MakeTempDir creates a temporary image cache directory that can then be used for the execution of a e2e test.

This function shall not set the environment variable to specify the image cache location since it would create thread safety problems.

func OrigGID

func OrigGID() int

OrigGID returns the GID of the user running the test suite.

func OrigUID

func OrigUID() int

OrigUID returns the UID of the user running the test suite.

func PathExists

func PathExists(t *testing.T, path string) bool

PathExists return true if the path (file or directory) exists, false otherwise.

func PathPerms

func PathPerms(t *testing.T, path string, perms os.FileMode) bool

PathPerms return true if the path (file or directory) has specified permissions, false otherwise.

func PrepRegistry

func PrepRegistry(t *testing.T, env TestEnv)

PrepRegistry runs a docker registry and pushes in a busybox image and the test image using the oras transport. This *MUST* be called before any tests using OCI/instances as it temporarily mounts a shadow instance directory in the test user $HOME that will obscure any instances of concurrent tests, causing them to fail.

func PrepareDefFile

func PrepareDefFile(dfd DefFileDetails) (outputPath string)

PrepareDefFile reads a template from a file, applies data to it, writes the contents to disk, and returns the path.

func PrepareMultiStageDefFile

func PrepareMultiStageDefFile(dfd []DefFileDetails) (outputPath string)

PrepareMultiStageDefFile reads a template from a file, applies data to it for each definition, concatenates them all together, writes them to a file and returns the path.

func Privileged

func Privileged(f func(*testing.T)) func(*testing.T)

Privileged wraps the supplied test function with calls to ensure the test is run with elevated privileges.

func PullImage

func PullImage(t *testing.T, env TestEnv, imageURL string, arch string, path string)

PullImage will pull a test image.

func RawDefFile

func RawDefFile(t *testing.T, dir string, r io.Reader) (outputPath string)

func SetupDefaultConfig

func SetupDefaultConfig(t *testing.T, path string)

func SetupDockerHubCredentials

func SetupDockerHubCredentials(t *testing.T)

func SetupHomeDirectories

func SetupHomeDirectories(t *testing.T)

SetupHomeDirectories creates temporary home directories for privileged and unprivileged users and bind mount those directories on top of real ones. It's possible because e2e tests are executed in a dedicated mount namespace.

func SetupPluginDir

func SetupPluginDir(t *testing.T, testDir string)

func SetupSystemECLAndGlobalKeyRing

func SetupSystemECLAndGlobalKeyRing(t *testing.T, testDir string)

func SetupSystemRemoteFile

func SetupSystemRemoteFile(t *testing.T, testDir string)

func WriteTempFile

func WriteTempFile(dir, pattern, content string) (string, error)

WriteTempFile creates and populates a temporary file in the specified directory or in os.TempDir if dir is "" returns the file name or an error

Types

type AppDetail

type AppDetail struct {
	Name    string
	Help    []string
	Env     []string
	Labels  map[string]string
	Files   []FilePair
	Install []string
	Run     []string
	Test    []string
}

AppDetail describes an app

type ApptainerCmdOp

type ApptainerCmdOp func(*apptainerCmd)

ApptainerCmdOp is a function type passed to RunCommand used to define the test execution context.

func AsSubtest

func AsSubtest(name string) ApptainerCmdOp

AsSubtest requests the command to be run as a subtest

func ConsoleRun

func ConsoleRun(consoleOps ...ApptainerConsoleOp) ApptainerCmdOp

ConsoleRun sets console operations to interact with the running command.

func ExpectExit

func ExpectExit(code int, resultOps ...ApptainerCmdResultOp) ApptainerCmdOp

ExpectExit is called once the command completed and before PostRun function in order to check the exit code returned. This function is always required by RunCommand and can call additional test functions processing the command result like ExpectOutput, ExpectError.

func PostRun

func PostRun(fn func(*testing.T)) ApptainerCmdOp

PostRun sets a function to execute when the apptainer command execution finished, this function is executed with privileges if the profile is either RootProfile or RootUserNamespaceProfile. PostRun is executed in all cases even when the command execution failed, it's the responsibility of the caller to check if the test failed with t.Failed().

func PreRun

func PreRun(fn func(*testing.T)) ApptainerCmdOp

PreRun sets a function to execute before running the apptainer command, this function is executed with privileges if the profile is either RootProfile or RootUserNamespaceProfile.

func WithArgs

func WithArgs(args ...string) ApptainerCmdOp

WithArgs sets the apptainer command arguments.

func WithCommand

func WithCommand(command string) ApptainerCmdOp

WithCommand sets the apptainer command to execute.

func WithDir

func WithDir(dir string) ApptainerCmdOp

WithDir sets the current working directory for the execution of a command.

func WithEnv

func WithEnv(envs []string) ApptainerCmdOp

WithEnv sets environment variables to use while running a apptainer command.

func WithGlobalOptions

func WithGlobalOptions(options ...string) ApptainerCmdOp

WithGlobalOptions sets global apptainer option (eg: --debug, --silent).

func WithProfile

func WithProfile(profile Profile) ApptainerCmdOp

WithProfile sets the Apptainer execution profile, this is a convenient way to automatically set requirements like privileges, arguments injection in order to execute Apptainer command with the corresponding profile. RootProfile, RootUserNamespaceProfile will set privileges which means that PreRun and PostRun are executed with privileges.

func WithStdin

func WithStdin(r io.Reader) ApptainerCmdOp

WithStdin sets a reader to use as input data to pass to the apptainer command.

type ApptainerCmdResult

type ApptainerCmdResult struct {
	Stdout  []byte
	Stderr  []byte
	FullCmd string
}

ApptainerCmdResult holds the result for an Apptainer command execution test.

type ApptainerCmdResultOp

type ApptainerCmdResultOp func(*testing.T, *ApptainerCmdResult)

ApptainerCmdResultOp is a function type executed by ExpectExit to process and test execution result.

func ExpectError

func ExpectError(mt MatchType, pattern string) ApptainerCmdResultOp

ExpectError tests if the command error stream match the pattern string based on the type of match.

func ExpectErrorf

func ExpectErrorf(mt MatchType, formatPattern string, a ...interface{}) ApptainerCmdResultOp

ExpectErrorf tests if the command error stream match the pattern string based on the type of match.

func ExpectOutput

func ExpectOutput(mt MatchType, pattern string) ApptainerCmdResultOp

ExpectOutput tests if the command output stream match the pattern string based on the type of match.

func ExpectOutputf

func ExpectOutputf(mt MatchType, formatPattern string, a ...interface{}) ApptainerCmdResultOp

ExpectOutputf tests if the command output stream match the formatted string pattern based on the type of match.

func GetStreams

func GetStreams(stdout *string, stderr *string) ApptainerCmdResultOp

GetStreams gets command stdout and stderr result.

type ApptainerConsoleOp

type ApptainerConsoleOp func(*testing.T, *expect.Console)

ApptainerConsoleOp is a function type passed to ConsoleRun to execute interactive commands.

func ConsoleExpect

func ConsoleExpect(s string) ApptainerConsoleOp

ConsoleExpect reads from the console until the provided string is read or an error occurs.

func ConsoleExpectf

func ConsoleExpectf(format string, args ...interface{}) ApptainerConsoleOp

ConsoleExpectf reads from the console until the provided formatted string is read or an error occurs.

func ConsoleSend

func ConsoleSend(s string) ApptainerConsoleOp

ConsoleSend writes a string to the console.

func ConsoleSendLine

func ConsoleSendLine(s string) ApptainerConsoleOp

ConsoleSendLine writes a string to the console with a trailing newline.

type BuildOpts

type BuildOpts struct {
	Force   bool
	Sandbox bool
	Env     []string
}

BuildOpts define image build options

type DefFileDetails

type DefFileDetails struct {
	Bootstrap   string
	From        string
	Registry    string
	Namespace   string
	Stage       string
	Help        []string
	Env         []string
	Labels      map[string]string
	Files       []FilePair
	FilesFrom   []FileSection
	Pre         []string
	Setup       []string
	Post        []string
	RunScript   []string
	Test        []string
	StartScript []string
	Apps        []AppDetail
}

DefFileDetails describes the sections of a definition file

type FilePair

type FilePair struct {
	Src string
	Dst string
}

FilePair represents a source destination pair for file copying

type FileSection

type FileSection struct {
	Stage string
	Files []FilePair
}

FileSection describes elements of %files section

type MatchType

type MatchType uint8

MatchType defines the type of match for ExpectOutput and ExpectError functions

const (
	// ContainMatch is for contain match
	ContainMatch MatchType = iota
	// ExactMatch is for exact match
	ExactMatch
	// UnwantedContainMatch checks that output does not contain text
	UnwantedContainMatch
	// UnwantedExactMatch checks that output does not exactly match text
	UnwantedExactMatch
	// RegexMatch is for regular expression match
	RegexMatch
)

func (MatchType) String

func (m MatchType) String() string

type Profile

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

Profile represents various properties required to run an E2E test under a particular user profile. A profile can define if `RunApptainer` will run with privileges (`privileged`), if an option flag is injected (`apptainerOption`), the option injection is also controllable for a subset of apptainer commands with `optionForCommands`. A profile can also set a default current working directory via `defaultCwd`, profile like "RootUserNamespace" need to run from a directory owned by root. A profile can also have two identities (eg: "Fakeroot" profile), a host identity corresponding to user ID `hostUID` and a container identity corresponding to user ID `containerUID`.

func (Profile) ContainerUser

func (p Profile) ContainerUser(t *testing.T) *user.User

ContainerUser returns the container user information.

func (Profile) HostUser

func (p Profile) HostUser(t *testing.T) *user.User

HostUser returns the host user information.

func (Profile) In

func (p Profile) In(profiles ...Profile) bool

In returns true if the specified list of profiles contains this profile.

func (Profile) Privileged

func (p Profile) Privileged() bool

Privileged returns whether the test should be executed with elevated privileges or not.

func (Profile) Requirements

func (p Profile) Requirements(t *testing.T)

Requirements calls the different require.* functions necessary for running an E2E test under this profile.

func (Profile) String

func (p Profile) String() string

String provides a string representation of this profile.

type TestEnv

type TestEnv struct {
	CmdPath              string // Path to the Apptainer binary to use for the execution of an Apptainer command
	ImagePath            string // Path to the image that has to be used for the execution of an Apptainer command
	SingularityImagePath string // Path to a Singularity image for legacy tests
	OrasTestImage        string
	TestDir              string // Path to the directory from which an Apptainer command needs to be executed
	TestRegistry         string
	KeyringDir           string // KeyringDir sets the directory where the keyring will be created for the execution of a command (instead of using APPTAINER_KEYSDIR which should be avoided when running e2e tests)
	ImgCacheDir          string // ImgCacheDir sets the location of the image cache to be used by the Apptainer command to be executed (instead of using APPTAINER_CACHE_DIR which should be avoided when running e2e tests)
	RunDisabled          bool
	DisableCache         bool // DisableCache can be set to disable the cache during the execution of a e2e command
}

TestEnv stores all the information under the control of e2e test developers, from specifying which Apptainer binary to use to controlling how Apptainer environment variables will be set.

func (TestEnv) ImageVerify

func (env TestEnv) ImageVerify(t *testing.T, imagePath string, profile Profile)

ImageVerify checks for an image integrity.

func (TestEnv) RunApptainer

func (env TestEnv) RunApptainer(t *testing.T, cmdOps ...ApptainerCmdOp)

RunApptainer executes an Apptainer command within a test execution context.

cmdPath specifies the path to the apptainer binary and cmdOps provides a list of operations to be executed before or after running the command.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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