summaryrefslogtreecommitdiff
path: root/test/librefetch-test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/librefetch-test.sh')
-rw-r--r--test/librefetch-test.sh99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh
new file mode 100644
index 0000000..f10ee7f
--- /dev/null
+++ b/test/librefetch-test.sh
@@ -0,0 +1,99 @@
+#!/usr/bin/env roundup
+
+describe librefetch
+
+. ./test-common.sh
+
+KEYSERVER=hkp://pool.sks-keyservers.net
+GPG="gpg --quiet --batch --no-tty --no-permission-warning --keyserver ${KEYSERVER}"
+
+before() {
+ _before
+
+ mkdir -p "$XDG_CONFIG_HOME"/{pacman,libretools} "$tmpdir/srcdest"
+
+ cat <<EOF > "$XDG_CONFIG_HOME/pacman/makepkg.conf"
+DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
+ 'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'rsync::/usr/bin/rsync --no-motd -z %u %o'
+ 'scp::/usr/bin/scp -C %u %o')
+BUILDDIR=""
+SRCDEST=$tmpdir/srcdest
+. ${_librelib_conf_sh_pkgconfdir}/librefetch-makepkg.conf
+EOF
+ sed -i 's,/usr/bin/librefetch,$(which librefetch),' \
+ "${_librelib_conf_sh_pkgconfdir}/librefetch-makepkg.conf"
+
+ export MAKEPKG_CONF="$XDG_CONFIG_HOME/pacman/makepkg.conf"
+
+ printf '%s\n' \
+ 'MIRRORS=("phony://example.com/dir/")' \
+ 'DOWNLOADER=/usr/bin/false' \
+ > "$XDG_CONFIG_HOME/libretools/librefetch.conf"
+
+ printf '%s\n' \
+ 'Key-Type: RSA' \
+ 'Key-Length: 1024' \
+ 'Key-Usage: sign' \
+ 'Name-Real: Temporary LibreTools testsuite key' \
+ 'Name-Email: libretools-test@localhost' \
+ 'Expire-Date: 0' \
+ '%no-protection' \
+ '%commit' \
+ | $GPG --gen-key 2>/dev/null
+}
+
+after() {
+ _after
+}
+
+it_displays_help() {
+ LC_ALL=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ empty $tmpdir/stderr
+}
+
+# This test used to be called "it_cleans_src_libre_first", but let's
+# be honest: it checks pretty much everything related to normal
+# operation.
+it_runs() {
+ local srcball=testpkg-1.0.tar.gz
+ cp librefetch.d/* "$tmpdir/"
+ cd "$tmpdir"
+
+ # Create garbage, to verifiy that it cleans src-libre first
+ mkdir -p src-libre/foo
+ touch src-libre/foo/file
+
+ # Run librefetch
+ makepkg -g
+
+ # Verify that no temporary files were left around
+ not test -e librefetch.*
+
+ # Verify:
+ # - The srcball was created...
+ # - ... and is in the correct directory
+ # - The srcball does not contain the garbage created earlier
+ # - The files in the srcball are in the correct order (if the
+ # order isn't ensured, then this would only sometimes fail,
+ # unfortunately).
+ bsdtar tf "$tmpdir/srcdest/$srcball" > list-pkg.txt
+ diff -u list.txt list-pkg.txt
+ # Verify that the signature was created and matches
+ gpg --quiet --verify "$tmpdir/srcdest/$srcball"{.sig,} 2>/dev/null
+}
+
+it_recurses() {
+ local srcball=testpkg-1.0.tar.gz
+ cp librefetch.d/* "$tmpdir/"
+ cd "$tmpdir"
+ mv PKGBUILD{-recurse,}
+
+ makepkg -g
+ bsdtar tf "$tmpdir/srcdest/$srcball" > list-pkg.txt
+ diff -u list.txt list-pkg.txt
+ gpg --quiet --verify "$tmpdir/srcdest/$srcball"{.sig,} 2>/dev/null
+}