summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2018-09-25 21:42:05 -0400
committerLuke Shumaker <lukeshu@parabola.nu>2018-09-26 12:41:13 -0400
commitf0caf3ba9cbbc9c80b7a9221348df9ff8bcdeeda (patch)
tree616a5848b3d42b44541eca709a05b7b14e15cb0b
parent4baff63b94d3921526884e5f16d70fdec815d711 (diff)
test: Pull common stuff out of 'db-import-pkg.bats' in to 'import.bash'
-rw-r--r--test/cases/db-import-pkg.bats194
-rw-r--r--test/lib/import.bash194
2 files changed, 195 insertions, 193 deletions
diff --git a/test/cases/db-import-pkg.bats b/test/cases/db-import-pkg.bats
index a493ff7..f973c84 100644
--- a/test/cases/db-import-pkg.bats
+++ b/test/cases/db-import-pkg.bats
@@ -1,126 +1,4 @@
-load ../lib/common
-
-httpserver() {
- read -r verb path version || exit
- if [[ $verb != GET ]]; then
- printf "HTTP/1.1 405 Method Not Allowed\\r\\nContent-Type: text/plain\\r\\nContent-length: 0\\r\\n\\r\\n"
- exit
- fi
- path="$(cd / && realpath -ms "$path")"
- if ! [[ -f "$1/$path" ]]; then
- printf "HTTP/1.1 404 Not found\\r\\nContent-Type: text/plain\\r\\nContent-length: 0\\r\\n\\r\\n"
- exit
- fi
- printf "HTTP/1.1 200 OK\\r\\nContent-Type: text/plain\\r\\nContent-length: %d\\r\\n\\r\\n" "$(stat -L -c %s "$1/$path")"
- cat "$1/$path"
-}
-
-eval "__common_$(declare -f setup)"
-setup() {
- __common_setup
- local repo arch
-
- # Set up rsync server
- cat <<-eot >"${TMP}/rsyncd.conf"
- use chroot = no
- [rsyncd]
- path = ${TMP}/rsyncd
- eot
- local rsyncport
- rsyncport=$(./lib/runserver "$TMP/rsyncd.pid" \
- rsync --daemon --config "${TMP}/rsyncd.conf")
-
- # Set up rsync contents
- for repo in core testing; do
- mkdir -p -- "${TMP}/rsyncd/archlinux/${repo}/os/x86_64"
- touch -- "${TMP}/rsyncd/archlinux/${repo}/os/x86_64/${repo}.db.tar.gz"
- ln -sT -- "${repo}.db.tar.gz" "${TMP}/rsyncd/archlinux/${repo}/os/x86_64/${repo}.db"
- done
- mkdir -p -- "${TMP}/rsyncd/archlinux"/{pool,sources}/{packages,community}
- date +%s > "${TMP}/rsyncd/archlinux/lastupdate"
- date +%s > "${TMP}/rsyncd/archlinux/lastsync"
-
- for repo in core testing community community-testing; do
- mkdir -p -- "${TMP}/rsyncd/archlinux32/i686/${repo}"
- touch -- "${TMP}/rsyncd/archlinux32/i686/${repo}/${repo}.db.tar.gz"
- ln -sT -- "${repo}.db.tar.gz" "${TMP}/rsyncd/archlinux32/i686/${repo}/${repo}.db"
- done
- mkdir -p -- "${TMP}/rsyncd/archlinux32/pool"
- date +%s > "${TMP}/rsyncd/archlinux32/lastupdate"
- date +%s > "${TMP}/rsyncd/archlinux32/lastsync"
-
- for repo in core testing community community-testing; do
- mkdir -p -- "${TMP}/rsyncd/archlinuxarm/armv7h/${repo}"
- touch -- "${TMP}/rsyncd/archlinuxarm/armv7h/${repo}/${repo}.db.tar.gz"
- ln -sT -- "${repo}.db.tar.gz" "${TMP}/rsyncd/archlinuxarm/armv7h/${repo}/${repo}.db"
- done
- date +%s > "${TMP}/rsyncd/archlinuxarm/lastupdate"
- date +%s > "${TMP}/rsyncd/archlinuxarm/lastsync"
-
- # Configure db-import to use that rsyncd server
- cat <<-eot >"${TMP}/config.local.packages"
- source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
- source ../config.local.packages
- ARCHTAGS=('core-x86_64' 'testing-x86_64')
- ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinux/
- eot
- cat <<-eot >"${TMP}/config.local.community"
- source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
- source ../config.local.community
- ARCHTAGS=('community-x86_64' 'community-testing-x86_64')
- ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinux/
- eot
- cat <<-eot >"${TMP}/config.local.archlinux32"
- source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
- source ../config.local.archlinux32
- ARCHTAGS=('core-i686' 'testing-i686' 'community-i686' 'community-testing-i686')
- ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinux32/
- eot
- cat <<-eot >"${TMP}/config.local.archlinuxarm"
- source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
- source ../config.local.archlinuxarm
- ARCHTAGS=('core-armv7h' 'testing-armv7h' 'community-armv7h' 'community-testing-armv7h')
- ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinuxarm/
- eot
-
- # Set up HTTP server
- local httpport
- httpport=$(./lib/runserver "$TMP/httpd.pid" \
- bash -c "$(declare -f httpserver); httpserver \"\$@\"" -- "$TMP/httpd")
-
- # Set up HTTP contents
- mkdir -- "$TMP/httpd"
- cat <<-eot >"$TMP/httpd/blacklist.txt"
- slavery:freedom:fsf:slavekit:Obviously
- eot
-
- # Configure db-import to use that HTTP server
- export XDG_CONFIG_HOME="${TMP}/home/.config"
- mkdir -p "$XDG_CONFIG_HOME"/libretools
- cat <<-eot >"$XDG_CONFIG_HOME"/libretools/libretools.conf
- BLACKLIST=http://localhost:${httpport@Q}/blacklist.txt
- eot
-
- # Set up repo contents
- for arch in x86_64 i686 armv7h; do
- for repo in core testing community community-testing; do
- mkdir -p -- "${TMP}/ftp/${repo}/os/${arch}"
- touch -- "${TMP}/ftp/${repo}/os/${arch}/${repo}.db.tar.gz"
- ln -sT -- "${repo}.db.tar.gz" "${TMP}/ftp/${repo}/os/${arch}/${repo}.db"
- done
- done
- mkdir -p -- "${TMP}/ftp"/{pool,sources}/{packages,community,archlinux32,alarm}
- date +%s > "${TMP}/ftp/lastupdate"
- date +%s > "${TMP}/ftp/lastsync"
-}
-eval "__common_$(declare -f teardown)"
-teardown() {
- xargs -a "${TMP}/httpd.pid" kill --
- xargs -a "${TMP}/rsyncd.pid" kill --
- __common_teardown
-}
-
-######################################################################
+load ../lib/import
# Run the command in a new mount namespace with /tmp remounted
# read-only, but with $TMP (which might be under /tmp) still writable.
@@ -148,76 +26,6 @@ __db-import-pkg() {
return $ret
}
-# __releaseImportedPackage PKGBASE ARCH DBFILE [POOLDIR]
-#
-# This is different from common.bash:releasePackage because
-# - it doesn't mess with VCS
-# - it adds the package to the .db file
-__releaseImportedPackage() {
- local pkgbase=$1
- local arch=$2
- local dbfile=$3
- local pooldir=$4
- local repodir="${dbfile%/*}"
- local dir restore pkgfiles pkgfile pkgs
-
- dir="$TMP/import-build/$pkgbase"
- if ! [[ -d "$dir" ]]; then
- mkdir -p -- "$dir"
- cp -t "$dir" -- "fixtures/${pkgbase}"/*
- fi
- pushd "$dir"
- __buildPackage
- restore="$(shopt -p nullglob || true)"
- shopt -s nullglob
- pkgfiles=(*-{"$arch",any}"$PKGEXT"{,.sig})
- $restore
- popd
-
- mkdir -p "$repodir"
- if [[ -z $pooldir ]]; then
- mv -t "$repodir" -- "${pkgfiles[@]/#/"$dir/"}"
- else
- mkdir -p "$pooldir"
- mv -t "$pooldir" -- "${pkgfiles[@]/#/"$dir/"}"
- ln -sr -t "$repodir" -- "${pkgfiles[@]/#/"$pooldir/"}"
- fi
-
- pushd "$repodir"
- pkgs=()
- for pkgfile in "${pkgfiles[@]}"; do
- if [[ "$pkgfile" = *.sig ]]; then
- continue
- fi
- pkgs+=("$pkgfile")
- done
- repo-add -q "${dbfile##*/}" "${pkgs[@]}"
- popd
-}
-
-__updateImportedPackage() {
- pushd "$TMP/import-build/$1"
- local pkgrel
- pkgrel=$(. PKGBUILD; expr ${pkgrel} + 1)
- sed "s/pkgrel=.*/pkgrel=${pkgrel}/" -i PKGBUILD
- popd
-}
-
-__isLinkTo() {
- [[ -L $1 ]]
- [[ $1 -ef $2 ]]
-}
-
-__doesNotExist() {
- local file
- for file in "$@"; do
- if stat "$file" 2>/dev/null; then
- echo "TEST ERROR: File shouldn't exist, but does: $file"
- return 1
- fi
- done
-}
-
######################################################################
@test "import no blacklisted packages (x86_64)" {
diff --git a/test/lib/import.bash b/test/lib/import.bash
new file mode 100644
index 0000000..726f4b9
--- /dev/null
+++ b/test/lib/import.bash
@@ -0,0 +1,194 @@
+#!/hint/bash
+. "lib/common.bash"
+
+httpserver() {
+ read -r verb path version || exit
+ if [[ $verb != GET ]]; then
+ printf "HTTP/1.1 405 Method Not Allowed\\r\\nContent-Type: text/plain\\r\\nContent-length: 0\\r\\n\\r\\n"
+ exit
+ fi
+ path="$(cd / && realpath -ms "$path")"
+ if ! [[ -f "$1/$path" ]]; then
+ printf "HTTP/1.1 404 Not found\\r\\nContent-Type: text/plain\\r\\nContent-length: 0\\r\\n\\r\\n"
+ exit
+ fi
+ printf "HTTP/1.1 200 OK\\r\\nContent-Type: text/plain\\r\\nContent-length: %d\\r\\n\\r\\n" "$(stat -L -c %s "$1/$path")"
+ cat "$1/$path"
+}
+
+eval "__common_$(declare -f setup)"
+setup() {
+ __common_setup
+ local repo arch
+
+ # Set up rsync server
+ cat <<-eot >"${TMP}/rsyncd.conf"
+ use chroot = no
+ [rsyncd]
+ path = ${TMP}/rsyncd
+ eot
+ local rsyncport
+ rsyncport=$(./lib/runserver "$TMP/rsyncd.pid" \
+ rsync --daemon --config "${TMP}/rsyncd.conf")
+
+ # Set up rsync contents
+ for repo in core testing; do
+ mkdir -p -- "${TMP}/rsyncd/archlinux/${repo}/os/x86_64"
+ touch -- "${TMP}/rsyncd/archlinux/${repo}/os/x86_64/${repo}.db.tar.gz"
+ ln -sT -- "${repo}.db.tar.gz" "${TMP}/rsyncd/archlinux/${repo}/os/x86_64/${repo}.db"
+ done
+ mkdir -p -- "${TMP}/rsyncd/archlinux"/{pool,sources}/{packages,community}
+ date +%s > "${TMP}/rsyncd/archlinux/lastupdate"
+ date +%s > "${TMP}/rsyncd/archlinux/lastsync"
+
+ for repo in core testing community community-testing; do
+ mkdir -p -- "${TMP}/rsyncd/archlinux32/i686/${repo}"
+ touch -- "${TMP}/rsyncd/archlinux32/i686/${repo}/${repo}.db.tar.gz"
+ ln -sT -- "${repo}.db.tar.gz" "${TMP}/rsyncd/archlinux32/i686/${repo}/${repo}.db"
+ done
+ mkdir -p -- "${TMP}/rsyncd/archlinux32/pool"
+ date +%s > "${TMP}/rsyncd/archlinux32/lastupdate"
+ date +%s > "${TMP}/rsyncd/archlinux32/lastsync"
+
+ for repo in core testing community community-testing; do
+ mkdir -p -- "${TMP}/rsyncd/archlinuxarm/armv7h/${repo}"
+ touch -- "${TMP}/rsyncd/archlinuxarm/armv7h/${repo}/${repo}.db.tar.gz"
+ ln -sT -- "${repo}.db.tar.gz" "${TMP}/rsyncd/archlinuxarm/armv7h/${repo}/${repo}.db"
+ done
+ date +%s > "${TMP}/rsyncd/archlinuxarm/lastupdate"
+ date +%s > "${TMP}/rsyncd/archlinuxarm/lastsync"
+
+ # Configure db-import to use that rsyncd server
+ cat <<-eot >"${TMP}/config.local.packages"
+ source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
+ source ../config.local.packages
+ ARCHTAGS=('core-x86_64' 'testing-x86_64')
+ ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinux/
+ eot
+ cat <<-eot >"${TMP}/config.local.community"
+ source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
+ source ../config.local.community
+ ARCHTAGS=('community-x86_64' 'community-testing-x86_64')
+ ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinux/
+ eot
+ cat <<-eot >"${TMP}/config.local.archlinux32"
+ source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
+ source ../config.local.archlinux32
+ ARCHTAGS=('core-i686' 'testing-i686' 'community-i686' 'community-testing-i686')
+ ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinux32/
+ eot
+ cat <<-eot >"${TMP}/config.local.archlinuxarm"
+ source_testconfig() { local STAGING; source ${DBSCRIPTS_CONFIG@Q}; }; source_testconfig
+ source ../config.local.archlinuxarm
+ ARCHTAGS=('core-armv7h' 'testing-armv7h' 'community-armv7h' 'community-testing-armv7h')
+ ARCHMIRROR=rsync://localhost:${rsyncport@Q}/rsyncd/archlinuxarm/
+ eot
+
+ # Set up HTTP server
+ local httpport
+ httpport=$(./lib/runserver "$TMP/httpd.pid" \
+ bash -c "$(declare -f httpserver); httpserver \"\$@\"" -- "$TMP/httpd")
+
+ # Set up HTTP contents
+ mkdir -- "$TMP/httpd"
+ cat <<-eot >"$TMP/httpd/blacklist.txt"
+ slavery:freedom:fsf:slavekit:Obviously
+ eot
+
+ # Configure db-import to use that HTTP server
+ export XDG_CONFIG_HOME="${TMP}/home/.config"
+ mkdir -p "$XDG_CONFIG_HOME"/libretools
+ cat <<-eot >"$XDG_CONFIG_HOME"/libretools/libretools.conf
+ BLACKLIST=http://localhost:${httpport@Q}/blacklist.txt
+ eot
+
+ # Set up repo contents
+ for arch in x86_64 i686 armv7h; do
+ for repo in core testing community community-testing; do
+ mkdir -p -- "${TMP}/ftp/${repo}/os/${arch}"
+ touch -- "${TMP}/ftp/${repo}/os/${arch}/${repo}.db.tar.gz"
+ ln -sT -- "${repo}.db.tar.gz" "${TMP}/ftp/${repo}/os/${arch}/${repo}.db"
+ done
+ done
+ mkdir -p -- "${TMP}/ftp"/{pool,sources}/{packages,community,archlinux32,alarm}
+ date +%s > "${TMP}/ftp/lastupdate"
+ date +%s > "${TMP}/ftp/lastsync"
+}
+eval "__common_$(declare -f teardown)"
+teardown() {
+ xargs -a "${TMP}/httpd.pid" kill --
+ xargs -a "${TMP}/rsyncd.pid" kill --
+ __common_teardown
+}
+
+######################################################################
+
+# __releaseImportedPackage PKGBASE ARCH DBFILE [POOLDIR]
+#
+# This is different from common.bash:releasePackage because
+# - it doesn't mess with VCS
+# - it adds the package to the .db file
+__releaseImportedPackage() {
+ local pkgbase=$1
+ local arch=$2
+ local dbfile=$3
+ local pooldir=$4
+ local repodir="${dbfile%/*}"
+ local dir restore pkgfiles pkgfile pkgs
+
+ dir="$TMP/import-build/$pkgbase"
+ if ! [[ -d "$dir" ]]; then
+ mkdir -p -- "$dir"
+ cp -t "$dir" -- "fixtures/${pkgbase}"/*
+ fi
+ pushd "$dir"
+ __buildPackage
+ restore="$(shopt -p nullglob || true)"
+ shopt -s nullglob
+ pkgfiles=(*-{"$arch",any}"$PKGEXT"{,.sig})
+ $restore
+ popd
+
+ mkdir -p "$repodir"
+ if [[ -z $pooldir ]]; then
+ mv -t "$repodir" -- "${pkgfiles[@]/#/"$dir/"}"
+ else
+ mkdir -p "$pooldir"
+ mv -t "$pooldir" -- "${pkgfiles[@]/#/"$dir/"}"
+ ln -sr -t "$repodir" -- "${pkgfiles[@]/#/"$pooldir/"}"
+ fi
+
+ pushd "$repodir"
+ pkgs=()
+ for pkgfile in "${pkgfiles[@]}"; do
+ if [[ "$pkgfile" = *.sig ]]; then
+ continue
+ fi
+ pkgs+=("$pkgfile")
+ done
+ repo-add -q "${dbfile##*/}" "${pkgs[@]}"
+ popd
+}
+
+__updateImportedPackage() {
+ pushd "$TMP/import-build/$1"
+ local pkgrel
+ pkgrel=$(. PKGBUILD; expr ${pkgrel} + 1)
+ sed "s/pkgrel=.*/pkgrel=${pkgrel}/" -i PKGBUILD
+ popd
+}
+
+__isLinkTo() {
+ [[ -L $1 ]]
+ [[ $1 -ef $2 ]]
+}
+
+__doesNotExist() {
+ local file
+ for file in "$@"; do
+ if stat "$file" 2>/dev/null; then
+ echo "TEST ERROR: File shouldn't exist, but does: $file"
+ return 1
+ fi
+ done
+}