Skip to content

Commit c08542c

Browse files
oopsbagelDuncaen
authored andcommitted
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
1 parent bb98a39 commit c08542c

5 files changed

Lines changed: 97 additions & 1 deletion

File tree

tests/xbps/Kyuafile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include('libxbps/Kyuafile')
66
include('xbps-alternatives/Kyuafile')
77
include('xbps-checkvers/Kyuafile')
88
include('xbps-create/Kyuafile')
9+
include('xbps-fetch/Kyuafile')
910
include('xbps-install/Kyuafile')
1011
include('xbps-query/Kyuafile')
1112
include('xbps-rindex/Kyuafile')

tests/xbps/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-include ../../config.mk
22

3-
SUBDIRS = common libxbps xbps-alternatives xbps-checkvers xbps-create xbps-install xbps-query xbps-rindex xbps-uhelper xbps-remove xbps-digest
3+
SUBDIRS = common libxbps xbps-alternatives xbps-checkvers xbps-create xbps-fetch xbps-install xbps-query xbps-rindex xbps-uhelper xbps-remove xbps-digest
44

55
include ../../mk/subdir.mk

tests/xbps/xbps-fetch/Kyuafile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
syntax("kyuafile", 1)
2+
3+
test_suite("xbps-fetch")
4+
atf_test_program{name="fetch_test"}

tests/xbps/xbps-fetch/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
TOPDIR = ../../..
2+
-include $(TOPDIR)/config.mk
3+
4+
TESTSHELL = fetch_test
5+
TESTSSUBDIR = xbps/xbps-fetch
6+
EXTRA_FILES = Kyuafile
7+
8+
include $(TOPDIR)/mk/test.mk
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#! /usr/bin/env atf-sh
2+
# Test that xbps-fetch works as expected.
3+
4+
atf_test_case success
5+
6+
success_head() {
7+
atf_set "descr" "xbps-fetch: test successful remote fetch"
8+
}
9+
10+
success_body() {
11+
mkdir some_repo
12+
touch some_repo/pkg_A
13+
xbps-fetch file://$PWD/some_repo/pkg_A
14+
atf_check_equal $? 0
15+
}
16+
17+
atf_test_case pkgnotfound
18+
19+
pkgnotfound_head() {
20+
atf_set "descr" "xbps-fetch: test remote package not found"
21+
}
22+
23+
pkgnotfound_body() {
24+
xbps-fetch file://$PWD/nonexistant
25+
atf_check_equal $? 1
26+
}
27+
28+
atf_test_case identical
29+
30+
identical_head() {
31+
atf_set "descr" "xbps-fetch: test fetching identical file from remote"
32+
}
33+
34+
identical_body() {
35+
mkdir some_repo
36+
echo 'content' > some_repo/pkg_A
37+
echo 'content' > pkg_A
38+
output=$(xbps-fetch file://$PWD/some_repo/pkg_A 2>&1)
39+
atf_check_equal $? 0
40+
atf_check_equal "$output" "file://$PWD/some_repo/pkg_A: file is identical with remote."
41+
}
42+
43+
atf_test_case multiple_success
44+
45+
multiple_success_head() {
46+
atf_set "descr" "xbps-fetch: test fetching multiple remote files"
47+
}
48+
49+
multiple_success_body() {
50+
mkdir some_repo
51+
touch some_repo/pkg_A some_repo/pkg_B
52+
xbps-fetch file://$PWD/some_repo/pkg_A file://$PWD/some_repo/pkg_B
53+
atf_check_equal $? 0
54+
test -f pkg_A
55+
atf_check_equal $? 0
56+
test -f pkg_B
57+
atf_check_equal $? 0
58+
}
59+
60+
atf_test_case multiple_notfound
61+
62+
multiple_notfound_head() {
63+
atf_set "descr" "xbps-fetch: test fetching multiple remote files, with one not found"
64+
}
65+
66+
multiple_notfound_body() {
67+
mkdir some_repo
68+
touch some_repo/pkg_A
69+
xbps-fetch file://$PWD/some_repo/nonexistant file://$PWD/some_repo/pkg_A
70+
atf_check_equal $? 1
71+
test -f pkg_A
72+
atf_check_equal $? 0
73+
test -f nonexistant
74+
atf_check_equal $? 1
75+
}
76+
77+
atf_init_test_cases() {
78+
atf_add_test_case success
79+
atf_add_test_case pkgnotfound
80+
atf_add_test_case identical
81+
atf_add_test_case multiple_success
82+
atf_add_test_case multiple_notfound
83+
}

0 commit comments

Comments
 (0)