Namespace src/Assert

src/Assert

Overview

Directory src/Assert

file source src/Assert/bashFile.sh

Assert::bashFile

ensure that file begin with a bash shebang

Arguments
  • $1 file:String
Exit codes
  • 1: if file doesn’t have a bash shebang
  • 2: if file doesn’t exist

src/Assert/bashFrameworkFunction.sh

file source src/Assert/bashFrameworkFunction.sh

Assert::bashFrameworkFunction

assert that first arg respects this bash framework naming convention

Arguments
  • $1 (bashFrameworkFunction:String): the function’s name to assert
Exit codes
  • 1: if bashFrameworkFunction arg doesn’t respect this bash framework naming convention

src/Assert/commandExists.sh

file source src/Assert/commandExists.sh

Assert::commandExists

check if command specified exists or return 1 with error and message if not

Arguments
  • $1 (commandName:String): on which existence must be checked
  • $2 (helpIfNotExists:String): a help command to display if the command does not exist
Exit codes
  • 1: if the command specified does not exist
Output on stderr
  • diagnostic information + help if second argument is provided

src/Assert/curlPingWithRetry.sh

file source src/Assert/curlPingWithRetry.sh

Assert::curlPingWithRetry

Featuring Retry::parameterized

check if ulr provided can be reached (trying if failure)

Arguments
  • $1 (url:String): the url to contact using curl
  • $2 (title:String): the title to pass to Retry::parameterized method (default: “Try to contact ${title} …”)
  • $3 (maxRetries:int): max retries (default: 40)
  • $4 (delayBetweenTries:int): delay between attempt in seconds (default value: 5 seconds)
Output on stderr
  • progression status using title argument
Requires
  • Linux::requireCurlCommand
Features
  • Retry::parameterized

src/Assert/dirEmpty.sh

file source src/Assert/dirEmpty.sh

Assert::dirEmpty

asserts that directory does not exist check if directory empty using ls -A if pattern provided, apply grep -v with this pattern on ls -A result

Arguments
  • $1 directory:String
  • $2 (pattern:String): list of files considered to be present in the directory
Environment variables
  • SUDO (String): allows to use custom sudo prefix command
  • SUDO (String): allows to use custom sudo prefix command
Exit codes
  • 1: directory does not exists
  • 2: directory arg is actually a file
  • 3: directory not empty
Output on stderr
  • diagnostics information is displayed

src/Assert/dirExists.sh

file source src/Assert/dirExists.sh

Assert::dirExists

asserts that first argument is directory that exists with specified ownership

Arguments
  • $1 dir:String
  • $2 (user:String): expected owner user name of the directory (default: USERNAME or id -un command)
  • $3 (group:String): expected owner group name of the directory (default: USERGROUP or id -gn command)
Environment variables
  • USERNAME (String): if arg $2 is not provided
  • USERGROUP (String): if arg $3 is not provided
Exit codes
  • 1: if missing directory
  • 2: if incorrect user ownership
  • 3: if incorrect group ownership
Output on stderr
  • diagnostics information is displayed

src/Assert/dirNotExists.sh

file source src/Assert/dirNotExists.sh

Assert::dirNotExists

asserts that directory does not exist

Arguments
  • $1 dir:String
Environment variables
  • SUDO (String): allows to use custom sudo prefix command
  • SUDO (String): allows to use custom sudo prefix command
Exit codes
  • 1: existing dir
Output on stderr
  • diagnostics information is displayed

src/Assert/dnsHostname.sh

file source src/Assert/dnsHostname.sh

Assert::dnsHostname

check if param is valid dns hostname

Arguments
  • $1 (dnsHostname:String): the dns hostname
Exit codes
  • 1: if invalid hostname

src/Assert/emailAddress.sh

file source src/Assert/emailAddress.sh

Assert::emailAddress

1 Warning(s)

check if param is valid email address

Arguments
  • $1 (emailAddress:String): the full email address
Exit codes
  • 1: if invalid email address
Warnings
  • it is a very simple check, no RFC validation

src/Assert/emailAddressWithDomain.sh

file source src/Assert/emailAddressWithDomain.sh

Assert::emailAddressWithDomain

1 Warning(s)

check if param is valid email address with one the specified domains

Arguments
  • $1 (email:String): the full email address
  • (expectedDomains:String[]): the expected email address domains (no check if empty)
Exit codes
  • 1: if email invalid
  • 2: if email domain doesn’t match the expected domains passed in arguments
Warnings
  • it is a very simple check, no RFC validation
See also

src/Assert/etcHost.sh

file source src/Assert/etcHost.sh

