99set -eu
1010
1111HERE=$( CDPATH= cd -- " $( dirname -- " $0 " ) " && pwd)
12+ . " $HERE /lib.sh"
13+
1214SNIPPET=" $HERE /../migrate-apt-source.sh"
13- [ -f " $SNIPPET " ] || { echo " FAIL: $SNIPPET missing" ; exit 1 ; }
15+ assert_file " $SNIPPET " " $SNIPPET missing"
1416
1517WORK=$( mktemp -d)
1618trap ' rm -rf "$WORK"' EXIT
1719
18- fail () { echo " FAIL: $1 " ; exit 1; }
19-
2020# --- Case A: rewrite (AC#6) --------------------------------------------------
2121# A deb822 .sources naming the old kolibri-server host, plus a legacy one-line
2222# .list naming the old kolibri-installer-debian host. Both must move to the
3636
3737KOLIBRI_APT_SOURCES_DIR=" $A " sh " $SNIPPET "
3838
39- grep -q ' apt.learningequality.org' " $A /learningequality-kolibri-server.sources" \
40- || fail " Case A: .sources not rewritten to apt.learningequality.org"
41- grep -q ' apt.learningequality.org' " $A /learningequality-debian.list" \
42- || fail " Case A: .list not rewritten to apt.learningequality.org"
43- if grep -rq ' learningequality\.github\.io' " $A " ; then
44- fail " Case A: a github.io host survived the rewrite"
45- fi
39+ assert_contains " $A /learningequality-kolibri-server.sources" ' apt\.learningequality\.org' \
40+ " Case A: .sources not rewritten to apt.learningequality.org"
41+ assert_contains " $A /learningequality-debian.list" ' apt\.learningequality\.org' \
42+ " Case A: .list not rewritten to apt.learningequality.org"
43+ assert_absent " $A " ' learningequality\.github\.io' \
44+ " Case A: a github.io host survived the rewrite"
4645
4746# --- Case B: no-op (AC#7) ----------------------------------------------------
4847# A Launchpad-PPA source has no github.io host — the file must be byte-unchanged.
@@ -55,24 +54,24 @@ cp "$B/learningequality-ubuntu-kolibri.list" "$WORK/case_b_orig.list"
5554
5655KOLIBRI_APT_SOURCES_DIR=" $B " sh " $SNIPPET "
5756
58- cmp -s " $B /learningequality-ubuntu-kolibri.list" " $WORK /case_b_orig.list" \
59- || fail " Case B: Launchpad PPA source was modified (should be no-op)"
57+ assert_files_equal " $B /learningequality-ubuntu-kolibri.list" " $WORK /case_b_orig.list" \
58+ " Case B: Launchpad PPA source was modified (should be no-op)"
6059
6160# --- Case C: idempotent ------------------------------------------------------
6261# A second run over Case A's already-rewritten fixture changes nothing.
6362cp -a " $A " " $WORK /case_c"
6463C=" $WORK /case_c"
6564snapshot=$( cat " $C " /* )
6665KOLIBRI_APT_SOURCES_DIR=" $C " sh " $SNIPPET "
67- [ " $snapshot " = " $ ( cat " $C " /* ) " ] \
68- || fail " Case C: second run mutated an already-rewritten fixture"
66+ assert_equals " $( cat " $C " /* ) " " $snapshot " \
67+ " Case C: second run mutated an already-rewritten fixture"
6968
7069# --- Case D: sourced under `set -e`, no match, must not abort (AC#7 path) -----
7170# The postinst sources the snippet and calls the function under `set -e`; on a
7271# no-match install grep exits 1 — that must not abort. Mimic the integration.
7372KOLIBRI_APT_SOURCES_DIR=" $B " sh -e -c " . '$SNIPPET '; migrate_kolibri_apt_source; echo OK" \
7473 > " $WORK /case_d.out" 2>&1 || fail " Case D: aborted under set -e on no-match"
75- grep -qx ' OK ' " $WORK /case_d.out" \
76- || fail " Case D: did not reach OK (sourced call aborted under set -e)"
74+ assert_contains " $WORK /case_d.out" ' ^OK$ ' \
75+ " Case D: did not reach OK (sourced call aborted under set -e)"
7776
7877echo " PASS: rewrite, no-op, idempotent, and set -e no-match all green"
0 commit comments