Skip to content

Commit

Permalink
post_install.sh should work when run from any directory and be tested…
Browse files Browse the repository at this point in the history
… in test.sh
  • Loading branch information
mbautin committed Oct 21, 2019
1 parent 454e406 commit 79927a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
12 changes: 8 additions & 4 deletions brew-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,17 @@ get_fixed_length_path() {

# Use the Git SHA1 of the Homebrew repository as a filler.
if [[ -z $sha1 ]]; then
if [[ ! -d $path/.git ]]; then
fatal "Directory '$path' is not a Git repository, cannot get SHA1"
if [[ -f $path/GIT_SHA1 ]]; then
sha1=$( cat $path/GIT_SHA1 )
else
if [[ ! -d $path/.git ]]; then
fatal "Directory '$path' is not a Git repository, cannot get SHA1"
fi
sha1=$( cd "$path" && git rev-parse HEAD )
fi
sha1=$( cd "$path" && git rev-parse HEAD )
fi
if [[ ! $sha1 =~ ^[0-9a-f]{40}$ ]]; then
fatal "Invalid Git SHA1: '$sha1'"
fatal "Invalid Git SHA1: '$sha1', expected 40 hex characters"
fi

fixed_length_path=\
Expand Down
5 changes: 3 additions & 2 deletions post_install.template
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ fi
readonly orig_brew_home="{{ orig_brew_home }}"
declare -i -r ORIG_LEN=${#orig_brew_home}

brew_home=$PWD
brew_home=$script_dir
cd "$brew_home"
LEN=${#brew_home}
if [[ $LEN -gt $ORIG_LEN ]]; then
fatal "Homebrew/Linuxbrew absolute path should be no more than $ORIG_LEN bytes, but actual " \
fatal "Homebrew/Linuxbrew absolute path should be no more than $ORIG_LEN bytes, but actual" \
"length is $LEN bytes: $brew_home"
fi

Expand Down
35 changes: 31 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ cleanup() {
exit "$exit_code"
}

find_latest_brew_dir() {
latest_brew_dir=$(
ls -td $(
find . -mindepth 1 -maxdepth 1 -type d -name "$YB_BREW_TYPE_LOWERCASE-*"
) | head -1
)
if [[ ! -d $latest_brew_dir ]]; then
log "In directory $PWD, found latest brew directory: $latest_brew_dir"
( set -x; ls -l )
fatal "Unable to find the latest Homebrew/Linuxbrew installation in $PWD"
fi
latest_brew_dir=$( cd "$latest_brew_dir" && pwd )
}

# -------------------------------------------------------------------------------------------------
# Parsing command-line arguments
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -87,7 +101,7 @@ if [[ -z ${work_dir:-} ]]; then
tmp_dir=$HOME/tmp
mkdir -p "$tmp_dir"
fi
work_dir=$tmp_dir/ybbrewtest-$$-$(date +%Y-%m-%dT%H_%M_%S)
work_dir=$tmp_dir/ybbrewtst-$$-$(date +%Y%m%dT%H%M)
trap cleanup EXIT
fi
mkdir -p "$work_dir"
Expand All @@ -96,13 +110,26 @@ cd "$work_dir"
export YB_BREW_BUILD_UNIT_TEST_MODE=1
"$script_dir/brew-clone-and-build-all.sh"

find_latest_brew_dir
brew_home=$latest_brew_dir
log "Will use the directory $brew_home for further testing"

heading "Testing post_install.sh"

( set -x; cd /; rm -rf "$brew_home/.git"; "$brew_home/post_install.sh" )

heading "Testing brew-copy.sh"
brew_home=$(
find . -mindepth 1 -maxdepth 1 -type d -name "$YB_BREW_TYPE_LOWERCASE-*" | sort | head -1
)

if [[ -z $brew_home ]]; then
fatal "Could not find a subdirectory starting with '$YB_BREW_TYPE_LOWERCASE-' in $PWD"
fi
"$script_dir/brew-copy.sh" "$brew_home"

heading "Testing post_install.sh after brew-copy.sh"
find_latest_brew_dir
if [[ $latest_brew_dir == $brew_home ]]; then
fatal "brew-copy.sh failed to produce a new Homebrew/Linuxbrew directory in $PWD"
fi
( set -x; "$latest_brew_dir/post_install.sh" )

log "TEST SUCCEEDED"

0 comments on commit 79927a8

Please sign in to comment.