Documentation ¶
Index ¶
- Constants
- Variables
- func AllProfiles() map[string]Profile
- func BusyboxSIF(t *testing.T) string
- func CheckCryptsetupVersion() error
- func CopyOCIImage(t *testing.T, source, dest string, insecureSource, insecureDest bool)
- func CurrentUser(t *testing.T) *user.User
- func DefinitionImageVerify(t *testing.T, cmdPath, imagePath string, dfd DefFileDetails)
- func DownloadFile(url string, path string) error
- func EnsureDockerArchive(t *testing.T, env TestEnv)
- func EnsureImage(t *testing.T, env TestEnv)
- func EnsureOCIArchive(t *testing.T, env TestEnv)
- func EnsureOCILayout(t *testing.T, env TestEnv)
- func EnsureOCISIF(t *testing.T, env TestEnv)
- func EnsureORASImage(t *testing.T, env TestEnv)
- func EnsureORASOCISIF(t *testing.T, env TestEnv)
- func EnsureRegistryOCISIF(t *testing.T, env TestEnv)
- func GeneratePemFiles(t *testing.T, basedir string) (string, string)
- func MakeCacheDir(t *testing.T, baseDir string) (string, func(t *testing.T))
- func MakeSyPGPDir(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 PrepareDefFile(dfd DefFileDetails) (outputPath string)
- func PrepareMultiStageDefFile(dfd []DefFileDetails) (outputPath string)
- func PrivateRepoLogin(t *testing.T, env TestEnv, profile Profile, reqAuthFile string)
- func PrivateRepoLogout(t *testing.T, env TestEnv, profile Profile, reqAuthFile 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 StartRegistry(t *testing.T, env TestEnv) string
- func ThreadSetresgid(rgid, egid, sgid int) (err error)
- func ThreadSetresuid(ruid, euid, suid int) (err error)
- func WriteTempFile(dir, pattern, content string) (string, error)
- type AppDetail
- type BuildOpts
- type DefFileDetails
- type FilePair
- type FileSection
- type MatchType
- type Profile
- type SingularityCmdOp
- func AsSubtest(name string) SingularityCmdOp
- func ConsoleRun(consoleOps ...SingularityConsoleOp) SingularityCmdOp
- func ExpectExit(code int, resultOps ...SingularityCmdResultOp) SingularityCmdOp
- func PostRun(fn func(*testing.T)) SingularityCmdOp
- func PreRun(fn func(*testing.T)) SingularityCmdOp
- func WithArgs(args ...string) SingularityCmdOp
- func WithCommand(command string) SingularityCmdOp
- func WithDir(dir string) SingularityCmdOp
- func WithEnv(envs []string) SingularityCmdOp
- func WithGlobalOptions(options ...string) SingularityCmdOp
- func WithProfile(profile Profile) SingularityCmdOp
- func WithRootlessEnv() SingularityCmdOp
- func WithStdin(r io.Reader) SingularityCmdOp
- type SingularityCmdResult
- type SingularityCmdResultOp
- func ExpectError(mt MatchType, pattern string) SingularityCmdResultOp
- func ExpectErrorf(mt MatchType, formatPattern string, a ...interface{}) SingularityCmdResultOp
- func ExpectOutput(mt MatchType, pattern string) SingularityCmdResultOp
- func ExpectOutputf(mt MatchType, formatPattern string, a ...interface{}) SingularityCmdResultOp
- func GetStreams(stdout *string, stderr *string) SingularityCmdResultOp
- type SingularityConsoleOp
- 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, using the Singularity native runtime. UserProfile = NativeProfiles[userProfile] // RootProfile is the execution profile for root, using the Singularity native runtime. RootProfile = NativeProfiles[rootProfile] // FakerootProfile is the execution profile for fakeroot, using the Singularity native runtime. FakerootProfile = NativeProfiles[fakerootProfile] // UserNamespaceProfile is the execution profile for a regular user and a user namespace, using the Singularity native runtime. UserNamespaceProfile = NativeProfiles[userNamespaceProfile] // RootUserNamespaceProfile is the execution profile for root and a user namespace, using the Singularity native runtime. RootUserNamespaceProfile = NativeProfiles[rootUserNamespaceProfile] // OCIUserProfile is the execution profile for a regular user, using Singularity's OCI mode. OCIUserProfile = OCIProfiles[ociUserProfile] // OCIRootProfile is the execution profile for root, using Singularity's OCI mode. OCIRootProfile = OCIProfiles[ociRootProfile] // OCIFakerootProfile is the execution profile for fakeroot, using Singularity's OCI mode. OCIFakerootProfile = OCIProfiles[ociFakerootProfile] )
var NativeProfiles = map[string]Profile{ // contains filtered or unexported fields }
NativeProfiles defines all available profiles for the native singularity runtime
var OCIProfiles = map[string]Profile{ // contains filtered or unexported fields }
OCIProfiles defines all available profiles for the OCI runtime
Functions ¶
func AllProfiles ¶
AllProfiles is initialized to the union of NativeProfiles and OCIProfiles
func BusyboxSIF ¶
BusyboxImage will provide the path to a local busybox SIF image for the current architecture
func CheckCryptsetupVersion ¶
func CheckCryptsetupVersion() error
CheckCryptsetupVersion checks the version of cryptsetup and returns an error if the version is not compatible; nil otherwise
func CopyOCIImage ¶
CopyImage will copy an OCI image from source to destination
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 of supplied DefFileDetail
func DownloadFile ¶
func EnsureDockerArchive ¶
EnsureDockerArchive checks if e2e Docker test archive is available, and fetches it otherwise.
func EnsureImage ¶
EnsureImage checks if e2e test image is already built or built it otherwise.
func EnsureOCIArchive ¶
EnsureImage checks if e2e OCI test archive is available, and fetches it otherwise.
func EnsureOCILayout ¶ added in v4.1.0
func EnsureOCISIF ¶
EnsureImage checks if e2e OCI-SIF file is available, and fetches it otherwise.
func EnsureORASImage ¶
func EnsureORASOCISIF ¶
func EnsureRegistryOCISIF ¶
func GeneratePemFiles ¶
GeneratePemFiles creates a new PEM file for testing purposes.
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 MakeSyPGPDir ¶
MakeSyPGPDir 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 SYPGP 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 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 PrivateRepoLogin ¶ added in v4.1.0
PrivateRepoLogin logs in to the private repo at env.TestRegistryPrivURI. In all cases, the global default e2e repo username & password are used. If reqAuthFile is empty, the credentials will be stored in the default location ($HOME/.singularity/docker-config.json); if it is non-empty, the credentials will be stored as an authfile at the specified path.
func PrivateRepoLogout ¶ added in v4.1.0
PrivateRepoLogout logs out of the private repo at env.TestRegistryPrivURI. If reqAuthFile is empty, login credentials will be removed from the default location ($HOME/.singularity/docker-config.json); if it is non-empty, login credentials will be removed from the authfile at the specified path.
func Privileged ¶
Privileged wraps the supplied test function with calls to ensure the test is run with elevated privileges applied to the current thread, and the current goroutine locked to this thread.
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 ThreadSetresgid ¶
ThreadSetresgid performs a syscall setting gid for the current thread only. This is required as in Go 1.16 syscall.Setresuid is all-threads, and the newest x/sys/unix functions use this, so are all threads.
func ThreadSetresuid ¶
ThreadSetresuid performs a syscall setting uid for the current thread only. This is required as in Go 1.16 syscall.Setresuid is all-threads, and the newest x/sys/unix functions use this, so are all threads.
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 Start []string Test []string }
AppDetail describes an app
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 ExpectOuput 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 `RunSingularity` will run with privileges (`privileged`), if an option flag is injected (`singularityOption`), the option injection is also controllable for a subset of singularity 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) OCI ¶
OCI returns whether the profile is using an OCI runtime, rather than the singularity native runtime.
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 SingularityCmdOp ¶
type SingularityCmdOp func(*singularityCmd)
SingularityCmdOp is a function type passed to RunCommand used to define the test execution context.
func AsSubtest ¶
func AsSubtest(name string) SingularityCmdOp
AsSubtest requests the command to be run as a subtest
func ConsoleRun ¶
func ConsoleRun(consoleOps ...SingularityConsoleOp) SingularityCmdOp
ConsoleRun sets console operations to interact with the running command.
func ExpectExit ¶
func ExpectExit(code int, resultOps ...SingularityCmdResultOp) SingularityCmdOp
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)) SingularityCmdOp
PostRun sets a function to execute when the singularity 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)) SingularityCmdOp
PreRun sets a function to execute before running the singularity command, this function is executed with privileges if the profile is either RootProfile or RootUserNamespaceProfile.
func WithArgs ¶
func WithArgs(args ...string) SingularityCmdOp
WithArgs sets the singularity command arguments.
func WithCommand ¶
func WithCommand(command string) SingularityCmdOp
WithCommand sets the singularity command to execute.
func WithDir ¶
func WithDir(dir string) SingularityCmdOp
WithDir sets the current working directory for the execution of a command.
func WithEnv ¶
func WithEnv(envs []string) SingularityCmdOp
WithEnv sets environment variables to use while running a singularity command.
func WithGlobalOptions ¶
func WithGlobalOptions(options ...string) SingularityCmdOp
WithGlobalOptions sets global singularity option (eg: --debug, --silent).
func WithProfile ¶
func WithProfile(profile Profile) SingularityCmdOp
WithProfile sets the Singularity execution profile, this is a convenient way to automatically set requirements like privileges, arguments injection in order to execute Singularity command with the corresponding profile. RootProfile, RootUserNamespaceProfile will set privileges which means that PreRun and PostRun are executed with privileges.
func WithRootlessEnv ¶
func WithRootlessEnv() SingularityCmdOp
WithRootlessEnv passes through XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS for rootless operations that need these e.g. systemd cgroups interaction.
func WithStdin ¶
func WithStdin(r io.Reader) SingularityCmdOp
WithStdin sets a reader to use as input data to pass to the singularity command.
type SingularityCmdResult ¶
SingularityCmdResult holds the result for a Singularity command execution test.
type SingularityCmdResultOp ¶
type SingularityCmdResultOp func(*testing.T, *SingularityCmdResult)
SingularityCmdResultOp is a function type executed by ExpectExit to process and test execution result.
func ExpectError ¶
func ExpectError(mt MatchType, pattern string) SingularityCmdResultOp
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{}) SingularityCmdResultOp
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) SingularityCmdResultOp
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{}) SingularityCmdResultOp
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) SingularityCmdResultOp
GetStreams gets command stdout and stderr result.
type SingularityConsoleOp ¶
SingularityConsoleOp is a function type passed to ConsoleRun to execute interactive commands.
func ConsoleExpect ¶
func ConsoleExpect(s string) SingularityConsoleOp
ConsoleExpect reads from the console until the provided string is read or an error occurs.
func ConsoleExpectf ¶
func ConsoleExpectf(format string, args ...interface{}) SingularityConsoleOp
ConsoleExpectf reads from the console until the provided formatted string is read or an error occurs.
func ConsoleSend ¶
func ConsoleSend(s string) SingularityConsoleOp
ConsoleSend writes a string to the console.
func ConsoleSendLine ¶
func ConsoleSendLine(s string) SingularityConsoleOp
ConsoleSendLine writes a string to the console with a trailing newline.
type TestEnv ¶
type TestEnv struct { CmdPath string // Path to the Singularity binary to use for the execution of a Singularity command ImagePath string // Path to the image that has to be used for the execution of a Singularity command OrasTestImage string // URI to SIF image pushed into local registry with ORAS OrasTestOCISIF string // URI to OCI-SIF image pushed into local registry with ORAS OrasTestPrivImage string // URI to SIF image pushed into local registry with ORAS OCIArchivePath string // Path to test OCI archive tar file OCILayoutPath string // Path to test OCI layout directory OCISIFPath string // Path to test OCI-SIF file DockerArchivePath string // Path to test Docker archive tar file TestDir string // Path to the directory from which a Singularity command needs to be executed TestRegistry string // Host:Port of local registry TestRegistryPrivPath string // Host:Port of local registry + path to private location TestRegistryPrivURI string // Transport (docker://) + Host:Port of local registry + path to private location TestRegistryImage string // URI to single layer OCI image pushed into local registry TestRegistryLayeredImage string // URI to 7-layer OCI image pushed into local registry TestRegistryPrivImage string // URI to OCI image pushed into private location in local registry TestRegistryOCISIF string // URI to OCI SIF pushed into local registry as OCI image (non-oras) KeyringDir string // KeyringDir sets the directory where the keyring will be created for the execution of a command (instead of using SINGULARITY_SYPGPDIR which should be avoided when running e2e tests) PrivCacheDir string // PrivCacheDir sets the location of the image cache to be used by the Singularity command to be executed as root (instead of using SINGULARITY_CACHE_DIR which should be avoided when running e2e tests) UnprivCacheDir string // UnprivCacheDir sets the location of the image cache to be used by the Singularity command to be executed as the unpriv user (instead of using SINGULARITY_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 Singularity binary to use to controlling how Singularity environment variables will be set.
func (TestEnv) ImageVerify ¶
ImageVerify checks for an image integrity.
func (TestEnv) RunSingularity ¶
func (env TestEnv) RunSingularity(t *testing.T, cmdOps ...SingularityCmdOp)
RunSingularity executes a singularity command within a test execution context.
cmdPath specifies the path to the singularity binary and cmdOps provides a list of operations to be executed before or after running the command.
func (TestEnv) WithRootManagers ¶
WithCgroupManagers is a wrapper to call test function f in both the systemd and cgroupfs cgroup manager configurations. It *must* be run noparallel, as the cgroup manager setting is set / read from global configuration.