From fd5b6360501985c8cea9c122bab46389448a78c9 Mon Sep 17 00:00:00 2001 From: Nils Plaschke Date: Mon, 14 Feb 2022 17:27:17 +0100 Subject: [PATCH] feat: provide sensitive defaults for v2 tools (#302) Co-authored-by: Michael Kriese --- src/usr/local/buildpack/utils/v2/defaults.sh | 12 +++++++---- test/bash/v2/defaults.bats | 22 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/usr/local/buildpack/utils/v2/defaults.sh b/src/usr/local/buildpack/utils/v2/defaults.sh index 0fc77c71e..22211c566 100644 --- a/src/usr/local/buildpack/utils/v2/defaults.sh +++ b/src/usr/local/buildpack/utils/v2/defaults.sh @@ -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 diff --git a/test/bash/v2/defaults.bats b/test/bash/v2/defaults.bats index e500bd88e..50a066491 100644 --- a/test/bash/v2/defaults.bats +++ b/test/bash/v2/defaults.bats @@ -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