Documentation ¶
Index ¶
- Constants
- Variables
- func CheckCryptsetupVersion() error
- func CurrentUser(t *testing.T) *user.User
- func DefinitionImageVerify(t *testing.T, cmdPath, imagePath string, dfd DefFileDetails)
- func EnsureImage(t *testing.T, env TestEnv)
- func EnsureRegistry(t *testing.T)
- func EnsureSingularityImage(t *testing.T, env TestEnv)
- func GeneratePemFiles(t *testing.T, basedir string) (string, string)
- func KillRegistry(t *testing.T, env TestEnv)
- func MakeCacheDir(t *testing.T, baseDir string) (string, func(t *testing.T))
- func MakeKeysDir(t *testing.T, baseDir string) (string, func(t *testing.T))
- func MakeTempDir(t *testing.T, baseDir string, prefix string, context string) (string, func(t *testing.T))
- func OrigGID() int
- func OrigUID() int
- func PathExists(t *testing.T, path string) bool
- func PathPerms(t *testing.T, path string, perms os.FileMode) bool
- func PrepRegistry(t *testing.T, env TestEnv)
- func PrepareDefFile(dfd DefFileDetails) (outputPath string)
- func PrepareMultiStageDefFile(dfd []DefFileDetails) (outputPath string)
- func Privileged(f func(*testing.T)) func(*testing.T)
- func PullImage(t *testing.T, env TestEnv, imageURL string, arch string, path string)
- func RawDefFile(t *testing.T, dir string, r io.Reader) (outputPath string)
- func SetupDefaultConfig(t *testing.T, path string)
- func SetupDockerHubCredentials(t *testing.T)
- func SetupHomeDirectories(t *testing.T)
- func SetupPluginDir(t *testing.T, testDir string)
- func SetupSystemECLAndGlobalKeyRing(t *testing.T, testDir string)
- func SetupSystemRemoteFile(t *testing.T, testDir string)
- func WriteTempFile(dir, pattern, content string) (string, error)
- type AppDetail
- type ApptainerCmdOp
- func AsSubtest(name string) ApptainerCmdOp
- func ConsoleRun(consoleOps ...ApptainerConsoleOp) ApptainerCmdOp
- func ExpectExit(code int, resultOps ...ApptainerCmdResultOp) ApptainerCmdOp
- func PostRun(fn func(*testing.T)) ApptainerCmdOp
- func PreRun(fn func(*testing.T)) ApptainerCmdOp
- func WithArgs(args ...string) ApptainerCmdOp
- func WithCommand(command string) ApptainerCmdOp
- func WithDir(dir string) ApptainerCmdOp
- func WithEnv(envs []string) ApptainerCmdOp
- func WithGlobalOptions(options ...string) ApptainerCmdOp
- func WithProfile(profile Profile) ApptainerCmdOp
- func WithStdin(r io.Reader) ApptainerCmdOp
- type ApptainerCmdResult
- type ApptainerCmdResultOp
- func ExpectError(mt MatchType, pattern string) ApptainerCmdResultOp
- func ExpectErrorf(mt MatchType, formatPattern string, a ...interface{}) ApptainerCmdResultOp
- func ExpectOutput(mt MatchType, pattern string) ApptainerCmdResultOp
- func ExpectOutputf(mt MatchType, formatPattern string, a ...interface{}) ApptainerCmdResultOp
- func GetStreams(stdout *string, stderr *string) ApptainerCmdResultOp
- type ApptainerConsoleOp
- type BuildOpts
- type DefFileDetails
- type FilePair
- type FileSection
- type MatchType
- type Profile
- type TestEnv
Constants ¶
const ( // DefaultUsername is the default E2E username. DefaultUsername = "e2e" // DefaultPassword is the default E2E password. DefaultPassword = "e2e" )
const (
// Passphrase used for passphrase-based encryption tests
Passphrase = "e2e-passphrase"
)
Variables ¶
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] )
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 ¶
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 ¶
EnsureImage checks if e2e test image is already built or built it otherwise.
func EnsureRegistry ¶
EnsureRegistry fails the current test if the e2e docker registry is not up
func EnsureSingularityImage ¶ added in v1.0.0
EnsureSingularityImage checks if e2e test singularity image is already built or built it otherwise.
func GeneratePemFiles ¶
GeneratePemFiles creates a new PEM file for testing purposes.
func KillRegistry ¶
KillRegistry stop and cleanup docker registry.
func MakeCacheDir ¶
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
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 PathExists ¶
PathExists return true if the path (file or directory) exists, false otherwise.
func PathPerms ¶
PathPerms return true if the path (file or directory) has specified permissions, false otherwise.
func PrepRegistry ¶
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 ¶
Privileged wraps the supplied test function with calls to ensure the test is run with elevated privileges.
func SetupDefaultConfig ¶
func SetupHomeDirectories ¶
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 SetupSystemRemoteFile ¶
func WriteTempFile ¶
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 ¶
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 ¶
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 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 FileSection ¶
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 )
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 ¶
ContainerUser returns the container user information.
func (Profile) Privileged ¶
Privileged returns whether the test should be executed with elevated privileges or not.
func (Profile) Requirements ¶
Requirements calls the different require.* functions necessary for running an E2E test under 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 ¶
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.