Assert::etcHost

Check if Host is defined in etc/hosts of linux and windows (if applicable)

Arguments
  • $1 host:String
Exit codes
  • 1: if /etc/hosts doesn’t exist in linux
  • 2: if host doesn’t exist in linux /etc/hosts
  • 3: if host doesn’t exist in windows etc/hosts or windows etc/hosts doesn’t exists
Output on stderr
  • diagnostics information is displayed
See also

src/Assert/expectGlobalVariables.sh

file source src/Assert/expectGlobalVariables.sh

Assert::expectGlobalVariables

exits with message if expected global variable is not set

Example
Assert::expectGlobalVariables EXISTING_VAR EXISTING_VAR2
Arguments
  • (expectedGlobals:String[]): expected global variables
Exit codes
  • 1: if one of the expected global variables is not set
Output on stderr
  • diagnostics information displayed

src/Assert/expectNonRootUser.sh

file source src/Assert/expectNonRootUser.sh

Assert::expectNonRootUser

exits with message if current user is root

Function has no arguments.

Exit codes
  • 1: if current user is root
Output on stderr
  • diagnostics information is displayed

src/Assert/expectUser.sh

file source src/Assert/expectUser.sh

Assert::expectUser

exits with message if current user is not the expected one

Arguments
  • $1 (expectedUserName:String): expected user login
Exit codes
  • 1: if current user is not the expected one
Output on stderr
  • diagnostics information is displayed

src/Assert/fileExecutable.sh

file source src/Assert/fileExecutable.sh

Assert::fileExecutable

asserts that first argument is a file that exists with specified ownership and is executable

Arguments
  • $1 file:String
  • $2 (user:String): expected owner user name of the file (default: USERNAME or id -un command)
  • $3 (group:String): expected owner group name of the file (default: USERGROUP or id -gn command)
Environment variables
  • USERNAME (String): if arg $2 is not provided
  • USERGROUP (String): if arg $3 is not provided
Exit codes
  • 1: if Assert::fileExists fails
  • 2: if file is not executable
Output on stderr
  • diagnostics information is displayed
See also

src/Assert/fileExists.sh

file source src/Assert/fileExists.sh

Assert::fileExists

asserts that first argument is file that exists with specified ownership

Arguments
  • $1 file:String
  • $2 (user:String): expected owner user name of the file (default: USERNAME or id -un command)
  • $3 (group:String): expected owner group name of the file (default: USERGROUP or id -gn command)
Environment variables
  • USERNAME (String): if arg $2 is not provided
  • USERGROUP (String): if arg $3 is not provided
  • SUDO (String): allows to use custom sudo prefix command
Exit codes
  • 1: if missing file
  • 2: if incorrect user ownership
  • 3: if incorrect group ownership
Output on stderr
  • diagnostics information is displayed

src/Assert/fileNotExecutable.sh

file source src/Assert/fileNotExecutable.sh

Assert::fileNotExecutable

asserts that first argument is a file that exists with specified ownership and is NOT executable

Arguments
  • $1 file:String
  • $2 (user:String): expected owner user name of the file (default: USERNAME or id -un command)
  • $3 (group:String): expected owner group name of the file (default: USERGROUP or id -gn command)
Environment variables
  • USERNAME (String): if arg $2 is not provided
  • USERGROUP (String): if arg $3 is not provided
Exit codes
  • 1: if Assert::fileExists fails
  • 2: if file is executable
Output on stderr
  • diagnostics information is displayed
See also

src/Assert/fileNotExists.sh

file source src/Assert/fileNotExists.sh

Assert::fileNotExists

asserts that file does not exist

Arguments
  • $1 file:String
Environment variables
  • SUDO (String): allows to use custom sudo prefix command
  • SUDO (String): allows to use custom sudo prefix command
Exit codes
  • 1: existing file
Output on stderr
  • diagnostics information is displayed

src/Assert/fileWritable.sh

file source src/Assert/fileWritable.sh

Assert::fileWritable

Checks if file can be created in folder The file does not need to exist

Arguments
  • $1 file:String
Exit codes
  • 1: if file is not a valid path
  • 2: if file parent’s dir is not writable
  • 3: if existing file is not writable
See also

src/Assert/firstNameLastName.sh

file source src/Assert/firstNameLastName.sh

Assert::firstNameLastName

check if argument respects 2 or more words separated by a space it supports accentuated characters and names with hyphen(-)

Arguments
  • $1 firstNameLastName:String
Exit codes
  • 1: if regexp not matches
See also

src/Assert/functionExists.sh

file source src/Assert/functionExists.sh

