summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authortranch <tranch.xiao@gmail.com>2026-11-18 08:11:29 +0800
committertranch <tranch.xiao@gmail.com>2026-11-18 08:11:29 +0800
commitde9a4f9275afccbaf0b18d1b8e18a17e3070102f (patch)
treee567cd49c63b17c7809b19117d69889ca4f3c4eb /tests
parent977a1e6fb81dfc264fa1e5d87652a37508fedaf8 (diff)
parent95702ac4933104a7e3b6c512982fdf9334409379 (diff)
downloadAeroCore-OS-de9a4f9275afccbaf0b18d1b8e18a17e3070102f.tar.gz
AeroCore-OS-de9a4f9275afccbaf0b18d1b8e18a17e3070102f.zip
Merge testing-45.20261117 into main45.20261118
* testing: ci: add scheduled GHCR image cleanup build: align testing with Bazzite 45.20261117 Update existing Flatpak remotes at boot Make Flatpak mirror setup resilient
Diffstat (limited to 'tests')
-rw-r--r--tests/test-flatpak-mirror-build-config.sh68
-rwxr-xr-xtests/test-flatpak-runtime-mirror.sh62
2 files changed, 130 insertions, 0 deletions
diff --git a/tests/test-flatpak-mirror-build-config.sh b/tests/test-flatpak-mirror-build-config.sh
new file mode 100644
index 0000000..1b661bd
--- /dev/null
+++ b/tests/test-flatpak-mirror-build-config.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+build_script="${project_root}/build_files/build.sh"
+test_root="$(mktemp -d)"
+trap 'rm -rf "${test_root}"' EXIT
+
+mirror_function="${test_root}/configure-mirrors.sh"
+sed -n '/^configure_mirrors() {/,/^}$/p' "${build_script}" > "${mirror_function}"
+source "${mirror_function}"
+
+assert_eq() {
+ local expected="$1" actual="$2" message="$3"
+ if [[ "${expected}" != "${actual}" ]]; then
+ printf 'FAIL: %s\nexpected: <%s>\nactual: <%s>\n' "${message}" "${expected}" "${actual}" >&2
+ exit 1
+ fi
+}
+
+run_case() {
+ local name="$1" helper_mode="$2" repo_mode="$3"
+ local case_root="${test_root}/${name}"
+ mkdir -p "${case_root}/etc/environment.d" "${case_root}/skel/.config/environment.d" "${case_root}/etc/flatpak/remotes.d" "${case_root}/usr/libexec"
+ export TEST_ROOT="${case_root}"
+ export FLATPAK_REMOTE_URL='https://mirror.example/flathub'
+ unset HOMEBREW_BOTTLE_DOMAIN HOMEBREW_API_DOMAIN
+
+ if [[ "${helper_mode}" != missing ]]; then
+ cat > "${case_root}/usr/libexec/bazzite-mirror-utils.sh" <<'HELPER'
+#!/usr/bin/env bash
+[[ "${HELPER_MODE}" == fail ]] && exit 1
+awk -v url="${2%/}/" 'BEGIN{updated=0} /^Url=/{print "Url=" url;updated=1;next} {print} END{if(!updated)print "Url=" url}' "${TEST_ROOT}/etc/flatpak/remotes.d/flathub.flatpakrepo" > "${TEST_ROOT}/repo.tmp" && mv "${TEST_ROOT}/repo.tmp" "${TEST_ROOT}/etc/flatpak/remotes.d/flathub.flatpakrepo"
+HELPER
+ chmod +x "${case_root}/usr/libexec/bazzite-mirror-utils.sh"
+ fi
+
+ printf '[Flatpak Repo]\nTitle=Flathub\nUrl=https://dl.flathub.org/repo/\nHomepage=https://flathub.org/\n' > "${case_root}/etc/flatpak/remotes.d/flathub.flatpakrepo"
+ if [[ "${repo_mode}" == readonly ]]; then chmod 0444 "${case_root}/etc/flatpak/remotes.d/flathub.flatpakrepo"; fi
+
+ # Relocate production paths into an isolated fixture, then execute the
+ # extracted production function directly.
+ export HELPER_MODE="${helper_mode}"
+ sed -e "s|/etc/environment.d|${case_root}/etc/environment.d|g" \
+ -e "s|/etc/skel|${case_root}/skel|g" \
+ -e "s|/usr/libexec|${case_root}/usr/libexec|g" \
+ -e "s|/etc/flatpak|${case_root}/etc/flatpak|g" \
+ "${mirror_function}" > "${case_root}/configure-mirrors.sh"
+ source "${case_root}/configure-mirrors.sh"
+ configure_mirrors
+
+ local actual_url
+ actual_url="$(sed -n 's/^Url=//p' "${case_root}/etc/flatpak/remotes.d/flathub.flatpakrepo")"
+ if [[ "${helper_mode}" == success || ( "${repo_mode}" == writable && "${helper_mode}" != success ) ]]; then
+ assert_eq 'https://mirror.example/flathub/' "${actual_url}" "${name}: configured mirror URL"
+ else
+ assert_eq 'https://dl.flathub.org/repo/' "${actual_url}" "${name}: retain original URL when no write path exists"
+ fi
+ assert_eq 'FLATPAK_REMOTE_URL=https://mirror.example/flathub' "$(cat "${case_root}/etc/environment.d/99-aerocore-mirrors.conf")" "${name}: persist environment setting"
+}
+
+run_case helper_success success writable
+run_case helper_failure fail writable
+run_case helper_missing missing writable
+run_case no_write_path fail readonly
+
+echo "Flatpak mirror behavior checks passed."
diff --git a/tests/test-flatpak-runtime-mirror.sh b/tests/test-flatpak-runtime-mirror.sh
new file mode 100755
index 0000000..bd0fc86
--- /dev/null
+++ b/tests/test-flatpak-runtime-mirror.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+source_script="${project_root}/system_files/usr/libexec/aerocore-configure-flatpak-mirror"
+test_root="$(mktemp -d)"
+trap 'rm -rf "${test_root}"' EXIT
+
+assert_eq() {
+ local expected="$1" actual="$2" message="$3"
+ if [[ "${expected}" != "${actual}" ]]; then
+ printf 'FAIL: %s\nexpected: <%s>\nactual: <%s>\n' "${message}" "${expected}" "${actual}" >&2
+ exit 1
+ fi
+}
+
+run_case() {
+ local name="$1" exists="$2" url="$3"
+ local root="${test_root}/${name}"
+ mkdir -p "${root}/etc/environment.d" "${root}/etc/flatpak/remotes.d" "${root}/usr/bin"
+ printf 'FLATPAK_REMOTE_URL=%s\n' "${url}" > "${root}/etc/environment.d/99-aerocore-mirrors.conf"
+ : > "${root}/etc/flatpak/remotes.d/flathub.flatpakrepo"
+ printf '%s\n' "${exists}" > "${root}/remote-exists"
+ : > "${root}/flatpak.calls"
+
+ cat > "${root}/usr/bin/flatpak" <<'FLATPAK'
+#!/usr/bin/env bash
+printf '%s\n' "$*" >> "${TEST_ROOT}/flatpak.calls"
+if [[ "$1 $2 $3" == 'remotes --system --columns=name' ]]; then
+ [[ "$(cat "${TEST_ROOT}/remote-exists")" == true ]] && echo flathub
+fi
+if [[ "$1 $2 $3" == 'remote-add --system --if-not-exists' ]]; then
+ printf true > "${TEST_ROOT}/remote-exists"
+fi
+FLATPAK
+ chmod +x "${root}/usr/bin/flatpak"
+
+ sed -e "s|/etc/environment.d|${root}/etc/environment.d|g" \
+ -e "s|/etc/flatpak|${root}/etc/flatpak|g" \
+ "${source_script}" > "${root}/configure-mirror"
+ chmod +x "${root}/configure-mirror"
+ export TEST_ROOT="${root}" PATH="${root}/usr/bin:${PATH}"
+ bash "${root}/configure-mirror"
+ cat "${root}/flatpak.calls" > "${root}/calls.actual"
+}
+
+run_case existing_remote true https://mirror.example/flathub
+assert_eq 'remotes --system --columns=name
+remote-modify --system flathub --url=https://mirror.example/flathub/' "$(cat "${test_root}/existing_remote/calls.actual")" 'existing remote is updated'
+
+run_case missing_remote false https://mirror.example/flathub/
+expected_missing_calls="$(printf 'remotes --system --columns=name\nremote-add --system --if-not-exists flathub %s\nremote-modify --system flathub --url=https://mirror.example/flathub/' "${test_root}/missing_remote/etc/flatpak/remotes.d/flathub.flatpakrepo")"
+assert_eq "${expected_missing_calls}" "$(cat "${test_root}/missing_remote/calls.actual")" 'missing remote is added then updated'
+
+run_case empty_url true ''
+assert_eq '' "$(cat "${test_root}/empty_url/calls.actual")" 'empty setting leaves remotes unchanged'
+
+run_case invalid_url true 'not-a-url'
+assert_eq '' "$(cat "${test_root}/invalid_url/calls.actual")" 'invalid setting leaves remotes unchanged'
+
+echo "Flatpak runtime mirror behavior checks passed."