diff options
| author | Egor Tensin <egor@tensin.name> | 2026-10-15 02:00:06 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-10-15 08:32:35 +0500 |
| commit | ded8a1956cfe68c84023f9127f796a5ddf1aef1b (patch) | |
| tree | 3313cb3ce0f99bd58b623b6283d95405c805ffec /test/integration/lib | |
| parent | v9.0.0 (diff) | |
| download | cgitize-ded8a1956cfe68c84023f9127f796a5ddf1aef1b.tar.gz cgitize-ded8a1956cfe68c84023f9127f796a5ddf1aef1b.zip | |
t/i: migrate to test-harness
Diffstat (limited to '')
| -rw-r--r-- | test/integration/lib/basic.sh | 72 | ||||
| -rw-r--r-- | test/integration/lib/common.sh | 92 | ||||
| -rw-r--r-- | test/integration/lib/example.sh | 47 |
3 files changed, 211 insertions, 0 deletions
diff --git a/test/integration/lib/basic.sh b/test/integration/lib/basic.sh new file mode 100644 index 0000000..d537e8a --- /dev/null +++ b/test/integration/lib/basic.sh @@ -0,0 +1,72 @@ +# Copyright (c) 2026 Egor Tensin <egor@tensin.name> +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize +# Distributed under the MIT License. + +test_basic_setup() { + test_repo_dir="$test_root_dir/repo" + test_output_dir="$test_root_dir/output" + test_config_path="$test_root_dir/cgitize.toml" + test_mirror_name=repo_mirror + test_mirror_dir="$test_output_dir/$test_mirror_name.git" + + log "Repo directory: $test_repo_dir" + log "Output directory: $test_output_dir" + log "Config path: $test_config_path" + + mkdir -- "$test_repo_dir" + git -C "$test_repo_dir" init -q + git -C "$test_repo_dir" config user.name 'Test user' + git -C "$test_repo_dir" config user.email 'test@example.com' + + test_basic_make_commit + test_basic_make_commit + + cat > "$test_config_path" <<EOF +output_dir = "$test_output_dir" + +[repositories.repo] +name = "$test_mirror_name" +clone_url = "$test_repo_dir" +EOF +} + +_test_commit_counter=0 + +test_basic_make_commit() { + _test_commit_counter=$((_test_commit_counter + 1)) + + local file + file="$_test_commit_counter.txt" + echo "$_test_commit_counter" > "$test_repo_dir/$file" + + log "Commiting file $file in $test_repo_dir..." + + touch -- "$test_repo_dir/file" + git -C "$test_repo_dir" add "$file" + git -C "$test_repo_dir" commit -q -m "committing $file" +} + +test_basic_verify_commits() { + log "Verifying commits in $test_mirror_dir..." + + local msg + git -C "$test_mirror_dir" log --reverse --pretty=tformat:%s | + while IFS= read -r msg; do + if [ "$#" -eq 0 ]; then + fail "Unexpected commit found: $msg" + return 1 + fi + if [ "$msg" != "$1" ]; then + fail "Unexpected commit found: $msg" + fail_details "Expected commit: $1" + return 1 + fi + shift + done + + if [ "$#" -ne 0 ]; then + fail "Missing commit: $1" + return 1 + fi +} diff --git a/test/integration/lib/common.sh b/test/integration/lib/common.sh new file mode 100644 index 0000000..10774a7 --- /dev/null +++ b/test/integration/lib/common.sh @@ -0,0 +1,92 @@ +# Copyright (c) 2026 Egor Tensin <egor@tensin.name> +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize +# Distributed under the MIT License. + +export GIT_CONFIG_NOSYSTEM=true +#export GIT_CONFIG_GLOBAL=/dev/null + +test_run_cgitize() { + local cmd=(python3 -m cgitize.main --config "$test_config_path" "$@") + log_run "${cmd[@]}" + PYTHONPATH="$tests_dir/../.." "${cmd[@]}" +} + +test_verify_repos() { + local repo + for repo; do + log "Verifying repository: $repo..." + + local repo_dir + repo_dir="$test_output_dir/$repo.git" + GIT_DIR="$repo_dir" git rev-parse HEAD > /dev/null + log 'HEAD is fine.' + + if test -s "$repo_dir/info/web/last-modified"; then + log 'last-modified is fine.' + else + fail 'last-modified is missing!' + return 1 + fi + done +} + +test_verify_no_repos() { + local repo + for repo; do + log "Verifying repository doesn't exist: $repo" + + local repo_dir + repo_dir="$test_output_dir/$repo.git" + + if [ -e "$repo_dir" ]; then + fail "Exists, but it shouldn't" + return 1 + fi + done +} + +test_verify_origin() { + if [ "$#" -ne 2 ]; then + log "usage: ${FUNCNAME[0]} REPO URL" + return 1 + fi + + local repo="$1" + local expected="$2" + + log "Verifying origin for $repo..." + + local repo_dir + repo_dir="$test_output_dir/$repo.git" + + local actual + actual="$( GIT_DIR="$repo_dir" git config --get remote.origin.url )" + + if [ "$expected" != "$actual" ]; then + fail "Origin doesn't match!" + fail_details "Expected: $expected" + fail_details "Actual: $actual" + return 1 + fi +} + +test_verify_error_header_empty() { + log 'Verifying the error header...' + if [ -s "$test_output_dir/error.html" ]; then + fail "The error header should be empty" + return 1 + fi +} + +test_verify_error_header() { + log 'Verifying the error header...' + + local msg="Some repositories couldn't be updated" + + if ! grep -F -- "$msg" "$test_output_dir/error.html" > /dev/null; then + fail "The error header doesn't contain the required error" + fail_details "Expected error: $msg" + return 1 + fi +} diff --git a/test/integration/lib/example.sh b/test/integration/lib/example.sh new file mode 100644 index 0000000..2dd1ad6 --- /dev/null +++ b/test/integration/lib/example.sh @@ -0,0 +1,47 @@ +# Copyright (c) 2026 Egor Tensin <egor@tensin.name> +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize +# Distributed under the MIT License. + +_sed_config() { + if [ "$#" -ne 1 ]; then + log "usage: ${FUNCNAME[0]} EXPR" + return 1 + fi + + sed -i -E -e "$1" -- "$test_config_path" +} + +_test_example_setup_config() { + test_config_path="$test_root_dir/cgitize.toml" + log "Config path: $test_config_path" + + cp -- "$tests_dir/../../examples/cgitize.toml" "$test_config_path" + + _sed_config 's@^output_dir = .*$@output_dir = "'"$test_output_dir"'"@' + test_example_clone_ssh + test_example_private_skip +} + +test_example_setup() { + test_output_dir="$test_root_dir/output" + log "Output directory: $test_output_dir" + + _test_example_setup_config +} + +test_example_clone_ssh() { + _sed_config 's/^clone_via_ssh = (true|false)$/clone_via_ssh = true/' +} + +test_example_clone_https() { + _sed_config 's/^clone_via_ssh = (true|false)$/clone_via_ssh = false/' +} + +test_example_private_include() { + _sed_config 's/^private = (true|false)$/private = true/' +} + +test_example_private_skip() { + _sed_config 's/^private = (true|false)$/private = false/' +} |
