Skip to content

Commit

Permalink
tests: add xbps-fetch tests
Browse files Browse the repository at this point in the history
Add test cases for xbps-fetch, including testing for:
- remote file identical with local file
- multiple files fetched
- error handling for multiple files fetched
  • Loading branch information
oopsbagel authored and Duncaen committed Jun 21, 2022
1 parent bb98a39 commit c08542c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/xbps/Kyuafile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/xbps/Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/xbps/xbps-fetch/Kyuafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
syntax("kyuafile", 1)

test_suite("xbps-fetch")
atf_test_program{name="fetch_test"}
8 changes: 8 additions & 0 deletions tests/xbps/xbps-fetch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TOPDIR = ../../..
-include $(TOPDIR)/config.mk

TESTSHELL = fetch_test
TESTSSUBDIR = xbps/xbps-fetch
EXTRA_FILES = Kyuafile

include $(TOPDIR)/mk/test.mk
83 changes: 83 additions & 0 deletions tests/xbps/xbps-fetch/fetch_test.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit c08542c

Please sign in to comment.