summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2018-07-15 00:27:53 -0400
committerLuke Shumaker <lukeshu@parabola.nu>2018-10-07 18:15:03 -0400
commita85281eeed42e5ffa37ce6ab8f57dd9b5d9dc8b9 (patch)
tree804158c092346a37731984126c53cae57c288bd9
parent830078cbeed18c64cffce4f4844081c7b5644a65 (diff)
test: Centralize all SVN access in to 'vcs*' functions in the 'common-svn.bash' file
Similarly to the main code, factor out all SVN-specific code in the tests in to a separate `common-$VCS.bash`. This will allow anyone writing a different `db-functions-$VCS` file to actually test that file.
-rw-r--r--test/cases/db-update.bats2
-rw-r--r--test/lib/common-svn.bash125
-rw-r--r--test/lib/common.bash84
3 files changed, 143 insertions, 68 deletions
diff --git a/test/cases/db-update.bats b/test/cases/db-update.bats
index 9ee0632..0be47d7 100644
--- a/test/cases/db-update.bats
+++ b/test/cases/db-update.bats
@@ -207,7 +207,7 @@ load ../lib/common
@test "add package with inconsistent pkgbuild fails" {
releasePackage extra 'pkg-any-a'
- updateRepoPKGBUILD 'pkg-any-a' extra any
+ updateRepoPKGBUILD 'pkg-any-a' extra
run db-update
[ "$status" -ne 0 ]
diff --git a/test/lib/common-svn.bash b/test/lib/common-svn.bash
new file mode 100644
index 0000000..35bfc52
--- /dev/null
+++ b/test/lib/common-svn.bash
@@ -0,0 +1,125 @@
+#!/hint/bash
+
+# usage: vcsSetup
+# Do any test-suite setup.
+#
+# Count on $TMP and $DBSCRIPTS_CONFIG being set, but not much else
+# being done. Notably $DBSCRIPTS_CONFIG hasn't been loaded yet (so
+# that we have a chance to edit it).
+vcsSetup() {
+ cat <<eot >> "${DBSCRIPTS_CONFIG}"
+ SVNREPO="file://${TMP}/svn-packages-repo"
+eot
+
+ mkdir -p "${TMP}"/svn-packages-{copy,repo}
+
+ svnadmin create "${TMP}/svn-packages-repo"
+ svn checkout -q "file://${TMP}/svn-packages-repo" "${TMP}/svn-packages-copy"
+}
+
+# usage: vcsDirOfPKGBUILD $pkgbase
+#
+# Print the path to the directory storing the "trunk"/"master" working
+# copy of the PKGBUILD for the given $pkgbase.
+vcsDirOfPKGBUILD() {
+ local pkgbase=$1
+
+ echo "${TMP}/svn-packages-copy/${pkgbase}/trunk/"
+}
+
+# usage: vcsInitFixture $pkgbase
+#
+# Initialize from the test fixtures the "trunk"/"master" working copy
+# of the PKGBUILD for the given $pkgbase.
+vcsInitFixture() {
+ local pkgbase=$1
+
+ mkdir -p "${TMP}/svn-packages-copy/${pkgbase}"/{trunk,repos}
+ cp -r "fixtures/${pkgbase}"/* "${TMP}/svn-packages-copy/${pkgbase}/trunk/"
+ svn add -q "${TMP}/svn-packages-copy/${pkgbase}"
+ svn commit -q -m"initial commit of ${pkgbase}" "${TMP}/svn-packages-copy"
+}
+
+# usage: vcsCommit $msg
+# Commit changes to the PKGBUILD in the current directory
+vcsCommit() {
+ local msg=$1
+ svn commit -q -m"$msg"
+}
+
+# usage: vcsRelease $repo
+# Run from the "trunk"/"master" PKGBUILD directory.
+#
+# This is a cheap imitation of the `archrelease` program that is part
+# of the `devtools` package.
+vcsRelease() {
+ local repo=$1
+ local pkgarches
+ local tarch
+ local tag
+
+ pkgarches=($(. PKGBUILD; echo ${arch[@]}))
+ pushd ..
+ for tarch in ${pkgarches[@]}; do
+ tag=${repo}-${tarch}
+
+ if [[ -d repos/$tag ]]; then
+ svn rm repos/$tag/PKGBUILD
+ else
+ mkdir -p repos/$tag
+ svn add repos/$tag
+ fi
+
+ svn copy -r HEAD trunk/PKGBUILD repos/$tag/
+ done
+ svn commit -m "__archrelease"
+ popd
+}
+
+# usage: vcsCheckPackage $repo $pkgbase $pkgver
+#
+# Verify that the PKGBUILD for the given $pkgbase is tagged as
+# existing in $repo, and has the correct $pkgver.
+vcsCheckPackage() {
+ local repo=$1
+ local pkgbase=$2
+ local pkgver=$3
+
+ svn up -q "${TMP}/svn-packages-copy/${pkgbase}"
+
+ local dirarches=() pkgbuildarches=()
+ local pkgbuild dirarch pkgbuildver
+ for pkgbuild in "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-"+([^-])"/PKGBUILD"; do
+ [[ -e $pkgbuild ]] || continue
+ dirarch=${pkgbuild%/PKGBUILD}
+ dirarch=${dirarch##*-}
+
+ dirarches+=("$dirarch")
+ pkgbuildarches+=($(. "$pkgbuild"; echo ${arch[@]}))
+ pkgbuildver=$(. "$pkgbuild"; get_full_version)
+ [[ $pkgver = "$pkgbuildver" ]]
+ done
+ # Verify that the arches-from-dirnames and
+ # arches-from-PKGBUILDs agree (that a PKGBUILD existed for
+ # every arch).
+ (( ${#dirarches[@]} > 0 ))
+ read -d '' -r -a dirarches < <(printf '%s\0' "${dirarches[@]}" | sort -uz)
+ read -d '' -r -a pkgbuildarches < <(printf '%s\0' "${pkgbuildarches[@]}" | sort -uz)
+ declare -p dirarches pkgbuildarches
+ [[ "${dirarches[*]}" = "${pkgbuildarches[*]}" ]]
+}
+
+# usage: vcsCheckRemovedPackage $repo $pkgbase
+#
+# Verify that no PKGBUILD for the given $pkgbase is tagged as existing
+# in $repo.
+vcsCheckRemovedPackage() {
+ local repo=$1
+ local pkgbase=$2
+
+ svn up -q "${TMP}/svn-packages-copy/${pkgbase}"
+
+ if __isGlobfile "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-"+([^-])"/PKGBUILD"; then
+ return 1
+ fi
+}
diff --git a/test/lib/common.bash b/test/lib/common.bash
index 83aaac4..8fc1bdb 100644
--- a/test/lib/common.bash
+++ b/test/lib/common.bash
@@ -6,7 +6,7 @@ __updatePKGBUILD() {
pkgrel=$(. PKGBUILD; expr ${pkgrel} + 1)
sed "s/pkgrel=.*/pkgrel=${pkgrel}/" -i PKGBUILD
- svn commit -q -m"update pkg to pkgrel=${pkgrel}"
+ vcsCommit "update pkg to pkgrel=${pkgrel}"
}
__getCheckSum() {
@@ -63,30 +63,6 @@ __buildPackage() {
done
}
-__archrelease() {
- local repo=$1
- local pkgarches
- local tarch
- local tag
-
- pkgarches=($(. PKGBUILD; echo ${arch[@]}))
- pushd ..
- for tarch in ${pkgarches[@]}; do
- tag=${repo}-${tarch}
-
- if [[ -d repos/$tag ]]; then
- svn rm repos/$tag/PKGBUILD
- else
- mkdir -p repos/$tag
- svn add repos/$tag
- fi
-
- svn copy -r HEAD trunk/PKGBUILD repos/$tag/
- done
- svn commit -m "__archrelease"
- popd
-}
-
setup() {
local p
local pkg
@@ -99,7 +75,6 @@ setup() {
export DBSCRIPTS_CONFIG=${TMP}/config.local
cat <<eot > "${DBSCRIPTS_CONFIG}"
FTP_BASE="${TMP}/ftp"
- SVNREPO="file://${TMP}/svn-packages-repo"
PKGREPOS=('core' 'extra' 'testing')
PKGPOOL='pool/packages'
SRCPOOL='sources/packages'
@@ -113,9 +88,11 @@ setup() {
CLEANUP_DRYRUN=false
SOURCE_CLEANUP_DRYRUN=false
eot
+ . "lib/common-$(. config; echo "$VCS").bash"
+ vcsSetup
. config
- mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup,svn-packages-{copy,repo}}
+ mkdir -p "${TMP}/"{ftp,tmp,staging,{package,source}-cleanup}
for r in ${PKGREPOS[@]}; do
mkdir -p "${TMP}/staging/${r}"
@@ -125,9 +102,6 @@ eot
done
mkdir -p "${TMP}/ftp/${PKGPOOL}"
mkdir -p "${TMP}/ftp/${SRCPOOL}"
-
- svnadmin create "${TMP}/svn-packages-repo"
- svn checkout -q "file://${TMP}/svn-packages-repo" "${TMP}/svn-packages-copy"
}
teardown() {
@@ -138,23 +112,22 @@ releasePackage() {
local repo=$1
local pkgbase=$2
- if [ ! -d "${TMP}/svn-packages-copy/${pkgbase}/trunk" ]; then
- mkdir -p "${TMP}/svn-packages-copy/${pkgbase}"/{trunk,repos}
- cp -r "fixtures/${pkgbase}"/* "${TMP}/svn-packages-copy"/${pkgbase}/trunk/
- svn add -q "${TMP}/svn-packages-copy"/${pkgbase}
- svn commit -q -m"initial commit of ${pkgbase}" "${TMP}/svn-packages-copy"
+ local dir=$(vcsDirOfPKGBUILD "$pkgbase")
+
+ if [[ ! -d $dir ]]; then
+ vcsInitFixture "$pkgbase"
fi
- pushd "${TMP}/svn-packages-copy"/${pkgbase}/trunk/
+ pushd "$dir"
__buildPackage "${STAGING}"/${repo}
- __archrelease ${repo}
+ vcsRelease ${repo}
popd
}
updatePackage() {
local pkgbase=$1
- pushd "${TMP}/svn-packages-copy/${pkgbase}/trunk/"
+ pushd "$(vcsDirOfPKGBUILD "$pkgbase")"
__updatePKGBUILD
__buildPackage
popd
@@ -163,10 +136,12 @@ updatePackage() {
updateRepoPKGBUILD() {
local pkgbase=$1
local repo=$2
- local arch=$3
- pushd "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-${arch}/"
+ # Update the PKGBUILD and release the PKGBUILD, but *without*
+ # ever building or releasing the binary package.
+ pushd "$(vcsDirOfPKGBUILD "$pkgbase")"
__updatePKGBUILD
+ vcsRelease ${repo}
popd
}
@@ -227,28 +202,7 @@ checkPackage() {
local pkgbase=$2
local pkgver=$3
- svn up -q "${TMP}/svn-packages-copy/${pkgbase}"
-
- local dirarches=() pkgbuildarches=()
- local pkgbuild dirarch pkgbuildver
- for pkgbuild in "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-"+([^-])"/PKGBUILD"; do
- [[ -e $pkgbuild ]] || continue
- dirarch=${pkgbuild%/PKGBUILD}
- dirarch=${dirarch##*-}
-
- dirarches+=("$dirarch")
- pkgbuildarches+=($(. "$pkgbuild"; echo ${arch[@]}))
- pkgbuildver=$(. "$pkgbuild"; get_full_version)
- [[ $pkgver = "$pkgbuildver" ]]
- done
- # Verify that the arches-from-dirnames and
- # arches-from-PKGBUILDs agree (that a PKGBUILD existed for
- # every arch).
- (( ${#dirarches[@]} > 0 ))
- read -d '' -r -a dirarches < <(printf '%s\0' "${dirarches[@]}" | sort -uz)
- read -d '' -r -a pkgbuildarches < <(printf '%s\0' "${pkgbuildarches[@]}" | sort -uz)
- declare -p dirarches pkgbuildarches
- [[ "${dirarches[*]}" = "${pkgbuildarches[*]}" ]]
+ vcsCheckPackage "$repo" "$pkgbase" "$pkgver"
checkPackageDB "$repo" "$pkgbase" "$pkgver"
}
@@ -257,11 +211,7 @@ checkRemovedPackage() {
local repo=$1
local pkgbase=$2
- svn up -q "${TMP}/svn-packages-copy/${pkgbase}"
-
- if __isGlobfile "${TMP}/svn-packages-copy/${pkgbase}/repos/${repo}-"+([^-])"/PKGBUILD"; then
- return 1
- fi
+ vcsCheckRemovedPackage "$repo" "$pkgbase"
checkRemovedPackageDB $repo $pkgbase
}