mirror of
https://gitlab.alpinelinux.org/alpine/abuild.git
synced 2025-01-23 07:44:00 +00:00
tests: refactor abuild-keygen tests
This commit is contained in:
parent
7f675c1de3
commit
2326f0c4ef
@ -1,43 +0,0 @@
|
||||
setup() {
|
||||
export ABUILD_KEYGEN="$PWD/../abuild-keygen"
|
||||
export ABUILD_SHAREDIR="$PWD/.."
|
||||
export ABUILD_USERDIR="$BATS_TEST_TMPDIR"/user
|
||||
mkdir -p "$ABUILD_USERDIR"
|
||||
export abuild_keygen_install_root=${ABUILD_USERDIR}
|
||||
|
||||
# provide a fake git
|
||||
mkdir -p "$BATS_TEST_TMPDIR"/bin
|
||||
cat >"$BATS_TEST_TMPDIR"/bin/git <<-EOF
|
||||
#!/bin/sh
|
||||
exit 1
|
||||
EOF
|
||||
chmod +x "$BATS_TEST_TMPDIR"/bin/git
|
||||
export PATH="$BATS_TEST_TMPDIR/bin:$PATH"
|
||||
}
|
||||
|
||||
@test "abuild-keygen: help text" {
|
||||
$ABUILD_KEYGEN --help
|
||||
}
|
||||
|
||||
@test "abuild-keygen: generate key non-interactively" {
|
||||
$ABUILD_KEYGEN -n
|
||||
}
|
||||
|
||||
@test "abuild-keygen: --append option" {
|
||||
PACKAGER="Test User <user@example.com>" $ABUILD_KEYGEN --append -n
|
||||
grep '^PACKAGER_PRIVKEY=.*user@example.com' "$ABUILD_USERDIR"/abuild.conf
|
||||
}
|
||||
|
||||
@test "abuild-keygen: --install option fails without SUDO" {
|
||||
run SUDO=false $ABUILD_KEYGEN --install
|
||||
[ $status -ne 0 ]
|
||||
}
|
||||
|
||||
@test "abuild-keygen: --install option (interactive)" {
|
||||
echo | SUDO= $ABUILD_KEYGEN --install
|
||||
}
|
||||
|
||||
@test "abuild-keygen: --install -n (non-interacive)" {
|
||||
SUDO= $ABUILD_KEYGEN --install -n
|
||||
}
|
||||
|
81
tests/abuild_keygen_test
Executable file
81
tests/abuild_keygen_test
Executable file
@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env atf-sh
|
||||
|
||||
. $(atf_get_srcdir)/test_env.sh
|
||||
init_tests \
|
||||
abuild_keygen_help \
|
||||
abuild_keygen_invalid_opts \
|
||||
abuild_keygen_invalid_arg \
|
||||
abuild_keygen_non_interactive \
|
||||
abuild_keygen_append \
|
||||
abuild_keygen_install_without_sudo \
|
||||
abuild_keygen_install_interactive \
|
||||
abuild_keygen_install_non_interactive
|
||||
|
||||
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
|
||||
export GIT=false
|
||||
|
||||
abuild_keygen_help_body() {
|
||||
atf_check -s exit:0 \
|
||||
-o not-empty \
|
||||
-e empty \
|
||||
abuild-keygen --help
|
||||
}
|
||||
|
||||
abuild_keygen_invalid_opts_body() {
|
||||
atf_check -s exit:1 \
|
||||
-o empty \
|
||||
-e not-empty \
|
||||
abuild-keygen -INVALID
|
||||
}
|
||||
|
||||
abuild_keygen_invalid_arg_body() {
|
||||
atf_check -s exit:2 \
|
||||
-o empty \
|
||||
-e not-empty \
|
||||
abuild-keygen INVALID
|
||||
}
|
||||
|
||||
abuild_keygen_non_interactive_body() {
|
||||
atf_check -s exit:0 \
|
||||
-o empty \
|
||||
-e match:"Generating RSA.*4096" \
|
||||
abuild-keygen -n
|
||||
}
|
||||
|
||||
abuild_keygen_append_body() {
|
||||
PACKAGER="Test User <user@example.com>" \
|
||||
atf_check -s exit:0 \
|
||||
\
|
||||
-o empty \
|
||||
-e match:"Generating RSA" \
|
||||
abuild-keygen --append -n
|
||||
grep '^PACKAGER_PRIVKEY=.*user@example.com' "$HOME"/.abuild/abuild.conf \
|
||||
|| atf_fail 'PACKAGER_PRIVKEY not set in abuild.conf'
|
||||
}
|
||||
|
||||
abuild_keygen_install_without_sudo_body() {
|
||||
SUDO=false \
|
||||
atf_check -s exit:1 \
|
||||
\
|
||||
-o empty \
|
||||
-e match:"Generating RSA" \
|
||||
abuild-keygen --install -n
|
||||
}
|
||||
|
||||
abuild_keygen_install_interactive_body() {
|
||||
echo | abuild_keygen_install_root="$PWD" SUDO= \
|
||||
atf_check -s exit:0 \
|
||||
\
|
||||
-o match:"Enter file" \
|
||||
-e match:"Generating RSA" \
|
||||
abuild-keygen --install
|
||||
}
|
||||
|
||||
abuild_keygen_install_non_interactive_body() {
|
||||
abuild_keygen_install_root="$PWD" SUDO= \
|
||||
atf_check -s exit:0 \
|
||||
\
|
||||
-o empty \
|
||||
-e match:"Generating RSA" \
|
||||
abuild-keygen --install -n
|
||||
}
|
Loading…
Reference in New Issue
Block a user