From: Pierre Schmitz <pie...@archlinux.de>

(cherry picked from commit a53b874b6ed85097382d8d4889dc50cc98fbfdc6)
---
 test/cases/db-repo-add.bats    | 35 ++++++++++++++++++++++++-----------
 test/cases/db-update.bats      | 11 ++---------
 test/cases/ftpdir-cleanup.bats | 24 ++++++++++++++----------
 test/cases/sourceballs.bats    | 20 +++++++++++++++-----
 test/lib/common.bash           | 22 ++++++++++++----------
 5 files changed, 67 insertions(+), 45 deletions(-)

diff --git a/test/cases/db-repo-add.bats b/test/cases/db-repo-add.bats
index d76b245..869796a 100755
--- a/test/cases/db-repo-add.bats
+++ b/test/cases/db-repo-add.bats
@@ -1,5 +1,26 @@
 load ../lib/common
 
+__movePackageToRepo() {
+       local repo=$1
+       local pkgbase=$2
+       local arch=$3
+       local tarch
+       local tarches
+
+       if [[ $arch == any ]]; then
+               tarches=(${ARCHES[@]})
+       else
+               tarches=(${arch})
+       fi
+
+       # FIXME: pkgbase might not be part of the package filename
+       mv -v "${STAGING}"/${repo}/${pkgbase}-*-*-${arch}${PKGEXT}{,.sig} 
"${FTP_BASE}/${PKGPOOL}/"
+       for tarch in ${tarches[@]}; do
+               ln -sv ${FTP_BASE}/${PKGPOOL}/${pkgbase}-*-*-${arch}${PKGEXT} 
"${FTP_BASE}/${repo}/os/${tarch}/"
+               ln -sv 
${FTP_BASE}/${PKGPOOL}/${pkgbase}-*-*-${arch}${PKGEXT}.sig 
"${FTP_BASE}/${repo}/os/${tarch}/"
+       done
+}
+
 @test "add simple packages" {
        local pkgs=('pkg-simple-a' 'pkg-simple-b')
        local pkgbase
@@ -8,9 +29,7 @@ load ../lib/common
        for pkgbase in "${pkgs[@]}"; do
                for arch in "${ARCH_BUILD[@]}"; do
                        releasePackage extra "$pkgbase" "$arch"
-                       mv "${STAGING}"/extra/* "${FTP_BASE}/${PKGPOOL}/"
-                       ln -s 
"${FTP_BASE}/${PKGPOOL}/${pkgbase}-1-1-${arch}.pkg.tar.xz" 
"${FTP_BASE}/extra/os/${arch}/"
-                       ln -s 
"${FTP_BASE}/${PKGPOOL}/${pkgbase}-1-1-${arch}.pkg.tar.xz.sig" 
"${FTP_BASE}/extra/os/${arch}/"
+                       __movePackageToRepo extra ${pkgbase} ${arch}
                        db-repo-add extra "${arch}" 
"${pkgbase}-1-1-${arch}.pkg.tar.xz"
                done
        done
@@ -31,9 +50,7 @@ load ../lib/common
                add_pkgs=()
                for pkgbase in "${pkgs[@]}"; do
                        releasePackage extra "$pkgbase" "$arch"
-                       mv "${STAGING}"/extra/* "${FTP_BASE}/${PKGPOOL}/"
-                       ln -s 
"${FTP_BASE}/${PKGPOOL}/${pkgbase}-1-1-${arch}.pkg.tar.xz" 
"${FTP_BASE}/extra/os/${arch}/"
-                       ln -s 
"${FTP_BASE}/${PKGPOOL}/${pkgbase}-1-1-${arch}.pkg.tar.xz.sig" 
"${FTP_BASE}/extra/os/${arch}/"
+                       __movePackageToRepo extra ${pkgbase} ${arch}
                        add_pkgs+=("${pkgbase}-1-1-${arch}.pkg.tar.xz")
                done
                db-repo-add extra "${arch}" "${add_pkgs[@]}"
@@ -53,11 +70,7 @@ load ../lib/common
 
        for pkgbase in ${pkgs[@]}; do
                releasePackage extra ${pkgbase} any
-               mv "${STAGING}"/extra/* "${FTP_BASE}/${PKGPOOL}/"
-               for arch in "${ARCH_BUILD[@]}"; do
-                       ln -s 
"${FTP_BASE}/${PKGPOOL}/${pkgbase}-1-1-any.pkg.tar.xz" 
"${FTP_BASE}/extra/os/${arch}/"
-                       ln -s 
"${FTP_BASE}/${PKGPOOL}/${pkgbase}-1-1-any.pkg.tar.xz.sig" 
"${FTP_BASE}/extra/os/${arch}/"
-               done
+               __movePackageToRepo extra ${pkgbase} any
                db-repo-add extra any ${pkgbase}-1-1-any.pkg.tar.xz
        done
 
diff --git a/test/cases/db-update.bats b/test/cases/db-update.bats
index f648456..cf60fcd 100755
--- a/test/cases/db-update.bats
+++ b/test/cases/db-update.bats
@@ -114,12 +114,7 @@ load ../lib/common
        run db-update
        [ "$status" -ne 0 ]
 
-       local arch
-       for arch in "${ARCH_BUILD[@]}"; do
-               if [ -r "${FTP_BASE}/testing/os/${arch}/testing${DBEXT%.tar.*}" 
]; then
-                       ! bsdtar -xf 
"${FTP_BASE}/testing/os/${arch}/testing${DBEXT%.tar.*}" -O | grep "${pkgbase}" 
&>/dev/null
-               fi
-       done
+       checkRemovedPackageDB testing pkg-any-a any
 }
 
 @test "add incomplete split package" {
@@ -139,9 +134,7 @@ load ../lib/common
        [ "$status" -ne 0 ]
 
        for arch in "${ARCH_BUILD[@]}"; do
-               if [ -r "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" 
]; then
-                       ! bsdtar -xf 
"${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT%.tar.*}" -O | grep "${pkgbase}" 
&>/dev/null
-               fi
+               checkRemovedPackageDB ${repo} ${pkgbase} ${arch}
        done
 }
 
diff --git a/test/cases/ftpdir-cleanup.bats b/test/cases/ftpdir-cleanup.bats
index 5f6b680..2cb2e59 100755
--- a/test/cases/ftpdir-cleanup.bats
+++ b/test/cases/ftpdir-cleanup.bats
@@ -1,5 +1,15 @@
 load ../lib/common
 
+__checkRepoRemovedPackage() {
+       local repo=$1
+       local pkgbase=$2
+       local arch=$3
+
+       # FIXME: pkgbase might not be part of the package filename
+       [[ ! -f ${FTP_BASE}/${PKGPOOL}/${pkgbase}*${PKGEXT} ]]
+       [[ ! -f ${FTP_BASE}/${repo}/os/${arch}/${pkgbase}*${PKGEXT} ]]
+}
+
 @test "cleanup simple packages" {
        local pkgs=('pkg-simple-a' 'pkg-simple-b')
        local pkgbase
@@ -20,10 +30,8 @@ load ../lib/common
        ftpdir-cleanup
 
        for arch in "${ARCH_BUILD[@]}"; do
-               local pkg1="pkg-simple-a-1-1-${arch}.pkg.tar.xz"
                checkRemovedPackage extra 'pkg-simple-a' "${arch}"
-               [ ! -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ]
-               [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ]
+               __checkRepoRemovedPackage extra 'pkg-simple-a' ${arch}
 
                local pkg2="pkg-simple-b-1-1-${arch}.pkg.tar.xz"
                checkPackage extra "${pkg2}" "${arch}"
@@ -50,10 +58,8 @@ load ../lib/common
        ftpdir-cleanup
 
        for arch in "${ARCH_BUILD[@]}"; do
-               local pkg1="pkg-simple-epoch-1:1-1-${arch}.pkg.tar.xz"
                checkRemovedPackage extra 'pkg-simple-epoch' "${arch}"
-               [ ! -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ]
-               [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ]
+               __checkRepoRemovedPackage extra 'pkg-simple-epoch' ${arch}
        done
 }
 
@@ -72,8 +78,7 @@ load ../lib/common
 
        local pkg1='pkg-any-a-1-1-any.pkg.tar.xz'
        checkRemovedPackage extra 'pkg-any-a' any
-       [ ! -f "${FTP_BASE}/${PKGPOOL}/${pkg1}" ]
-       [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${pkg1}" ]
+       __checkRepoRemovedPackage extra 'pkg-any-a' any
 
        local pkg2="pkg-any-b-1-1-${arch}.pkg.tar.xz"
        checkPackage extra "${pkg2}" any
@@ -102,8 +107,7 @@ load ../lib/common
        for arch in "${ARCH_BUILD[@]}"; do
                for pkg in $(getPackageNamesFromPackageBase "${pkgs[0]}"); do
                        checkRemovedPackage extra "${pkg}" "${arch}"
-                       [ ! -f "${FTP_BASE}/${PKGPOOL}/${pkg}" ]
-                       [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ]
+                       __checkRepoRemovedPackage extra ${pkg} ${arch}
                done
 
                for pkg in $(getPackageNamesFromPackageBase "${pkgs[1]}"); do
diff --git a/test/cases/sourceballs.bats b/test/cases/sourceballs.bats
index cf80658..ba06b8d 100755
--- a/test/cases/sourceballs.bats
+++ b/test/cases/sourceballs.bats
@@ -1,5 +1,15 @@
 load ../lib/common
 
+__checkSourcePackage() {
+       local pkgbase=$1
+       [ -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ]
+}
+
+__checkRemovedSourcePackage() {
+       local pkgbase=$1
+       [ ! -r ${FTP_BASE}/${SRCPOOL}/${pkgbase}-*${SRCEXT} ]
+}
+
 @test "sourceballs" {
        local pkgs=('pkg-simple-a' 'pkg-simple-b' 'pkg-simple-epoch')
        local pkgbase
@@ -14,7 +24,7 @@ load ../lib/common
 
        sourceballs
        for pkgbase in "${pkgs[@]}"; do
-               [ -r "${FTP_BASE}/${SRCPOOL}/${pkgbase}"-*"${SRCEXT}" ]
+               __checkSourcePackage ${pkgbase}
        done
 }
 
@@ -29,7 +39,7 @@ load ../lib/common
 
        sourceballs
        for pkgbase in "${pkgs[@]}"; do
-               [ -r "${FTP_BASE}/${SRCPOOL}/${pkgbase}"-*"${SRCEXT}" ]
+               __checkSourcePackage ${pkgbase}
        done
 }
 
@@ -49,7 +59,7 @@ load ../lib/common
 
        sourceballs
        for pkgbase in "${pkgs[@]}"; do
-               [ -r "${FTP_BASE}/${SRCPOOL}/${pkgbase}"-*"${SRCEXT}" ]
+               __checkSourcePackage ${pkgbase}
        done
 }
 
@@ -71,6 +81,6 @@ load ../lib/common
        done
 
        sourceballs
-       [ ! -r "${FTP_BASE}/${SRCPOOL}/pkg-simple-a"-*"${SRCEXT}" ]
-       [ -r "${FTP_BASE}/${SRCPOOL}/pkg-simple-b"-*"${SRCEXT}" ]
+       __checkRemovedSourcePackage pkg-simple-a
+       __checkSourcePackage pkg-simple-b
 }
diff --git a/test/lib/common.bash b/test/lib/common.bash
index d8a01ca..dab16a5 100644
--- a/test/lib/common.bash
+++ b/test/lib/common.bash
@@ -183,6 +183,7 @@ checkPackageDB() {
        local pkg=$2
        local arch=$3
        local db
+       local tarch
        local tarches
 
        [ -r "${FTP_BASE}/${PKGPOOL}/${pkg}" ]
@@ -196,16 +197,16 @@ checkPackageDB() {
                tarches=("${arch}")
        fi
 
-       for arch in "${tarches[@]}"; do
-               [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}" ]
-               [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}")" == 
"$(readlink -e "${FTP_BASE}/${PKGPOOL}/${pkg}")" ]
+       for tarch in "${tarches[@]}"; do
+               [ -L "${FTP_BASE}/${repo}/os/${tarch}/${pkg}" ]
+               [ "$(readlink -e "${FTP_BASE}/${repo}/os/${tarch}/${pkg}")" == 
"$(readlink -e "${FTP_BASE}/${PKGPOOL}/${pkg}")" ]
 
-               [ -L "${FTP_BASE}/${repo}/os/${arch}/${pkg}.sig" ]
-               [ "$(readlink -e "${FTP_BASE}/${repo}/os/${arch}/${pkg}.sig")" 
== "$(readlink -e "${FTP_BASE}/${PKGPOOL}/${pkg}.sig")" ]
+               [ -L "${FTP_BASE}/${repo}/os/${tarch}/${pkg}.sig" ]
+               [ "$(readlink -e "${FTP_BASE}/${repo}/os/${tarch}/${pkg}.sig")" 
== "$(readlink -e "${FTP_BASE}/${PKGPOOL}/${pkg}.sig")" ]
 
                for db in "${DBEXT}" "${FILESEXT}"; do
-                       [ -r 
"${FTP_BASE}/${repo}/os/${arch}/${repo}${db%.tar.*}" ]
-                       bsdtar -xf 
"${FTP_BASE}/${repo}/os/${arch}/${repo}${db%.tar.*}" -O | grep "${pkg}" 
&>/dev/null
+                       [ -r 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" ]
+                       bsdtar -xf 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" -O | grep "${pkg}" 
&>/dev/null
                done
        done
 }
@@ -238,6 +239,7 @@ checkRemovedPackageDB() {
        local pkgbase=$2
        local arch=$3
        local db
+       local tarch
        local tarches
 
        if [[ $arch == any ]]; then
@@ -247,9 +249,9 @@ checkRemovedPackageDB() {
        fi
 
        for db in "${DBEXT}" "${FILESEXT}"; do
-               for arch in "${tarches[@]}"; do
-                       if [ -r 
"${FTP_BASE}/${repo}/os/${arch}/${repo}${db%.tar.*}" ]; then
-                               ! bsdtar -xf 
"${FTP_BASE}/${repo}/os/${arch}/${repo}${db%.tar.*}" -O | grep "${pkgbase}" 
&>/dev/null
+               for tarch in "${tarches[@]}"; do
+                       if [ -r 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" ]; then
+                               ! bsdtar -xf 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" -O | grep "${pkgbase}" 
&>/dev/null
                        fi
                done
        done
-- 
2.16.2

_______________________________________________
Dev mailing list
Dev@lists.parabola.nu
https://lists.parabola.nu/mailman/listinfo/dev

Reply via email to