Skip to content

Commit

Permalink
feat: provide sensitive defaults for v2 tools (#302)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
Chumper and viceice authored Feb 14, 2022
1 parent e0b224a commit fd5b636
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/usr/local/buildpack/utils/v2/defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@

# Is used to check if all requirements are met to install the tool
function check_tool_requirements () {
echo "'check_tool_requirements' not defined for tool ${TOOL_NAME}"
exit 1
# Sensitive default that can be overwritten by tools if needed
check_semver "${TOOL_VERSION}"
if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then
echo Invalid version: "${TOOL_VERSION}"
exit 1
fi
}

# Is used to check if the tool has already been installed in the given version
function check_tool_installed () {
echo "'check_tool_installed' not defined for tool ${TOOL_NAME}"
exit 1
# Sensitive default that can be overwritten by tools if needed
test -n "$(find_versioned_tool_path)"
}

# Installs the tool with the given version
Expand Down
22 changes: 20 additions & 2 deletions test/bash/v2/defaults.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,29 @@ teardown() {

run check_tool_requirements
assert_failure
assert_output --partial "not defined"
assert_output --partial "Not a semver like version"

TOOL_VERSION=1.2.3
run check_tool_requirements
assert_success

run check_tool_installed
assert_failure
assert_output --partial "not defined"

TOOL_NAME=foo \
TOOL_VERSION=1.2.3
run check_tool_installed
assert_failure

TOOL_NAME=foo \
TOOL_VERSION=1.2.3
run create_versioned_tool_path
assert_success

TOOL_NAME=foo \
TOOL_VERSION=1.2.3
run check_tool_installed
assert_success

run install_tool
assert_failure
Expand Down

0 comments on commit fd5b636

Please sign in to comment.