summaryrefslogtreecommitdiff
path: root/test/cases/librerelease.bats
blob: eb73d35fda3f9f0e849667c4fb4ebce4be3fe71d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
load ../lib/common

setup() {
	common_setup

	cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
		REPODEST=ssh://repo@repo.parabola.nu:1863/~/staging/$LIBREUSER/staging/
		eot
	cat >> "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot
		PKGEXT=.pkg.tar.gz
		eot
}

@test "librerelease displays usage text" {
	rm -rf "$XDG_CONFIG_HOME"
	LC_ALL=C librerelease -h >"$tmpdir/stdout" 2>"$tmpdir/stderr"

	[[ "$(sed 1q "$tmpdir/stdout")" =~ Usage:.* ]]
	empty "$tmpdir/stderr"
}

@test "librerelease lists all files" {
	local workdir="$tmpdir/workdir"
	mkdir -p "$workdir/staging/repo1" "$workdir/staging/repo2/sub"
	touch \
		"$workdir/staging/repo1/file1" \
		"$workdir/staging/repo1/file2" \
		"$workdir/staging/repo2/file with spaces" \
		"$workdir/staging/repo2/sub/subfolder"

	LC_ALL=C librerelease -l &>"$tmpdir/list" || { status=$?; cat "$tmpdir/list"; return $status; }

	cat > "$tmpdir/list-correct" <<-eot
		  -> repo1
		     file1
		     file2
		  -> repo2
		     file with spaces
		     sub/subfolder
		eot

	diff "$tmpdir/list-correct" "$tmpdir/list"
}

@test "librerelease fails if gpgkey not set" {
	unset GPGKEY

	local workdir="$tmpdir/workdir"
	mkdir -p "$workdir/staging/repo1" "$workdir/staging/repo2/sub"
	touch \
		"$workdir/staging/repo1/file1" \
		"$workdir/staging/repo1/file2" \
		"$workdir/staging/repo2/file with spaces" \
		"$workdir/staging/repo2/sub/subfolder"

	LC_ALL=C librerelease -l >"$tmpdir/stdout" 2>"$tmpdir/stderr" || status=$?

	[[ $status != 0 ]]
	empty "$tmpdir/stdout"
	grep GPGKEY "$tmpdir/stderr"
}