summaryrefslogtreecommitdiff
path: root/test/librerelease-test.sh
blob: 6e2b42d96e72180c8e49ce15ee8fb13dd09c2090 (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
62
63
64
65
66
67
68
#!/usr/bin/env roundup

describe librerelease
. ./test-common.sh

common_before() {
	mkdir -p $XDG_CONFIG_HOME/libretools
	{
		echo "WORKDIR='$tmpdir/workdir'"
		echo 'REPODEST=ssh://repo@repo.parabola.nu:1863/~/staging/$LIBREUSER/staging/'
	} >$XDG_CONFIG_HOME/libretools/libretools.conf
	mkdir -p $XDG_CONFIG_HOME/pacman
	{
		echo 'PKGEXT=.pkg.tar.gz'
		echo "PKGDEST='$tmpdir/workdir/pkgdest'"
		echo "GPGKEY=YOURKEY"
	} >$XDG_CONFIG_HOME/pacman/makepkg.conf
	mkdir -p "$tmpdir/workdir/pkgdest"
}

it_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"
}

it_lists_all_files() {
	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"
	unset WORKDIR
	LC_ALL=C librerelease -l &>"$tmpdir/list"

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

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

it_fails_if_gpgkey_not_set() {
	echo 'unset GPGKEY' >> "$XDG_CONFIG_HOME"/pacman/makepkg.conf

	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"
	unset WORKDIR
	LC_ALL=C librerelease -l >"$tmpdir/stdout" 2>"$tmpdir/stderr" || stat=$?

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