Assert::functionExists

checks if function name provided exists

Arguments
  • $1 functionName:String
Exit codes
  • 1: if function name doesn’t exist

src/Assert/ldapLogin.sh

file source src/Assert/ldapLogin.sh

Assert::ldapLogin

check if argument respects ldap login naming convention only using lowercase characters a-z

Arguments
  • $1 ldapLogin:String
Exit codes
  • 1: if regexp not matches

src/Assert/posixFunctionName.sh

file source src/Assert/posixFunctionName.sh

Assert::posixFunctionName

assert that first arg respects posix function naming convention

Arguments
  • $1 (posixFunctionName:String): the function’s name to assert
Exit codes
  • 1: if posixFunctionName arg doesn’t respect posix function naming convention

src/Assert/symLinkValid.sh

file source src/Assert/symLinkValid.sh

Assert::symLinkValid

asserts that first argument is link to a file that exists

Arguments
  • $1 (link:String): expected link
Environment variables
  • SUDO (String): allows to use custom sudo prefix command
Exit codes
  • 1: if missing link
  • 2: if not a link
  • 3: if broken link (missing linked file)
Output on stderr
  • diagnostics information is displayed

src/Assert/tty.sh

file source src/Assert/tty.sh

Assert::tty

check if tty (interactive mode) is active

Function has no arguments.

Environment variables
  • NON_INTERACTIVE (if): 1 consider as not interactive even if environment is interactive
  • INTERACTIVE (if): 1 consider as interactive even if environment is not interactive
Exit codes
  • 1: if tty not active

src/Assert/validPath.sh

file source src/Assert/validPath.sh

Assert::validPath

check if argument is a valid linux path invalid path are those with:

  • invalid characters
  • component beginning by a - (because could be considered as a command’s option)
  • not beginning with a slash
  • relative
Arguments
  • $1 (path:string): path that needs to be checked
Exit codes
  • 1: if path is invalid
See also

src/Assert/validPosixPath.sh

file source src/Assert/validPosixPath.sh

Assert::validPosixPath

1 Warning(s)

check if argument is a valid posix linux path and does not contains relative directory

Arguments
  • $1 (path:string): path that needs to be checked
Exit codes
  • 1: if path is invalid
Requires
  • Linux::requirePathchkCommand
  • Linux::requireRealpathCommand
Warnings
  • posix path is really restrictive, if you need less restrictive check you can use Assert::validPath

src/Assert/validVariableName.sh

file source src/Assert/validVariableName.sh

Assert::validVariableName

check if argument respects this framework variable naming convention

  • if variable begins with an uppercase or underscore, following letters have to be uppercase or underscore
  • variable name can includes ‘:’ or ‘_’ or digits but not as first letter here valid variable name examples
Arguments
  • $1 variableName:String
Exit codes
  • 1: if regexp not matches
See also

src/Assert/varExistsAndNotEmpty.sh

file source src/Assert/varExistsAndNotEmpty.sh

Assert::varExistsAndNotEmpty

checks if variable name provided exists

Arguments
  • $1 varName:String
Exit codes
  • 1: if variable doesn’t exist
  • 2: if variable value empty
  • 3: if variable name invalid
Output on stderr
  • diagnostics information is displayed
See also

src/Assert/windows.sh

file source src/Assert/windows.sh

Assert::windows

determine if the script is executed under windows (using wsl)

Example
uname GitBash windows (with wsl) => MINGW64_NT-10.0 ZOXFL-6619QN2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys
uname GitBash windows (wo wsl)   => MINGW64_NT-10.0 frsa02-j5cbkc2 2.9.0(0.318/5/3) 2018-01-12 23:37 x86_64 Msys
uname wsl => Linux ZOXFL-6619QN2 4.4.0-17134-Microsoft #112-Microsoft Thu Jun 07 22:57:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
Exit codes
  • 1: on error

src/Assert/wsl.sh

file source src/Assert/wsl.sh

Assert::wsl

determine if the script is executed under WSL

Example
uname GitBash windows (with wsl) => MINGW64_NT-10.0 ZOXFL-6619QN2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys
uname GitBash windows (wo wsl)   => MINGW64_NT-10.0 frsa02-j5cbkc2 2.9.0(0.318/5/3) 2018-01-12 23:37 x86_64 Msys
uname wsl => Linux ZOXFL-6619QN2 4.4.0-17134-Microsoft #112-Microsoft Thu Jun 07 22:57:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
Exit codes
  • 1: on error
Or, if you want, you can alternatively use the GitHub discussion Q&A for feedback and questions.