Skip to content

Commit

Permalink
test(import lib): add tests for return to original dir on script exit
Browse files Browse the repository at this point in the history
- Added test cases to ensure the script returns to the original directory on exit.
- Verified functionality for both standalone and superproject contexts.
- add test for N2ST_VERSION (fetching and format)
  • Loading branch information
RedLeader962 committed Aug 8, 2024
1 parent d6d9dee commit d1f3220
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/test_import_lib.bats
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ teardown() {
assert_empty ${N2ST_GIT_NAME}
assert_empty ${N2ST_SRC_NAME}
assert_empty ${N2ST_PATH}
assert_empty ${N2ST_VERSION}

# ....Import N2ST library........................................................................
source "$TESTED_FILE"
Expand All @@ -99,6 +100,7 @@ teardown() {
assert_equal "${N2ST_GIT_NAME}" "norlab-shell-script-tools"
assert_equal "${N2ST_SRC_NAME}" "norlab-shell-script-tools"
assert_equal "${N2ST_PATH}" "/code/norlab-shell-script-tools"
assert_regex "${N2ST_VERSION}" [0-9]+\.[0-9]+\.[0-9]+
}

@test "${TESTED_FILE} › validate the import function mechanism › expect pass" {
Expand All @@ -119,6 +121,49 @@ teardown() {
assert_success
}

@test "${TESTED_FILE} › validate return to original dir on script exit › expect pass" {
# ....Test setup.................................................................................
local ORIGINAL_CWD=$(pwd)

# ....Import N2ST library........................................................................
source "$TESTED_FILE"

# ....Tests......................................................................................
assert_equal "$(pwd)" "${ORIGINAL_CWD}"
}

@test "${TESTED_FILE} › validate return to original dir on script exit (superproject version) › expect pass" {
TEST_N2ST_PATH="/code/norlab-shell-script-tools"
SUPERPROJECT_NAME="dockerized-norlab-project-mock"
SUPERPROJECT_PATH="/code/${SUPERPROJECT_NAME}"

# ....Setup superproject.........................................................................
assert_equal "$(pwd)" "$TEST_N2ST_PATH"
cd ..
assert_equal "$(pwd)" "/code"

git clone "https://github.com/norlab-ulaval/${SUPERPROJECT_NAME}.git"
assert_dir_exist "${SUPERPROJECT_PATH}"

# ....Test setup.................................................................................
cd "${SUPERPROJECT_PATH}"
local ORIGINAL_CWD=$(pwd)

# # Visualise the testing directories
# (echo && pwd && tree -L 2 -a) >&3

# ....Import N2ST library........................................................................
# cd "$TEST_N2ST_PATH"
source "${TEST_N2ST_PATH}/${TESTED_FILE}"

# ....Tests......................................................................................
assert_equal "$(pwd)" "${ORIGINAL_CWD}"

# ....Teardown this test case ...................................................................
# Delete cloned repository mock
rm -rf "$SUPERPROJECT_PATH"
}


@test "${TESTED_FILE} › import from within a superproject › Env variables set ok" {
TEST_N2ST_PATH="/code/norlab-shell-script-tools"
Expand Down

0 comments on commit d1f3220

Please sign in to comment.