e2e

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: BSD-3-Clause Imports: 48 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, 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]
)
View Source
var NativeProfiles = map[string]Profile{
	// contains filtered or unexported fields
}

NativeProfiles defines all available profiles for the native singularity runtime

View Source
var OCIProfiles = map[string]Profile{
	// contains filtered or unexported fields
}

OCIProfiles defines all available profiles for the OCI runtime

Functions

func AllProfiles

func AllProfiles() map[string]Profile

AllProfiles is initialized to the union of NativeProfiles and OCIProfiles

func BusyboxSIF

func BusyboxSIF(t *testing.T) string

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

func CopyOCIImage(t *testing.T, source, dest string, insecureSource, insecureDest bool)

CopyImage will copy an OCI image from source to destination

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 of supplied DefFileDetail

func DownloadFile

func DownloadFile(url string, path string) error

func EnsureDockerArchive

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

EnsureDockerArchive checks if e2e Docker test archive is available, and fetches it otherwise.

func EnsureImage

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

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

func EnsureOCIArchive

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

EnsureImage checks if e2e OCI test archive is available, and fetches it otherwise.

func EnsureOCILayout added in v4.1.0

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

func EnsureOCISIF

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

EnsureImage checks if e2e OCI-SIF file is available, and fetches it otherwise.

func EnsureORASImage

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

func EnsureORASOCISIF

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

func EnsureRegistryOCISIF

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

func GeneratePemFiles

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

GeneratePemFiles creates a new PEM file for testing purposes.

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 MakeSyPGPDir

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

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

func PrivateRepoLogin(t *testing.T, env TestEnv, profile Profile, reqAuthFile string)

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

func PrivateRepoLogout(t *testing.T, env TestEnv, profile Profile, reqAuthFile string)

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

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 applied to the current thread, and the current goroutine locked to this thread.

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 StartRegistry

func StartRegistry(t *testing.T, env TestEnv) string

func ThreadSetresgid

func ThreadSetresgid(rgid, egid, sgid int) (err error)

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

func ThreadSetresuid(ruid, euid, suid int) (err error)

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

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
	Start   []string
	Test    []string
}

AppDetail describes an app

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

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

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

func (p Profile) OCI() bool

OCI returns whether the profile is using an OCI runtime, rather than the singularity native runtime.

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

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

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

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

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

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

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

func (env TestEnv) WithRootManagers(f func(t *testing.T)) func(t *testing.T)

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.

func (TestEnv) WithRootlessManagers

func (env TestEnv) WithRootlessManagers(f func(t *testing.T)) func(t *testing.T)

WithRootlessManagers is a wrapper to call test function f if we can satisfy the requirement of rootless cgroups (systemd and cgroupsv2)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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