tests: add xbps-fetch tests

Add test cases for xbps-fetch, including testing for:
- remote file identical with local file
- multiple files fetched
- error handling for multiple files fetched
This commit is contained in:
oopsbagel 2022-03-06 11:38:28 -08:00 committed by Duncan Overbruck
parent bb98a393c0
commit c08542ccac
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35
5 changed files with 97 additions and 1 deletions

View File

@ -6,6 +6,7 @@ include('libxbps/Kyuafile')
include('xbps-alternatives/Kyuafile')
include('xbps-checkvers/Kyuafile')
include('xbps-create/Kyuafile')
include('xbps-fetch/Kyuafile')
include('xbps-install/Kyuafile')
include('xbps-query/Kyuafile')
include('xbps-rindex/Kyuafile')

View File

@ -1,5 +1,5 @@
-include ../../config.mk
SUBDIRS = common libxbps xbps-alternatives xbps-checkvers xbps-create xbps-install xbps-query xbps-rindex xbps-uhelper xbps-remove xbps-digest
SUBDIRS = common libxbps xbps-alternatives xbps-checkvers xbps-create xbps-fetch xbps-install xbps-query xbps-rindex xbps-uhelper xbps-remove xbps-digest
include ../../mk/subdir.mk

View File

@ -0,0 +1,4 @@
syntax("kyuafile", 1)
test_suite("xbps-fetch")
atf_test_program{name="fetch_test"}

View File

@ -0,0 +1,8 @@
TOPDIR = ../../..
-include $(TOPDIR)/config.mk
TESTSHELL = fetch_test
TESTSSUBDIR = xbps/xbps-fetch
EXTRA_FILES = Kyuafile
include $(TOPDIR)/mk/test.mk

View File

@ -0,0 +1,83 @@
#! /usr/bin/env atf-sh
# Test that xbps-fetch works as expected.
atf_test_case success
success_head() {
atf_set "descr" "xbps-fetch: test successful remote fetch"
}
success_body() {
mkdir some_repo
touch some_repo/pkg_A
xbps-fetch file://$PWD/some_repo/pkg_A
atf_check_equal $? 0
}
atf_test_case pkgnotfound
pkgnotfound_head() {
atf_set "descr" "xbps-fetch: test remote package not found"
}
pkgnotfound_body() {
xbps-fetch file://$PWD/nonexistant
atf_check_equal $? 1
}
atf_test_case identical
identical_head() {
atf_set "descr" "xbps-fetch: test fetching identical file from remote"
}
identical_body() {
mkdir some_repo
echo 'content' > some_repo/pkg_A
echo 'content' > pkg_A
output=$(xbps-fetch file://$PWD/some_repo/pkg_A 2>&1)
atf_check_equal $? 0
atf_check_equal "$output" "file://$PWD/some_repo/pkg_A: file is identical with remote."
}
atf_test_case multiple_success
multiple_success_head() {
atf_set "descr" "xbps-fetch: test fetching multiple remote files"
}
multiple_success_body() {
mkdir some_repo
touch some_repo/pkg_A some_repo/pkg_B
xbps-fetch file://$PWD/some_repo/pkg_A file://$PWD/some_repo/pkg_B
atf_check_equal $? 0
test -f pkg_A
atf_check_equal $? 0
test -f pkg_B
atf_check_equal $? 0
}
atf_test_case multiple_notfound
multiple_notfound_head() {
atf_set "descr" "xbps-fetch: test fetching multiple remote files, with one not found"
}
multiple_notfound_body() {
mkdir some_repo
touch some_repo/pkg_A
xbps-fetch file://$PWD/some_repo/nonexistant file://$PWD/some_repo/pkg_A
atf_check_equal $? 1
test -f pkg_A
atf_check_equal $? 0
test -f nonexistant
atf_check_equal $? 1
}
atf_init_test_cases() {
atf_add_test_case success
atf_add_test_case pkgnotfound
atf_add_test_case identical
atf_add_test_case multiple_success
atf_add_test_case multiple_notfound
}