-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Unit Tests | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: [push] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout shell test framework shUnit2 | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: kward/shunit2 | ||
path: ${{github.workspace}}/tests/shunit2 | ||
fetch-depth: 1 | ||
- name: Run unit tests | ||
shell: bash | ||
run: | | ||
export PATH="tests/shunit2:$PATH" | ||
tests/unit_test.sh | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env bash | ||
# file: tests/unit_test.sh | ||
|
||
|
||
test_urlencode() { | ||
result=`urlencode "/test/a/b/c"` | ||
expected="%2Ftest%2Fa%2Fb%2Fc" | ||
assertEquals \ | ||
"the result of url_encode() was wrong" \ | ||
"${expected}" "${result}" | ||
} | ||
|
||
|
||
test_pathtype() { | ||
result=`pathtype "/test/a/b/c"` | ||
expected='curl "${curl_authorization[@]}" \ | ||
"${curl_options_no_errors[@]}" \ | ||
-X GET "$api/namespace/$path" \ | ||
| jq -r .fileType' | ||
assertEquals \ | ||
"the result of pathtype() was wrong" \ | ||
"${expected}" "${result}" | ||
} | ||
|
||
|
||
test_create_path() { | ||
# Check error handling when incorrect path is given | ||
counter=0 | ||
( create_path "/test/a" true >${stdoutF} 2>${stderrF} ) | ||
result=$? | ||
assertFalse "expecting return code of 1 (false)" ${result} | ||
grep "ERROR: Unable to create dirs. Check the specified path" "${stderrF}" >/dev/null | ||
assertTrue "STDERR message incorrect" $? | ||
|
||
# Check error handling when parent does not exist | ||
( create_path "/test/a" false >${stdoutF} 2>${stderrF} ) | ||
result=$? | ||
assertFalse "expecting return code of 1 (false)" ${result} | ||
grep "ERROR: parent dir '/test' does not exist. To recursivly create dirs, add --recursive" "${stderrF}" >/dev/null | ||
assertTrue 'STDERR message incorrect' $? | ||
|
||
# Check error handling when max number of directories is exceeded | ||
counter=10 | ||
( create_path "/test/a" true >${stdoutF} 2>${stderrF} ) | ||
result=$? | ||
assertFalse "expecting return code of 1 (false)" ${result} | ||
grep "ERROR: max number of directories that can be created at once is 10" "${stderrF}" >/dev/null | ||
assertTrue "STDERR message incorrect" $? | ||
} | ||
|
||
|
||
test_get_pnfsid() { | ||
result=`get_pnfsid "/test/a/b/c"` | ||
expected='curl "${curl_authorization[@]}" \ | ||
"${curl_options_no_errors[@]}" \ | ||
-X GET "$api/namespace/$path" \ | ||
| jq -r .pnfsId' | ||
assertEquals \ | ||
"the result of get_pnfsid() was wrong" \ | ||
"${expected}" "${result}" | ||
} | ||
|
||
|
||
test_is_online() { | ||
result=`is_online "/test/a/b/c"` | ||
expected='curl "${curl_authorization[@]}" \ | ||
"${curl_options_no_errors[@]}" \ | ||
-X GET "$api/namespace/$path?locality=true&qos=true" \ | ||
| jq -r ".fileLocality" \ | ||
| grep --silent "ONLINE"' | ||
assertEquals \ | ||
"the result of is_online() was wrong" \ | ||
"${expected}" "${result}" | ||
} | ||
|
||
|
||
test_get_subdirs() { | ||
result=`get_subdirs "/test/a/b/c"` | ||
expected='curl "${curl_authorization[@]}" \ | ||
"${curl_options_common[@]}" \ | ||
-X GET "$api/namespace/$path?children=true" \ | ||
| jq -r "$str"' | ||
assertEquals \ | ||
"the result of get_subdirs() was wrong" \ | ||
"${expected}" "${result}" | ||
} | ||
|
||
|
||
test_get_files_in_dir() { | ||
result=`get_files_in_dir "/test/a/b/c"` | ||
expected='curl "${curl_authorization[@]}" \ | ||
"${curl_options_common[@]}" \ | ||
-X GET "$api/namespace/$path?children=true" \ | ||
| jq -r "$str"' | ||
assertEquals \ | ||
"the result of get_files_in_dir() was wrong" \ | ||
"${expected}" "${result}" | ||
} | ||
|
||
|
||
oneTimeSetUp() { | ||
outputDir="${SHUNIT_TMPDIR}/output" | ||
mkdir "${outputDir}" | ||
stdoutF="${outputDir}/stdout" | ||
stderrF="${outputDir}/stderr" | ||
debug=false | ||
dry_run=true | ||
|
||
# Load functions to test | ||
. ada/ada_functions.inc | ||
} | ||
|
||
|
||
# Load and run shunit2 | ||
. shunit2 |