generated from demus/basic-rpm-template
Check for at least one of git or find and complain
This commit is contained in:
@@ -15,10 +15,13 @@ __find_sources() {
|
||||
DO_POP=1
|
||||
pushd "$(dirname $SOURCES_FILE)" > /dev/null || exit 98
|
||||
fi
|
||||
if [ -d .git ]; then
|
||||
if [ -d .git ] && which git &>/dev/null; then
|
||||
FILENAMES=$(git ls-files --exclude-standard | grep -v -e '^\.' -e sources)
|
||||
else
|
||||
elif which find &>/dev/null; then
|
||||
FILENAMES=$(find . -path "./RPMS" -prune -o -path "./BUILD" -prune -o -path "./SRPMS" -prune -o -path "./.*" -prune -o \( ! \( -name '*.spec' -o -name '.*' -o -name sources \) -a -type f \) -printf ' %P')
|
||||
else
|
||||
echo "No way to search for relevant source files was found. Please install find (and git if this is a git repository directory)."
|
||||
exit 97
|
||||
fi
|
||||
if [[ "$DO_POP" -eq 1 ]]; then
|
||||
popd > /dev/null || echo $FILENAMES
|
||||
@@ -173,7 +176,10 @@ _update_sources() {
|
||||
echo No relevant sources found. Skipping checksumming.
|
||||
return 0
|
||||
fi
|
||||
cksum -a sha512 $SOURCES > "${SOURCES_FILE:-sources}"
|
||||
if ! cksum -a sha512 $SOURCES > "${SOURCES_FILE:-sources}"; then
|
||||
echo Sources checksum calculation failed
|
||||
exit 17
|
||||
fi
|
||||
|
||||
if [[ "$DO_POP" -eq 1 ]]; then
|
||||
popd > /dev/null || exit 98
|
||||
|
||||
@@ -200,7 +200,6 @@ License update failed"
|
||||
}
|
||||
|
||||
@test "When there are no relevant sources, checksumming is skipped" {
|
||||
stub cksum "exit 1"
|
||||
export UPDATE_SOURCES=1
|
||||
echo "Source: go-vendor-tools.toml" > $SPEC_FILE
|
||||
|
||||
@@ -211,6 +210,20 @@ License update failed"
|
||||
No relevant sources found. Skipping checksumming."
|
||||
}
|
||||
|
||||
@test "Sane feedback is proffered when cksum fails" {
|
||||
stub cksum "exit 1"
|
||||
export UPDATE_SOURCES=1
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
echo "Source: go-vendor-tools.toml" > $SPEC_FILE
|
||||
|
||||
run _update_sources
|
||||
|
||||
unstub cksum
|
||||
assert_failure 17
|
||||
assert_output - <<<"Calculating checksums
|
||||
Sources checksum calculation failed"
|
||||
}
|
||||
|
||||
# bats test_tags=find_sources
|
||||
@test "The list of files to include in sources excludes the correct things in a git repo" {
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
@@ -230,3 +243,15 @@ No relevant sources found. Skipping checksumming."
|
||||
assert_success
|
||||
assert_output "vendor.tar.bz2 v1.0.0.tar.gz README.md LICENSE data/somedata.csv data/README changelog"
|
||||
}
|
||||
|
||||
# bats test_tags=find_sources
|
||||
@test "If neither git or find are installed you get an error and explanation" {
|
||||
stub which "return 1" "return 1"
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
|
||||
run __find_sources
|
||||
|
||||
unstub which
|
||||
assert_failure 97
|
||||
assert_output "No way to search for relevant source files was found. Please install find (and git if this is a git repository directory)."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user