Move cli building script to bin/

Add convenience try for pwd as repo to test when calling test_tests.sh without arguments
This commit is contained in:
southerntofu 2022-02-20 21:48:05 +01:00
parent d07f677eab
commit 9f17e49114
3 changed files with 25 additions and 16 deletions

View File

@ -38,7 +38,7 @@ In order to facilitate deployment in varied setups, the following conventions ar
- **if all those discovery methods failed, the validator program fails to start and returns an error code**
- each implementation contains a `spec` submodule containing this very repository (*forge/endpoints*)
- each implementation contains a `test.sh` executable script allowing to start the automated tests for this codebase, as explained in the next section ; the script should also check for the presence of the `specs` submodule and clone it if it was not already done
- each implementation contains a `cli` executable script which will build the code and if it succeeds return a 0 exit code with the absolute path to the executable printed to STDOUT
- each implementation contains a `bin/cli` executable script which will build the code and if it succeeds return a 0 exit code with the absolute path to the executable printed to STDOUT
## Testing
@ -46,17 +46,21 @@ In order to facilitate deployment in varied setups, the following conventions ar
**NOTE:** Running tests requires the bats testing framework. You can usually find it in your distro repositories. If not, head over to the [bats repository](https://github.com/bats-core/bats-core/).
The `test_cli.sh` script is used for testing CLI webhook validators (such as [whck](https://tildegit.org/forge/whck)). It takes as first positional argument a path to the `cli` script returning the (compiled) program to check. If no program is provided as argument, the following paths will be attempted, in order of precedence:
The `test_cli.sh` script is used for testing CLI webhook validators (such as [whck](https://tildegit.org/forge/whck)). It takes as first positional argument a path to the repository to test (which contains a `bin/cli` script as explained above). If no repository is provided as argument, the following paths will be attempted, in order of precedence:
- `./cli`, relative to the directory from which you called the tests (eg. if you're running `specs/test_cli.sh` from whck repository)
- `../cli`, relative to the directory containing test_cli.sh (eg. if you're running `./test_web.sh` from specs submodule in whck repository)
- `./`, relative to the directory from which you called the tests (eg. if you're running `~/endpoints/specs/test_cli.sh` from `~/whck` repository)
- `../`, relative to the directory containing test_cli.sh (eg. if you're running `./test_web.sh` from specs submodule in whck repository, or from the main repository)
- if no path was matched, the test suite fails to start
**To run tests, simply call ./test.sh from your implementation repository**.
If you're making an implementation from scratch, you need to write your custom `cli` script. Then, you can copy the `test.sh` script from [whck](https://tildegit.org/forge/whck) and it should work.
If you're making an implementation from scratch, you need to write your custom `bin/cli` script. Then, you can copy the `test.sh` script from [whck](https://tildegit.org/forge/whck) and it should work.
**Note: to test that the test suites can be called from several folders using different kind of relative/absolute paths, use the `test_tests.sh` script.:**
**Note: to test that the test suites can be called from several folders using different kind of relative/absolute paths, use the `test_tests.sh` script.:** It will try the following paths, in order of precedence:
- the explicit path passed as first argument
- the current working dir (from which test_tests.sh is called), so you can for example call `spec/test_tests.sh` from the whck repository
- a temporary directory where whck will be cloned, and tests will be run against the latest commit
# Web interface {#web}

View File

@ -12,7 +12,7 @@ export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh"
source tests/helper.bash
if [ -z "$1" ]; then
output="$(findBin ../cli)"
output="$(findBin "$ORIGDIR"/bin/cli ../bin/cli)"
if [ $? -eq 0 ]; then
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
FIND_WHCK="$output"
@ -29,7 +29,7 @@ if [ -z "$1" ]; then
# cli script needs to be executed to get absolute path to the program
export WHCK="$("$FIND_WHCK")"
else
if WHCK="$(realpath "$ORIGDIR"/"$1")"; then
if WHCK="$(realpath -q "$ORIGDIR"/"$1")"; then
export WHCK
else
export WHCK="$(realpath "$1")"

View File

@ -7,22 +7,27 @@ function testVariousScenarios() {
./test.sh || echo "ERROR running from repo"
cd spec
./test_cli.sh || echo "ERROR test_cli.sh failed with implicit ../cli"
./test_cli.sh "$(../cli)" || echo "ERROR test_cli with explicit result from ../cli"
./test_cli.sh "$(../bin/cli)" || echo "ERROR test_cli with explicit result from ../cli"
../test.sh || echo "ERROR test.sh failed called from spec submodule"
cd tests
../../test.sh || echo "ERROR test.sh failed from spec/tests folder"
../test_cli.sh || echo "ERROR test_cli.sh failed from spec/tests folder with implicit ../../cli"
../test_cli.sh "$(../../cli)" || echo "ERROR test_cli.sh failed from spec/tests folder with explicit result from ../../cli"
../test_cli.sh "$(../../bin/cli)" || echo "ERROR test_cli.sh failed from spec/tests folder with explicit result from ../../cli"
}
ORIGDIR="$(pwd)"
if [ -z "$1" ]; then
TMPDIR="$(mktemp -d)"
cd "$TMPDIR"
git clone --recursive https://tildegit.org/forge/whck
cd whck
testVariousScenarios
rm -rf "$TMPDIR"
# When no explicit dir, try ./ first, otherwise make a temporary dir
if [ -x bin/cli ]; then
testVariousScenarios
else
TMPDIR="$(mktemp -d)"
cd "$TMPDIR"
git clone --recursive https://tildegit.org/forge/whck
cd whck
testVariousScenarios
rm -rf "$TMPDIR"
fi
else
if [ ! -d "$1" ]; then
echo "Wrong repo: "$1""