From c08542ccacacb52e70c157b1030bf5de6e2e8c64 Mon Sep 17 00:00:00 2001 From: oopsbagel Date: Sun, 6 Mar 2022 11:38:28 -0800 Subject: [PATCH] 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 --- tests/xbps/Kyuafile | 1 + tests/xbps/Makefile | 2 +- tests/xbps/xbps-fetch/Kyuafile | 4 ++ tests/xbps/xbps-fetch/Makefile | 8 +++ tests/xbps/xbps-fetch/fetch_test.sh | 83 +++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/xbps/xbps-fetch/Kyuafile create mode 100644 tests/xbps/xbps-fetch/Makefile create mode 100755 tests/xbps/xbps-fetch/fetch_test.sh diff --git a/tests/xbps/Kyuafile b/tests/xbps/Kyuafile index a71995e2..f1e22c8b 100644 --- a/tests/xbps/Kyuafile +++ b/tests/xbps/Kyuafile @@ -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') diff --git a/tests/xbps/Makefile b/tests/xbps/Makefile index a0fc3f95..840fa4c6 100644 --- a/tests/xbps/Makefile +++ b/tests/xbps/Makefile @@ -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 diff --git a/tests/xbps/xbps-fetch/Kyuafile b/tests/xbps/xbps-fetch/Kyuafile new file mode 100644 index 00000000..ca036e04 --- /dev/null +++ b/tests/xbps/xbps-fetch/Kyuafile @@ -0,0 +1,4 @@ +syntax("kyuafile", 1) + +test_suite("xbps-fetch") +atf_test_program{name="fetch_test"} diff --git a/tests/xbps/xbps-fetch/Makefile b/tests/xbps/xbps-fetch/Makefile new file mode 100644 index 00000000..1eb0b46e --- /dev/null +++ b/tests/xbps/xbps-fetch/Makefile @@ -0,0 +1,8 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TESTSHELL = fetch_test +TESTSSUBDIR = xbps/xbps-fetch +EXTRA_FILES = Kyuafile + +include $(TOPDIR)/mk/test.mk diff --git a/tests/xbps/xbps-fetch/fetch_test.sh b/tests/xbps/xbps-fetch/fetch_test.sh new file mode 100755 index 00000000..65aad3f6 --- /dev/null +++ b/tests/xbps/xbps-fetch/fetch_test.sh @@ -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 +}