NorLab TeamCity GUI (VPN/intranet access) • norlabulaval (Docker Hub)
A library of shell script functions and a shell testing tools
leveraging both bats-core and docker. N2ST
purposes is
to speed up shell script development and improve code reliability.
Maintainer Luc Coupal
Just clone the norlab-shell-script-tools as a submodule in your project repository (ie the superproject), in an arbitrary directory eg.: my-project/utilities/
.
Procedure
cd <my-project> mkdir utilities git submodule init git submodule \ add https://github.com/norlab-ulaval/norlab-shell-script-tools.git \ utilities/norlab-shell-script-tools # Traverse the submodule recursively to fetch any sub-submodule git submodule update --remote --recursive --init # Commit the submodule to your repository git add .gitmodules git add utilities/norlab-shell-script-tools git commit -m 'Added norlab-shell-script-tools submodule to repository'
To clone your repository and its submodule at the same time, use
git clone --recurse-submodules
Be advise, submodules are a snapshot at a specific commit of the norlab-shell-script-tools repository. To update the submodule to its latest commit, use
[sudo] git submodule update --remote --recursive --init [--force]
Notes:
--force
flag if you want to reset the submodule and throw away local changes to it. This is equivalent to performing git checkout --force
when cd
in the submodule root directory.sudo
if you get an error such as error: unable to unlink old '<name-of-a-file>': Permission denied
To set the submodule to point to a different branch, use
cd <the/submodule/directory> git checkout the_submodule_feature_branch_name
and use the --recurse-submodules
flag when switching branch in your main project
cd <your/project/root> git checkout --recurse-submodules the_feature_branch_nameCommiting to submodule from the main project (the one where the submodule is cloned) If you encounter
error: insufficient permission for adding an object to repository database ...
# Change the `.git/objects` permissions cd <main/project/root>/.git/objects/ chown -R $(id -un):$(id -gn) * # <yourname>:<yourgroup> # Share the git repository (the submodule) with a Group cd ../../<the/submodule/root>/ git config core.sharedRepository group # Note: dont replace the keyword "group"
This should solve the problem permanently.
n2st::
prefix for maintaining legacy v1 API support. Be advised, they will only be available in their n2st::
prefixed form in release >= v3
.Try this in norlab-shell-script-tools
root
source import_norlab_shell_script_tools_lib.bash n2st::norlab_splash "NorLab rule 🦾" https://github.com/norlab-ulavalN2ST shell script function/script library
src/function_library
for shell script functions:
src/utility_scripts
for utility script:
To import the library functions, execute the following
cd <path/to/norlab-shell-script-tools> bash import_norlab_shell_script_tools_lib.bash # All norlab-shell-script-tools functions are now sourced in your current shell.
Note: N2ST
functions are prefixed with n2st
, i.e.: n2st::<function_name>
Copy the norlab-shell-script-tools/tests/tests_template/
directory in your main project top directory and rename it, e.g. tests_template/
→ tests_shell/
( recommand using the convention tests/
);
Add project test code in this new test directory.
test_template.bats
for bats test implementation examples;test_template.bats
and rename it using the convention test_<logic_or_script_name>.bats
;Use the copied script run_bats_core_test_in_n2st.bash
to execute your tests. They will be executed in isolation in a docker container tailormade for testing shell script or command level logic in your codebase.
tests/
directory. Pass your test directory name as an argument otherwise.Assuming that the superproject (i.e. the project which have cloned N2ST
as a submodule) as the following structure, tests/
would be containing all the .bats
files
myCoolSuperProject
┣━━ src/
┣━━ tests/
┃ ┣━━ run_bats_core_test_in_n2st.bash
┃ ┣━━ test_pew_poo_poo.bats
┃ ┗━━ tests_those/
┃ ┣━━ test_poo_po_pew_pow.bats
┃ ┗━━ test_poooow_pew_poo.bats
┣━━ utilities/
┃ ┗━━ norlab-shell-script-tools/
┃ ┣━━ src/
┃ ┣━━ tests/
┃ ┃ ┣━━ bats_testing_tools/
┃ ┃ ┣━━ tests_template/
┃ ┃ ┗━━ ...
┃ ┗━━ ...
┣━━ .env.my_superproject
┣━━ .git
┣━━ .gitmodules
┗━━ README.md
To execute your superproject shell script tests
To execute your superproject shell scripts bats
test via 'norlab-shell-script-tools' library, just run the following from your repository root
cd "<path/to/superproject>/tests" bash run_bats_core_test_in_n2st.bash ['<test-directory>[/<bats-test-file-name.bats>]' ['<image-distro>']]
Arguments:
['<test-directory>']
The directory from which to start test, default to 'tests'['/<bats-test-file-name.bats>']
A specific bats file to run, default will run all bats file in the test directorySee tests/tests_template/run_bats_core_test_in_n2st.bash
for details.
bats
helper library (pre-installed in norlab-shell-script-tools
testing containers in the tests/
dir)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4