Please visit the official GitHub link for more details. Below is a brief use case.
Shellspec is used as a framework for unit test. There are 2 options to install it.
We recently migrated to using container to run shellspec so that it supports all platforms!
Shellspec is already included in the makefile. You can build the dockerfile and run the tests by simply running make shellspec in root (/AgentBaker) directory.
If you want to install it in your local machine, please run curl -fsSL https://git.io/shellspec | sh.
By default, it should be installed in ~/.local/lib/shellspec. Please append it to the $PATH for your convenience. Example command export PATH=$PATH:~/.local/lib/shellspec.
You will need to write xxx_spec.sh file for the test.
For example, AgentBaker/spec/parts/linux/cloud-init/artifacts/cse_install_spec.sh is a test file for AgentBaker/parts/linux/cloud-init/artifacts/cse_install.sh
To run all tests, in AgentBaker folder, simply run make shellspec in root (/AgentBaker) directory. Another way is to run docker run -v "$PWD:/src" shellspec-docker --shell bash --format d.
Assuming you have run at least once make shellspec to build the dockerfile locally,
-
docker run -v "$PWD:/src" shellspec-docker --shell bash --xtraceWith
--xtrace, it will show verbose trace for debugging. -
docker run -t -v "$PWD:/src" shellspec-docker --shell bash --example <test name> -xtraceYou can run a single test case by using
--examplefollowed by the test name. For example,docker run -t -v "$PWD:/src" shellspec-docker --shell bash --example "sets PACKAGE_DOWNLOAD_BASE_URL to packages.aks.azure.comwhen run locally". You can also add--xtraceto display verbose trace for this single test case. -
docker run -v "$PWD:/src" shellspec-docker --shell bash <path to xxx_spec.sh>By providing a full path a particular spec file, you can run only that spec file instead of all spec files in AgentBaker project. For example,
docker run -t -v "$PWD:/src" shellspec-docker --shell bash spec/parts/linux/cloud-init/artifacts/cse_helpers_spec.sh
You can also run shellspec in focus mode via the make shellspec-focus target. This will run shellspec with the --focus flag, which can be useful for debugging multiple test cases at once. For more details, please refer to the official shellspec docs regarding this feature: # allows usage of focus mode: https://github.com/shellspec/shellspec/tree/master?tab=readme-ov-file#fdescribe-fcontext-fexamplegroup---focused-example-group.