aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-15 02:00:06 +0500
committerEgor Tensin <egor@tensin.name>2026-10-15 08:32:35 +0500
commitded8a1956cfe68c84023f9127f796a5ddf1aef1b (patch)
tree3313cb3ce0f99bd58b623b6283d95405c805ffec
parentv9.0.0 (diff)
downloadcgitize-ded8a1956cfe68c84023f9127f796a5ddf1aef1b.tar.gz
cgitize-ded8a1956cfe68c84023f9127f796a5ddf1aef1b.zip
t/i: migrate to test-harness
-rw-r--r--.github/workflows/ci.yml12
-rw-r--r--.gitmodules3
-rw-r--r--DEVELOPMENT.md30
-rw-r--r--Makefile24
-rwxr-xr-xtest/integration/example/test.sh312
-rw-r--r--test/integration/lib/basic.sh72
-rw-r--r--test/integration/lib/common.sh92
-rw-r--r--test/integration/lib/example.sh47
-rwxr-xr-xtest/integration/local/test.sh244
m---------test/integration/runner0
-rw-r--r--test/integration/tst-basic-error.sh21
-rw-r--r--test/integration/tst-basic.sh21
-rw-r--r--test/integration/tst-example-https-private.sh33
-rw-r--r--test/integration/tst-example-https.sh31
-rw-r--r--test/integration/tst-example-one-repo.sh10
-rw-r--r--test/integration/tst-example-ssh-private.sh33
-rw-r--r--test/integration/tst-example-ssh.sh31
17 files changed, 432 insertions, 584 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b514c16..c9af59f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -43,6 +43,7 @@ jobs:
uses: actions/checkout@v7
with:
fetch-depth: 0
+ submodules: recursive
- name: Set up Python
uses: actions/setup-python@v7
with:
@@ -61,6 +62,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v7
+ with:
+ submodules: recursive
- name: Integration test (Docker)
run: sudo make test/docker
@@ -80,6 +83,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v7
+ with:
+ submodules: recursive
- name: Set up Python
uses: actions/setup-python@v7
with:
@@ -90,8 +95,8 @@ jobs:
uses: webfactory/ssh-agent@v0.10.0
with:
ssh-private-key: '${{ secrets.SSH_KEY }}'
- - name: Integration test (example config)
- run: make test/example
+ - name: Integration tests
+ run: make test/integration
publish_docker:
needs:
@@ -110,6 +115,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v7
+ with:
+ submodules: recursive
# https://github.com/docker/metadata-action#semver
- id: meta
name: Docker Hub metadata
@@ -168,6 +175,7 @@ jobs:
uses: actions/checkout@v7
with:
fetch-depth: 0
+ submodules: recursive
- name: Set up Python
uses: actions/setup-python@v7
- name: Verify package can be installed
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..bc03511
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "test/integration/local/runner"]
+ path = test/integration/runner
+ url = https://github.com/egor-tensin/test-harness.git
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 34105e6..79be474 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -8,8 +8,8 @@ Workspace setup
Testing
-------
-N.B.: `make test` is a shortcut for unit tests and the `local` integration
-test.
+N.B.: `make test` is a shortcut for unit tests and the "basic" integration
+tests.
### Unit tests
@@ -29,22 +29,24 @@ You can run `. test/set_credentials.sh`; it'll ask you to fill in the secrets.
### Integration
-* There're three integration tests: `local`, `docker` and `example`.
-Run them using
+ make test/integration
- make test/local
- sudo make test/docker
- make test/example
-
- * The `example` test uses the forges' APIs and might easily hit their rate
+* The "example" tests use the forges' APIs and might easily hit their rate
limits.
Use the tokens used for unit tests.
- * Additionally, it tests cloning via SSH (the `clone_via_ssh` setting) too,
-so you need to add the secret project-specific SSH key to your agent as well
-(make sure it's the only one in the agent; if there's a key associated with
-another user, it could get used instead).
+* Additionally, it tests cloning via SSH (the `clone_via_ssh` setting) too, so
+you need to add the secret project-specific SSH key to your agent as well (make
+sure it's the only one in the agent; if there's a key associated with another
+user, it could get used instead).
+* Run only basic integration tests:
+
+ make test/integration/basic
+
+### Docker setup
+
+ sudo make test/docker
-[examples/cgitize.toml]: examples/cgitize.toml
+It's a separate test to check Docker container building & setup.
Upgrading dependencies
----------------------
diff --git a/Makefile b/Makefile
index 1930ec8..8b08a13 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ python:
repl: python
.PHONY: test
-test: test/unit test/local
+test: test/unit test/integration/basic
.PHONY: test/unit
test/unit:
@@ -59,12 +59,19 @@ test/unit:
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
python -m unittest --verbose --buffer
-.PHONY: test/local
-test/local:
+.PHONY: test/integration
+test/integration:
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- @echo Integration test: local
+ @echo Integration tests
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ./test/integration/local/test.sh
+ ./test/integration/runner/harness
+
+.PHONY: test/integration/basic
+test/integration/basic:
+ @echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ @echo Basic integration tests
+ @echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ./test/integration/runner/harness -f '*basic*'
.PHONY: test/docker
test/docker:
@@ -72,10 +79,3 @@ test/docker:
@echo Integration test: docker
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./test/integration/docker/test.sh
-
-.PHONY: test/example
-test/example:
- @echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- @echo Integration test: example
- @echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ./test/integration/example/test.sh
diff --git a/test/integration/example/test.sh b/test/integration/example/test.sh
deleted file mode 100755
index b7773b1..0000000
--- a/test/integration/example/test.sh
+++ /dev/null
@@ -1,312 +0,0 @@
-#!/usr/bin/env bash
-
-set -o errexit -o nounset -o pipefail
-shopt -s inherit_errexit lastpipe
-
-script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
-script_dir="$( cd -- "$script_dir" && pwd )"
-readonly script_dir
-
-readonly cgitize_toml_path="$script_dir/../../../examples/cgitize.toml"
-readonly output_dir='/tmp/cgitize'
-
-success() {
- echo
- echo ----------------------------------------------------------------------
- echo "SUCCESS: ${FUNCNAME[1]}"
- echo ----------------------------------------------------------------------
-}
-
-clone_via_ssh_true() {
- sed -i -E -e 's/^clone_via_ssh = (true|false)$/clone_via_ssh = true/' -- "$cgitize_toml_path"
-}
-
-clone_via_ssh_false() {
- sed -i -E -e 's/^clone_via_ssh = (true|false)$/clone_via_ssh = false/' -- "$cgitize_toml_path"
-}
-
-private_repos_true() {
- sed -i -E -e 's/^private = (true|false)$/private = true/' -- "$cgitize_toml_path"
-}
-
-private_repos_false() {
- sed -i -E -e 's/^private = (true|false)$/private = false/' -- "$cgitize_toml_path"
-}
-
-cleanup() {
- echo
- echo ----------------------------------------------------------------------
- echo Cleaning up
- echo ----------------------------------------------------------------------
-
- echo "Removing output directory: $output_dir"
- rm -rf -- "$output_dir"
- echo "Reverting clone_via_ssh settings: $cgitize_toml_path"
- clone_via_ssh_false
- echo "Reverting repository visibility settings: $cgitize_toml_path"
- private_repos_false
-}
-
-cgitize() {
- echo
- echo ----------------------------------------------------------------------
- echo Running cgitize
- echo ----------------------------------------------------------------------
-
- python3 -m cgitize.main --config "$cgitize_toml_path" "$@"
-}
-
-setup_ssh() {
- clone_via_ssh_true
-}
-
-setup_https() {
- clone_via_ssh_false
-}
-
-setup_private_repos() {
- private_repos_true
-}
-
-verify_origin() {
- if [ "$#" -ne 2 ]; then
- echo "usage: ${FUNCNAME[0]} REPO URL" >&2
- return 1
- fi
-
- local repo="$1"
- local expected="$2"
-
- echo
- echo ----------------------------------------------------------------------
- echo "Verifying origin: $repo"
- echo ----------------------------------------------------------------------
-
- local repo_dir="$output_dir/$repo.git"
-
- local actual
- actual="$( GIT_DIR="$repo_dir" git config --get remote.origin.url )"
-
- if [ "$expected" = "$actual" ]; then
- echo 'It matches.'
- else
- echo "It doesn't match!"
- echo " Expected: $expected"
- echo " Actual: $actual"
- return 1
- fi
-}
-
-verify_repos() {
- local repo
- for repo; do
- echo
- echo ----------------------------------------------------------------------
- echo "Verifying repository: $repo"
- echo ----------------------------------------------------------------------
-
- local repo_dir="$output_dir/$repo.git"
- GIT_DIR="$repo_dir" git rev-parse HEAD > /dev/null
- echo 'HEAD is fine.'
-
- if test -f "$repo_dir/info/web/last-modified"; then
- echo 'last-modified is fine.'
- else
- echo 'last-modified is missing!'
- return 1
- fi
- done
-}
-
-verify_no_repos() {
- local repo
- for repo; do
- echo
- echo ----------------------------------------------------------------------
- echo "Verifying repository doesn't exist: $repo"
- echo ----------------------------------------------------------------------
-
- local repo_dir="$output_dir/$repo.git"
- if [ -e "$repo_dir" ]; then
- echo "Exists, but it shouldn't."
- return 1
- fi
- done
-}
-
-test_ssh() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_ssh
- cgitize
-
- verify_repos \
- lens \
- chromiumembedded/cef \
- graphviz \
- wireguard/wintun \
- goauthentik-dir/authentik \
- github-dir/public \
- bitbucket-dir/public \
- gitlab-dir/public
-
- verify_no_repos \
- github-dir/private \
- bitbucket-dir/private \
- gitlab-dir/private
-
- verify_origin lens 'git@github.com:ekmett/lens.git'
- verify_origin chromiumembedded/cef 'git@bitbucket.org:chromiumembedded/cef.git'
- verify_origin graphviz 'git@gitlab.com:graphviz/graphviz.git'
- verify_origin goauthentik-dir/authentik 'git@github.com:goauthentik/authentik.git'
-
- verify_origin github-dir/public 'git@github.com:cgitize-test/public.git'
- verify_origin bitbucket-dir/public 'git@bitbucket.org:cgitize-test-workspace/public.git'
- verify_origin gitlab-dir/public 'git@gitlab.com:cgitize-test/public.git'
-
- cleanup
- success
-}
-
-test_ssh_private() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_ssh
- setup_private_repos
- cgitize
-
- verify_repos \
- lens \
- chromiumembedded/cef \
- graphviz \
- wireguard/wintun \
- goauthentik-dir/authentik \
- github-dir/public \
- github-dir/private \
- bitbucket-dir/public \
- bitbucket-dir/private \
- gitlab-dir/public \
- gitlab-dir/private
-
- verify_origin lens 'git@github.com:ekmett/lens.git'
- verify_origin chromiumembedded/cef 'git@bitbucket.org:chromiumembedded/cef.git'
- verify_origin graphviz 'git@gitlab.com:graphviz/graphviz.git'
- verify_origin goauthentik-dir/authentik 'git@github.com:goauthentik/authentik.git'
-
- verify_origin github-dir/public 'git@github.com:cgitize-test/public.git'
- verify_origin github-dir/private 'git@github.com:cgitize-test/private.git'
- verify_origin bitbucket-dir/public 'git@bitbucket.org:cgitize-test-workspace/public.git'
- verify_origin bitbucket-dir/private 'git@bitbucket.org:cgitize-test-workspace/private.git'
- verify_origin gitlab-dir/public 'git@gitlab.com:cgitize-test/public.git'
- verify_origin gitlab-dir/private 'git@gitlab.com:cgitize-test/private.git'
-
- cleanup
- success
-}
-
-test_https() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_https
- cgitize
-
- verify_repos \
- lens \
- chromiumembedded/cef \
- graphviz \
- wireguard/wintun \
- goauthentik-dir/authentik \
- github-dir/public \
- bitbucket-dir/public \
- gitlab-dir/public
-
- verify_no_repos \
- github-dir/private \
- bitbucket-dir/private \
- gitlab-dir/private
-
- verify_origin lens 'https://github.com/ekmett/lens.git'
- verify_origin chromiumembedded/cef 'https://bitbucket.org/chromiumembedded/cef.git'
- verify_origin graphviz 'https://gitlab.com/graphviz/graphviz.git'
- verify_origin goauthentik-dir/authentik 'https://github.com/goauthentik/authentik.git'
-
- verify_origin github-dir/public 'https://github.com/cgitize-test/public.git'
- verify_origin bitbucket-dir/public 'https://bitbucket.org/cgitize-test-workspace/public.git'
- verify_origin gitlab-dir/public 'https://gitlab.com/cgitize-test/public.git'
-
- cleanup
- success
-}
-
-test_https_private() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_https
- setup_private_repos
- cgitize
-
- verify_repos \
- lens \
- chromiumembedded/cef \
- graphviz \
- wireguard/wintun \
- goauthentik-dir/authentik \
- github-dir/public \
- github-dir/private \
- bitbucket-dir/public \
- bitbucket-dir/private \
- gitlab-dir/public \
- gitlab-dir/private
-
- verify_origin lens 'https://github.com/ekmett/lens.git'
- verify_origin chromiumembedded/cef 'https://bitbucket.org/chromiumembedded/cef.git'
- verify_origin graphviz 'https://gitlab.com/graphviz/graphviz.git'
- verify_origin goauthentik-dir/authentik 'https://github.com/goauthentik/authentik.git'
-
- verify_origin github-dir/public 'https://github.com/cgitize-test/public.git'
- verify_origin github-dir/private 'https://github.com/cgitize-test/private.git'
- verify_origin bitbucket-dir/public 'https://bitbucket.org/cgitize-test-workspace/public.git'
- verify_origin bitbucket-dir/private 'https://bitbucket.org/cgitize-test-workspace/private.git'
- verify_origin gitlab-dir/public 'https://gitlab.com/cgitize-test/public.git'
- verify_origin gitlab-dir/private 'https://gitlab.com/cgitize-test/private.git'
-
- cleanup
- success
-}
-
-test_one_repo() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_https
- cgitize --repo cef
- verify_repos chromiumembedded/cef
- verify_no_repos lens wireguard/wintun
- cleanup
- success
-}
-
-main() {
- trap cleanup EXIT
- test_ssh
- test_ssh_private
- test_https
- test_https_private
- test_one_repo
-}
-
-main
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/'
+}
diff --git a/test/integration/local/test.sh b/test/integration/local/test.sh
deleted file mode 100755
index 04208ab..0000000
--- a/test/integration/local/test.sh
+++ /dev/null
@@ -1,244 +0,0 @@
-#!/usr/bin/env bash
-
-set -o errexit -o nounset -o pipefail
-shopt -s inherit_errexit lastpipe
-
-script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
-script_dir="$( cd -- "$script_dir" && pwd )"
-readonly script_dir
-
-upstream_repo_dir=
-readonly etc_dir="$script_dir/etc"
-readonly cgitize_toml_path="$etc_dir/cgitize.toml"
-readonly output_dir="$script_dir/output"
-
-readonly git_name='John Doe'
-readonly git_email='John.Doe@example.com'
-readonly git_default_branch=main
-
-_git() {
- git -c "user.name=$git_name" \
- -c "user.email=$git_email" \
- -c "init.defaultBranch=$git_default_branch" \
- "$@"
-}
-
-success() {
- echo
- echo ----------------------------------------------------------------------
- echo "SUCCESS: ${FUNCNAME[1]}"
- echo ----------------------------------------------------------------------
-}
-
-cleanup() {
- echo
- echo ----------------------------------------------------------------------
- echo Cleaning up
- echo ----------------------------------------------------------------------
-
- echo "Removing upstream repository directory: $upstream_repo_dir"
- rm -rf -- "$upstream_repo_dir"
- echo "Removing etc directory: $etc_dir"
- rm -rf -- "$etc_dir"
- echo "Removing output directory: $output_dir"
- rm -rf -- "$output_dir"
-}
-
-setup_upstream_repo() {
- echo
- echo ----------------------------------------------------------------------
- echo Setting up upstream repository
- echo ----------------------------------------------------------------------
-
- upstream_repo_dir="$( mktemp -d )"
- pushd -- "$upstream_repo_dir" > /dev/null
-
- _git init
- echo '1' > 1.txt
- _git add .
- _git commit -m 'first commit'
- echo '2' > 2.txt
- _git add .
- _git commit -m 'second commit'
-
- popd > /dev/null
-}
-
-add_commits() {
- echo
- echo ----------------------------------------------------------------------
- echo Adding new commits
- echo ----------------------------------------------------------------------
-
- pushd -- "$upstream_repo_dir" > /dev/null
-
- echo '3' > 3.txt
- _git add .
- _git commit -m 'third commit'
-
- popd > /dev/null
-}
-
-setup_cgitize_toml() {
- echo
- echo ----------------------------------------------------------------------
- echo cgitize.toml
- echo ----------------------------------------------------------------------
-
- local conf_dir
- conf_dir="$( dirname -- "$cgitize_toml_path" )"
- mkdir -p -- "$conf_dir"
-
- cat <<EOF | tee "$cgitize_toml_path"
-output_dir = "$output_dir"
-
-[repositories.test_repo]
-name = "test_repo"
-clone_url = "$upstream_repo_dir"
-EOF
-}
-
-setup_cgitize() {
- setup_cgitize_toml
-}
-
-setup_bare() {
- setup_upstream_repo
- setup_cgitize
-}
-
-cgitize() {
- echo
- echo ----------------------------------------------------------------------
- echo Running cgitize
- echo ----------------------------------------------------------------------
-
- python3 -m cgitize.main --config "$cgitize_toml_path" --verbose
-}
-
-check_contains() {
- if [ "$#" -lt 1 ]; then
- echo "usage: ${FUNCNAME[0]} TEST_STRING [PATTERN...]" >&2
- return 1
- fi
-
- local test_string="$1"
- shift
-
- local pattern
- for pattern; do
- # Be careful to _not_ use grep -q, since this fucks stuff up:
- # https://mywiki.wooledge.org/BashPitfalls#pipefail.
- if ! echo "$test_string" | grep --fixed-strings -- "$pattern" > /dev/null; then
- echo "${FUNCNAME[0]}: couldn't find the following pattern: $pattern" >&2
- return 1
- fi
- done
-}
-
-verify_commits() {
- # This is fucking stupid, but otherwise stuff like `if verify_commits;`
- # doesn't work: https://stackoverflow.com/q/4072984/514684
- # TODO: figure this out?
- pushd -- "$output_dir" > /dev/null &&
- cd -- test_repo.git &&
- local output &&
- output="$( _git log --oneline )" &&
- echo "$output" &&
- check_contains "$output" "$@" &&
- popd > /dev/null
-}
-
-verify_initial_commits() {
- echo
- echo ----------------------------------------------------------------------
- echo Checking the initial commits
- echo ----------------------------------------------------------------------
-
- verify_commits 'first commit' 'second commit'
-}
-
-verify_added_commits() {
- echo
- echo ----------------------------------------------------------------------
- echo Checking the added commits
- echo ----------------------------------------------------------------------
-
- verify_commits 'first commit' 'second commit' 'third commit'
-}
-
-verify_error_header_empty() {
- echo
- echo ----------------------------------------------------------------------
- echo Verifying the error header
- echo ----------------------------------------------------------------------
-
- test ! -s "$output_dir/error.html"
-}
-
-verify_error_header() {
- echo
- echo ----------------------------------------------------------------------
- echo Verifying the error header
- echo ----------------------------------------------------------------------
-
- local contents
- contents="$( cat -- "$output_dir/error.html" )"
- check_contains "$contents" "Some repositories couldn't be updated"
-}
-
-test_bare() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_bare
- cgitize
- verify_initial_commits
- add_commits
- cgitize
- verify_added_commits
- verify_error_header_empty
- cleanup
- success
-}
-
-test_failure() {
- echo
- echo ======================================================================
- echo "${FUNCNAME[0]}"
- echo ======================================================================
-
- setup_bare
- cgitize
- verify_initial_commits
- add_commits
-
- echo
- echo ----------------------------------------------------------------------
- echo Removing upstream repository
- echo ----------------------------------------------------------------------
- rm -rf -- "$upstream_repo_dir"
-
- if cgitize; then
- echo "cgitize should have failed to pull the upstream repository." >&2
- return 1
- fi
- verify_initial_commits
- if verify_added_commits; then
- echo "The added commits should not have been pulled." >&2
- return 1
- fi
- verify_error_header
- cleanup
- success
-}
-
-main() {
- trap cleanup EXIT
- test_bare
- test_failure
-}
-
-main
diff --git a/test/integration/runner b/test/integration/runner
new file mode 160000
+Subproject 882b380fe94ef7670c7aa13aa4435351e05acbf
diff --git a/test/integration/tst-basic-error.sh b/test/integration/tst-basic-error.sh
new file mode 100644
index 0000000..8abc42e
--- /dev/null
+++ b/test/integration/tst-basic-error.sh
@@ -0,0 +1,21 @@
+test_run() {
+ test_basic_setup
+ test_run_cgitize --verbose
+ test_basic_verify_commits \
+ 'committing 1.txt' \
+ 'committing 2.txt'
+
+ # Add new commits
+ test_basic_make_commit
+ test_basic_make_commit
+
+ rm -rf -- "$test_repo_dir"
+
+ # Must fail to pick up new commits
+ test_run_cgitize --verbose || true
+ test_basic_verify_commits \
+ 'committing 1.txt' \
+ 'committing 2.txt'
+
+ test_verify_error_header
+}
diff --git a/test/integration/tst-basic.sh b/test/integration/tst-basic.sh
new file mode 100644
index 0000000..5cc4566
--- /dev/null
+++ b/test/integration/tst-basic.sh
@@ -0,0 +1,21 @@
+test_run() {
+ test_basic_setup
+ test_run_cgitize --verbose
+ test_basic_verify_commits \
+ 'committing 1.txt' \
+ 'committing 2.txt'
+
+ # Add new commits
+ test_basic_make_commit
+ test_basic_make_commit
+
+ # Pick up new commits
+ test_run_cgitize --verbose
+ test_basic_verify_commits \
+ 'committing 1.txt' \
+ 'committing 2.txt' \
+ 'committing 3.txt' \
+ 'committing 4.txt'
+
+ test_verify_error_header_empty
+}
diff --git a/test/integration/tst-example-https-private.sh b/test/integration/tst-example-https-private.sh
new file mode 100644
index 0000000..8c41733
--- /dev/null
+++ b/test/integration/tst-example-https-private.sh
@@ -0,0 +1,33 @@
+test_run() {
+ test_example_setup
+ test_example_clone_https
+ test_example_private_include
+
+ test_run_cgitize
+ test_verify_error_header_empty
+
+ test_verify_repos \
+ lens \
+ chromiumembedded/cef \
+ graphviz \
+ wireguard/wintun \
+ goauthentik-dir/authentik \
+ github-dir/public \
+ github-dir/private \
+ bitbucket-dir/public \
+ bitbucket-dir/private \
+ gitlab-dir/public \
+ gitlab-dir/private
+
+ test_verify_origin lens 'https://github.com/ekmett/lens.git'
+ test_verify_origin chromiumembedded/cef 'https://bitbucket.org/chromiumembedded/cef.git'
+ test_verify_origin graphviz 'https://gitlab.com/graphviz/graphviz.git'
+ test_verify_origin goauthentik-dir/authentik 'https://github.com/goauthentik/authentik.git'
+
+ test_verify_origin github-dir/public 'https://github.com/cgitize-test/public.git'
+ test_verify_origin github-dir/private 'https://github.com/cgitize-test/private.git'
+ test_verify_origin bitbucket-dir/public 'https://bitbucket.org/cgitize-test-workspace/public.git'
+ test_verify_origin bitbucket-dir/private 'https://bitbucket.org/cgitize-test-workspace/private.git'
+ test_verify_origin gitlab-dir/public 'https://gitlab.com/cgitize-test/public.git'
+ test_verify_origin gitlab-dir/private 'https://gitlab.com/cgitize-test/private.git'
+}
diff --git a/test/integration/tst-example-https.sh b/test/integration/tst-example-https.sh
new file mode 100644
index 0000000..495d54e
--- /dev/null
+++ b/test/integration/tst-example-https.sh
@@ -0,0 +1,31 @@
+test_run() {
+ test_example_setup
+ test_example_clone_https
+
+ test_run_cgitize
+ test_verify_error_header_empty
+
+ test_verify_repos \
+ lens \
+ chromiumembedded/cef \
+ graphviz \
+ wireguard/wintun \
+ goauthentik-dir/authentik \
+ github-dir/public \
+ bitbucket-dir/public \
+ gitlab-dir/public
+
+ test_verify_no_repos \
+ github-dir/private \
+ bitbucket-dir/private \
+ gitlab-dir/private
+
+ test_verify_origin lens 'https://github.com/ekmett/lens.git'
+ test_verify_origin chromiumembedded/cef 'https://bitbucket.org/chromiumembedded/cef.git'
+ test_verify_origin graphviz 'https://gitlab.com/graphviz/graphviz.git'
+ test_verify_origin goauthentik-dir/authentik 'https://github.com/goauthentik/authentik.git'
+
+ test_verify_origin github-dir/public 'https://github.com/cgitize-test/public.git'
+ test_verify_origin bitbucket-dir/public 'https://bitbucket.org/cgitize-test-workspace/public.git'
+ test_verify_origin gitlab-dir/public 'https://gitlab.com/cgitize-test/public.git'
+}
diff --git a/test/integration/tst-example-one-repo.sh b/test/integration/tst-example-one-repo.sh
new file mode 100644
index 0000000..0dde691
--- /dev/null
+++ b/test/integration/tst-example-one-repo.sh
@@ -0,0 +1,10 @@
+test_run() {
+ test_example_setup
+ test_example_clone_https
+
+ test_run_cgitize --repo cef
+ test_verify_error_header_empty
+
+ test_verify_repos chromiumembedded/cef
+ test_verify_no_repos lens wireguard/wintun
+}
diff --git a/test/integration/tst-example-ssh-private.sh b/test/integration/tst-example-ssh-private.sh
new file mode 100644
index 0000000..016d0da
--- /dev/null
+++ b/test/integration/tst-example-ssh-private.sh
@@ -0,0 +1,33 @@
+test_run() {
+ test_example_setup
+ test_example_clone_ssh
+ test_example_private_include
+
+ test_run_cgitize
+ test_verify_error_header_empty
+
+ test_verify_repos \
+ lens \
+ chromiumembedded/cef \
+ graphviz \
+ wireguard/wintun \
+ goauthentik-dir/authentik \
+ github-dir/public \
+ github-dir/private \
+ bitbucket-dir/public \
+ bitbucket-dir/private \
+ gitlab-dir/public \
+ gitlab-dir/private
+
+ test_verify_origin lens 'git@github.com:ekmett/lens.git'
+ test_verify_origin chromiumembedded/cef 'git@bitbucket.org:chromiumembedded/cef.git'
+ test_verify_origin graphviz 'git@gitlab.com:graphviz/graphviz.git'
+ test_verify_origin goauthentik-dir/authentik 'git@github.com:goauthentik/authentik.git'
+
+ test_verify_origin github-dir/public 'git@github.com:cgitize-test/public.git'
+ test_verify_origin github-dir/private 'git@github.com:cgitize-test/private.git'
+ test_verify_origin bitbucket-dir/public 'git@bitbucket.org:cgitize-test-workspace/public.git'
+ test_verify_origin bitbucket-dir/private 'git@bitbucket.org:cgitize-test-workspace/private.git'
+ test_verify_origin gitlab-dir/public 'git@gitlab.com:cgitize-test/public.git'
+ test_verify_origin gitlab-dir/private 'git@gitlab.com:cgitize-test/private.git'
+}
diff --git a/test/integration/tst-example-ssh.sh b/test/integration/tst-example-ssh.sh
new file mode 100644
index 0000000..af99616
--- /dev/null
+++ b/test/integration/tst-example-ssh.sh
@@ -0,0 +1,31 @@
+test_run() {
+ test_example_setup
+ test_example_clone_ssh
+
+ test_run_cgitize
+ test_verify_error_header_empty
+
+ test_verify_repos \
+ lens \
+ chromiumembedded/cef \
+ graphviz \
+ wireguard/wintun \
+ goauthentik-dir/authentik \
+ github-dir/public \
+ bitbucket-dir/public \
+ gitlab-dir/public
+
+ test_verify_no_repos \
+ github-dir/private \
+ bitbucket-dir/private \
+ gitlab-dir/private
+
+ test_verify_origin lens 'git@github.com:ekmett/lens.git'
+ test_verify_origin chromiumembedded/cef 'git@bitbucket.org:chromiumembedded/cef.git'
+ test_verify_origin graphviz 'git@gitlab.com:graphviz/graphviz.git'
+ test_verify_origin goauthentik-dir/authentik 'git@github.com:goauthentik/authentik.git'
+
+ test_verify_origin github-dir/public 'git@github.com:cgitize-test/public.git'
+ test_verify_origin bitbucket-dir/public 'git@bitbucket.org:cgitize-test-workspace/public.git'
+ test_verify_origin gitlab-dir/public 'git@gitlab.com:cgitize-test/public.git'
+}