chiark / gitweb /
Mirroring: Tests: Break out various functions (nfc overall)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 11 Jul 2015 12:57:59 +0000 (13:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 11 Jul 2015 13:24:39 +0000 (14:24 +0100)
tests/lib
tests/lib-mirror [new file with mode: 0644]
tests/tests/mirror

index 469b8fc2cf97f15e2f92ee37b5da816f91b22af5..1179fb093f8ed48535c60a5eaaf52fc7ae9de481 100644 (file)
--- a/tests/lib
+++ b/tests/lib
@@ -436,6 +436,16 @@ t-pushed-good () {
        git verify-tag `t-v-tag`
 }
 
+t-commit-build-push-expect-log () {
+       local msg=$1
+       local mpat=$2
+       t-commit "$msg"
+       t-dgit build
+       LC_MESSAGES=C \
+       t-dgit push --new 2>&1 |tee $tmp/push.log
+       t-grep-mpat "$mpat" $tmp/push.log
+}
+
 t-822-field () {
        local file=$1
        local field=$2
diff --git a/tests/lib-mirror b/tests/lib-mirror
new file mode 100644 (file)
index 0000000..c84c30c
--- /dev/null
@@ -0,0 +1,40 @@
+
+t-mirror-setup () {
+       # p must be set already
+
+       reposmirror=$tmp/git-mirror
+       pmirror=$reposmirror/$p.git
+       queuedir=$tmp/git/_mirror-queue
+
+       mkdir $reposmirror
+
+       mirror_hook=$drs_dispatch/mirror-hook
+       ln -sf ${DGIT_INFRA_PFX}dgit-mirror-rsync $mirror_hook
+
+       >$drs_dispatch/mirror-settings
+       t-mirror-set remoterepos="$reposmirror"
+
+       t-mirror-hook setup
+}
+
+t-mirror-set () {
+       echo >>$drs_dispatch/mirror-settings "$1"
+}
+
+t-mirror-hook () {
+       "$mirror_hook" "$drs_dispatch" "$@"
+}
+
+t-check-mirrored () {
+       t-reporefs master
+       t-reporefs mirror $pmirror
+       diff $tmp/show-refs.{master,mirror}
+       cat $queuedir/$p.log
+       t-files-notexist $queuedir/$p.{n,a,lock,err}
+}
+
+t-check-not-mirrored () {
+       # uses previous t-reporefs-master
+       t-reporefs mirror $pmirror
+       diff $tmp/show-refs.{master,mirror}
+}
index 431b391714828b3f64b514029f14e6515d78468f..6f6300e298456e026a8fc5f16c75b4e3bb77a5db 100755 (executable)
@@ -1,65 +1,23 @@
 #!/bin/bash
 set -e
 . tests/lib
+. $troot/lib-mirror
 
 t-drs
 
-: ---- "setup up the mirror hook in a basic way" ----
-
-reposmirror=$tmp/git-mirror
-queuedir=$tmp/git/_mirror-queue
-mkdir $reposmirror
-
-mhook=$drs_dispatch/mirror-hook
-ln -sf ${DGIT_INFRA_PFX}dgit-mirror-rsync $mhook
-mhook () {
-       "$mhook" "$drs_dispatch" "$@"
-}
-
->$drs_dispatch/mirror-settings
-mset () { echo >>$drs_dispatch/mirror-settings "$1"; }
-
-mset remoterepos="$reposmirror"
-
-commit-build-push-expect-log () {
-       local msg=$1
-       local mpat=$2
-       t-commit "$msg"
-       t-dgit build
-       LC_MESSAGES=C \
-       t-dgit push --new 2>&1 |tee $tmp/push.log
-       t-grep-mpat "$mpat" $tmp/push.log
-}
-
-check-mirrored () {
-       t-reporefs master
-       t-reporefs mirror $pmirror
-       diff $tmp/show-refs.{master,mirror}
-       cat $queuedir/$p.log
-       t-files-notexist $queuedir/$p.{n,a,lock,err}
-}
-
-check-not-mirrored () {
-       # uses previous t-reporefs-master
-       t-reporefs mirror $pmirror
-       diff $tmp/show-refs.{master,mirror}
-}
-
 : ---- "basic test" ----
 
 t-tstunt-parsechangelog
 t-prep-newpackage example 1.0
 
-pmirror=$reposmirror/$p.git
-mhook setup
+t-mirror-setup
 
 cd $p
 revision=1
 t-dgit build
 t-dgit push --new
 
-check-mirrored
-
+t-check-mirrored
 
 : ---- "stunt ssh test" ----
 
@@ -77,38 +35,38 @@ date >${sentinel}2
 END
 chmod +x $tmp/stunt-ssh
 
-mset rsyncssh=$tmp/stunt-ssh
-mset remoterepos=HOST:$reposmirror
+t-mirror-set rsyncssh=$tmp/stunt-ssh
+t-mirror-set remoterepos=HOST:$reposmirror
 
 # mirror should fail due to lack of stunt-ssh-sentinel
 
-commit-build-push-expect-log "stunt ssh test" \
+t-commit-build-push-expect-log "stunt ssh test" \
        E:'mirror hook failed: .*exited'
 
 ls -al $queuedir/$p.a
-check-not-mirrored
+t-check-not-mirrored
 
 touch $sentinel
 
-mhook backlog
-check-mirrored
+t-mirror-hook backlog
+t-check-mirrored
 
 : ----- "stall timeout test" -----
 
 rm -f $sentinel ${sentinel}2
 mkfifo $sentinel ${sentinel}2
 
-mset hooktimeout=5
+t-mirror-set hooktimeout=5
 
-commit-build-push-expect-log "stall timeout test" \
+t-commit-build-push-expect-log "stall timeout test" \
        E:'mirror hook failed: .*timeout'
 
-check-not-mirrored
+t-check-not-mirrored
 
 exec 3<>$sentinel
 exec 3>&-
 cat ${sentinel}2
 
-check-mirrored
+t-check-mirrored
 
 echo done.