Skip to content

Commit

Permalink
Test install from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
KonishchevDmitry committed Nov 22, 2024
1 parent b38e962 commit 188994b
Showing 1 changed file with 56 additions and 14 deletions.
70 changes: 56 additions & 14 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ temp_dir="$(mktemp -d "/var/tmp/binup-test.XXXXXX")"

tool=binup
project="KonishchevDmitry/$tool"
binary_matcher="$tool"
changelog="https://github.com/$project/releases"
install_path="$temp_dir/bin"
custom_install_path="$temp_dir/custom-bin"
post_install_marker_path="$temp_dir/post-install-marker"
post_command="touch '$post_install_marker_path' && echo 'Post-install script stdout' && echo 'Post-install script stderr' >&2"

if [ "$(uname)" = Darwin ]; then
release_matcher="$tool-macos-arm64-*"
Expand Down Expand Up @@ -48,7 +54,7 @@ EOF
touch -c -d 2024-08-01T00:00:00 old-release-mock

cat > "config.yaml" <<EOF
path: $temp_dir/bin
path: $install_path
tools:
$tool:
Expand All @@ -60,27 +66,53 @@ tools:
upgradable:
project: $project
release_matcher: $release_matcher
binary_matcher: $tool
changelog: https://github.com/$project/releases
path: $temp_dir/custom-bin
post: touch $temp_dir/post-install-marker && echo "Post-install script stdout" && echo "Post-install script stderr" >&2
binary_matcher: $binary_matcher
changelog: $changelog
path: $custom_install_path
post: $post_command
$github_config
EOF
)

config_path="$temp_dir/config.yaml"
shasum "$config_path" > "$config_path.checksum"

run() {
cargo run --quiet -- --config "$temp_dir/config.yaml" "$@"
cargo run --quiet -- --config "$config_path" "$@"
}

ensure_post_install_marker() {
rm "$@"
}

ensure_no_post_install_marker() {
if [ -e "$1" ]; then
echo "An unexpected call of post-install command ($1 marker)." >&2
return 1
fi
}

# Test work with missing default config
cargo run --quiet -- list

# List with no installed tools
run list

# Should install the tool, but not change the config (fully matches)
for pass in ensure_post_install_marker ensure_no_post_install_marker; do
run install upgradable --project "$project" \
--release-matcher "$release_matcher" --binary-matcher "$binary_matcher" --changelog "$changelog" \
--path "$custom_install_path" --post "$post_command" < /dev/null

"$custom_install_path/upgradable" --help > /dev/null
"$pass" "$post_install_marker_path"
shasum -c "$config_path.checksum" > /dev/null
done

for command in install "install --force" upgrade; do
cp -a "$temp_dir/new-release-mock" "$temp_dir/bin/up-to-date"
cp -a "$temp_dir/old-release-mock" "$temp_dir/custom-bin/upgradable"
cp -a "$temp_dir/new-release-mock" "$install_path/up-to-date"
cp -a "$temp_dir/old-release-mock" "$custom_install_path/upgradable"

run $command

Expand All @@ -97,18 +129,28 @@ for command in install "install --force" upgrade; do

if [ "$command" = install ]; then
shasum "bin/$tool" > checksum

cmp custom-bin/upgradable old-release-mock
if [ -e post-install-marker ]; then
echo "An unexpected call of post-install script." >&2
exit 1
fi
ensure_no_post_install_marker "$post_install_marker_path"
else
shasum -c checksum > /dev/null
cmp custom-bin/upgradable "bin/$tool"
rm post-install-marker
ensure_post_install_marker "$post_install_marker_path"
fi
)
done

# Should update existing entry, but not reinstall
updated_post_install_marker="$temp_dir/updated-post-install-marker"
yes | run install --project "$project" --post "touch '$updated_post_install_marker'"
ensure_no_post_install_marker "$updated_post_install_marker"

# Should add a new entry and install
new_post_install_marker="$temp_dir/new-post-install-marker"
run install new --project "$project" --post "touch '$new_post_install_marker'"
ensure_post_install_marker "$new_post_install_marker"

# Ensure persistence of the changes
run install --force "$tool" && ensure_post_install_marker "$updated_post_install_marker"
run install --force new && ensure_post_install_marker "$new_post_install_marker"

run list --full

0 comments on commit 188994b

Please sign in to comment.