MIL-007: fix the new tests and document starting from any folder
- README: start from the folder where the project is created, make the script a global command, where config.env and .env are read from and the confirmation - Tests: qc tests set up the temp directory and force a real failure; the default-files test runs from a folder without files of its own; the link test allows for path aliases; the work directory cleanup deletes links Task: MIL-007#3 Task: MIL-007#4 Refs #49 Refs #51
This commit is contained in:
+1
-1
@@ -167,7 +167,7 @@ setup_local_remotes() {
|
||||
# first, then the now empty directories from the bottom up.
|
||||
remove_workdir() {
|
||||
if [[ -n $WORK && -d $WORK ]]; then
|
||||
find "$WORK" \( -type f -o -type p \) -delete
|
||||
find "$WORK" \( -type f -o -type p -o -type l \) -delete
|
||||
find "$WORK" -depth -type d -exec rmdir {} +
|
||||
fi
|
||||
WORK=""
|
||||
|
||||
+17
-16
@@ -4,7 +4,7 @@
|
||||
# --config and --env, else ./config.env and ./.env, else the checkout's.
|
||||
# Sourced by run-tests.sh.
|
||||
|
||||
# shellcheck disable=SC2016 # snippet and fixture text is literal on purpose
|
||||
# shellcheck disable=SC2016,SC2153 # snippet and fixture text is literal on purpose; SCRIPT comes from lib.sh
|
||||
|
||||
# make_checkout: a copy of the script's own files with config.env and .env
|
||||
# beside them, standing in for the checkout; the path is in CHECKOUT.
|
||||
@@ -53,19 +53,19 @@ test_the_framework_checklists_are_fetched() {
|
||||
test_an_empty_qc_is_filled_by_a_second_run_and_a_complete_one_is_not_changed() {
|
||||
setup_hosts
|
||||
printf 'GITEA_TOKEN=%s\n' "$FAKE_GITEA_TOKEN" >"$WORK/.env"
|
||||
local dir="$WORK/project" answers git_in
|
||||
local dir="$WORK/project" answers
|
||||
printf -v answers 'my-app\n\n\nTirSystem\nn\n%s\nn\n' "$dir"
|
||||
run_apply "$answers"$'y\n'
|
||||
assert_status "first run" 0 "$STATUS"
|
||||
git_in() { GIT_CONFIG_GLOBAL="$WORK/gitconfig" GIT_CONFIG_NOSYSTEM=1 git -C "$dir/framework" "$@"; }
|
||||
git_in submodule deinit -f qc >/dev/null 2>&1
|
||||
assert_file_missing "qc emptied" "$dir/framework/qc/qc-business-case.md"
|
||||
run_lib "" "init_framework_submodules '$dir'"
|
||||
run_lib "" "setup_temp_dir; init_framework_submodules '$dir'"
|
||||
assert_status "repair" 0 "$STATUS"
|
||||
assert_file_exists "qc filled again" "$dir/framework/qc/qc-business-case.md"
|
||||
local before after
|
||||
before="$(git_in status --porcelain)"
|
||||
run_lib "" "init_framework_submodules '$dir'"
|
||||
run_lib "" "setup_temp_dir; init_framework_submodules '$dir'"
|
||||
after="$(git_in status --porcelain)"
|
||||
assert_status "second call" 0 "$STATUS"
|
||||
assert_eq "nothing else changed" "$before" "$after"
|
||||
@@ -78,14 +78,15 @@ test_a_failed_qc_fetch_names_the_command_to_run_by_hand() {
|
||||
printf -v answers 'my-app\n\n\nTirSystem\nn\n%s\nn\n' "$dir"
|
||||
run_apply "$answers"$'y\n'
|
||||
GIT_CONFIG_GLOBAL="$WORK/gitconfig" GIT_CONFIG_NOSYSTEM=1 git -C "$dir/framework" submodule deinit -f qc >/dev/null 2>&1
|
||||
printf '[url "file://%s/nowhere/"]\n\tinsteadOf = ssh://git@git.tirsystem.com:10022/\n' "$WORK" >>"$WORK/gitconfig"
|
||||
GIT_CONFIG_GLOBAL="$WORK/gitconfig" GIT_CONFIG_NOSYSTEM=1 git -C "$dir/framework" config --unset-all submodule.qc.url >/dev/null 2>&1 || true
|
||||
run_lib "" "init_framework_submodules '$dir'"
|
||||
if ((STATUS == 0)); then
|
||||
# The earlier alias still wins in this git; remove the working alias instead.
|
||||
sed -i '/remote\/"\]/,+1d' "$WORK/gitconfig"
|
||||
run_lib "" "init_framework_submodules '$dir'"
|
||||
# Drop the cached copy of the checklists and refuse local fetches, so they
|
||||
# cannot be fetched again.
|
||||
local cache="$dir/.git/modules/framework/modules/qc"
|
||||
if [[ -d $cache ]]; then
|
||||
find "$cache" \( -type f -o -type l \) -delete
|
||||
find "$cache" -depth -type d -exec rmdir {} +
|
||||
fi
|
||||
printf '[protocol "file"]\n\tallow = never\n' >>"$WORK/gitconfig"
|
||||
run_lib "" "setup_temp_dir; init_framework_submodules '$dir'"
|
||||
assert_status "fetch fails" 1 "$STATUS"
|
||||
assert_contains "the command" "$ERR" "git submodule update --init --recursive"
|
||||
assert_not_contains "no token" "$ERR" "$FAKE_GITEA_TOKEN"
|
||||
@@ -96,7 +97,7 @@ test_a_framework_without_a_submodule_of_its_own_is_not_a_failure() {
|
||||
local dir="$WORK/plain"
|
||||
mkdir -p "$dir"
|
||||
git init -q "$dir"
|
||||
run_lib "" "init_framework_submodules '$dir'"
|
||||
run_lib "" "setup_temp_dir; init_framework_submodules '$dir'"
|
||||
assert_status "nothing to fetch" 0 "$STATUS"
|
||||
}
|
||||
|
||||
@@ -186,7 +187,7 @@ test_the_script_runs_through_a_link_and_creates_the_project_in_the_current_folde
|
||||
make_folder
|
||||
local bin="$WORK/linkbin"
|
||||
mkdir -p "$bin"
|
||||
ln -s "$CHECKOUT/src/create-project.sh" "$bin/repo-foundry" 2>/dev/null || true
|
||||
MSYS=winsymlinks:nativestrict ln -s "$CHECKOUT/src/create-project.sh" "$bin/repo-foundry" 2>/dev/null || true
|
||||
if [[ ! -L $bin/repo-foundry ]]; then
|
||||
printf 'skipped: this shell cannot make symbolic links\n'
|
||||
return 0
|
||||
@@ -196,7 +197,7 @@ test_the_script_runs_through_a_link_and_creates_the_project_in_the_current_folde
|
||||
assert_contains "found its files" "$OUT" "RepoFoundry"
|
||||
run_from "$bin/repo-foundry" "$FOLDER" "$ANSWERS_GITEA_ONLY"$'y\n' --apply
|
||||
assert_status "apply through the link" 0 "$STATUS"
|
||||
assert_contains "the checkout's files" "$OUT" "Config file : $CHECKOUT/config.env (from the checkout)"
|
||||
assert_contains "the checkout's files" "$OUT" "/checkout/config.env (from the checkout)"
|
||||
assert_file_exists "the project is in the current folder" "$FOLDER/my-app/.git"
|
||||
assert_file_missing "not in the checkout" "$CHECKOUT/my-app"
|
||||
}
|
||||
@@ -207,12 +208,12 @@ test_a_link_to_a_link_is_followed() {
|
||||
make_folder
|
||||
local bin="$WORK/linkbin"
|
||||
mkdir -p "$bin"
|
||||
ln -s "$CHECKOUT/src/create-project.sh" "$bin/first" 2>/dev/null || true
|
||||
MSYS=winsymlinks:nativestrict ln -s "$CHECKOUT/src/create-project.sh" "$bin/first" 2>/dev/null || true
|
||||
[[ -L $bin/first ]] || {
|
||||
printf 'skipped: this shell cannot make symbolic links\n'
|
||||
return 0
|
||||
}
|
||||
(cd "$bin" && ln -s first second)
|
||||
(cd "$bin" && MSYS=winsymlinks:nativestrict ln -s first second)
|
||||
run_from "$bin/second" "$FOLDER" "" --version
|
||||
assert_status "second link" 0 "$STATUS"
|
||||
}
|
||||
|
||||
@@ -201,13 +201,15 @@ test_default_files_are_in_the_project_root() {
|
||||
cp "$WORK/config.env" "$WORK/project/config.env"
|
||||
cp "$WORK/.env" "$WORK/project/.env"
|
||||
STATUS=0
|
||||
PATH="$WORK/bin:$PATH" STUB_DIR="$WORK" TMPDIR="$WORK/tmp" "$BASH" "$WORK/project/src/create-project.sh" \
|
||||
<<<"$ANSWERS_GITHUB" >"$WORK/out.txt" 2>"$WORK/err.txt" || STATUS=$?
|
||||
(cd "$WORK/project" && PATH="$WORK/bin:$PATH" STUB_DIR="$WORK" TMPDIR="$WORK/tmp" "$BASH" "$WORK/project/src/create-project.sh" \
|
||||
<<<"$ANSWERS_GITHUB" >"$WORK/out.txt" 2>"$WORK/err.txt") || STATUS=$?
|
||||
assert_status "run with the default files" 0 "$STATUS"
|
||||
assert_contains "found config.env in the project root" "$(cat "$WORK/out.txt")" "https://git.example.test/TirSystem/my-app"
|
||||
# Run from another directory: the defaults follow the script, not the cwd.
|
||||
# Run from another folder that holds no files of its own: the checkout's
|
||||
# files are used; the defaults follow the script, not the current folder.
|
||||
mkdir -p "$WORK/elsewhere"
|
||||
STATUS=0
|
||||
(cd "$WORK" && PATH="$WORK/bin:$PATH" STUB_DIR="$WORK" TMPDIR="$WORK/tmp" "$BASH" "$WORK/project/src/create-project.sh" \
|
||||
(cd "$WORK/elsewhere" && PATH="$WORK/bin:$PATH" STUB_DIR="$WORK" TMPDIR="$WORK/tmp" "$BASH" "$WORK/project/src/create-project.sh" \
|
||||
<<<"$ANSWERS_GITEA_ONLY" >"$WORK/out.txt" 2>"$WORK/err.txt") || STATUS=$?
|
||||
assert_status "run from another directory" 0 "$STATUS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user