2017-08-31 20:21:09 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-01-28 03:57:39 -07:00
|
|
|
bats_require_minimum_version 1.7.0
|
|
|
|
|
2020-03-02 10:44:31 -07:00
|
|
|
# shellcheck source=lib/utils.bash
|
|
|
|
. "$(dirname "$BATS_TEST_DIRNAME")"/lib/utils.bash
|
2016-06-28 20:56:33 -07:00
|
|
|
|
|
|
|
setup_asdf_dir() {
|
2023-03-24 05:37:23 -07:00
|
|
|
if [ "$BATS_TEST_NAME" = 'test_shim_exec_should_use_path_executable_when_specified_version_path-3a-3cpath-3e' ]; then
|
2024-06-04 18:03:03 -07:00
|
|
|
BASE_DIR="$BASE_DIR/asdf_with_no_spaces"
|
2021-07-19 21:21:39 -07:00
|
|
|
else
|
2024-06-04 18:03:03 -07:00
|
|
|
BASE_DIR="$BASE_DIR/w space${BATS_TEST_NAME}"
|
2021-07-19 21:21:39 -07:00
|
|
|
fi
|
2023-03-24 05:37:23 -07:00
|
|
|
|
2024-03-07 12:15:24 -07:00
|
|
|
# We don't call mktemp anymore so we need to create this sub directory manually
|
|
|
|
mkdir "$BASE_DIR"
|
|
|
|
|
2024-02-10 17:25:42 -07:00
|
|
|
# HOME is now defined by the Golang test code in main_test.go
|
2024-06-04 18:03:03 -07:00
|
|
|
HOME="$BASE_DIR/home"
|
|
|
|
export HOME
|
|
|
|
ASDF_DIR="$HOME/.asdf"
|
2017-08-31 20:21:09 -07:00
|
|
|
mkdir -p "$ASDF_DIR/plugins"
|
|
|
|
mkdir -p "$ASDF_DIR/installs"
|
|
|
|
mkdir -p "$ASDF_DIR/shims"
|
|
|
|
mkdir -p "$ASDF_DIR/tmp"
|
2024-02-10 17:25:42 -07:00
|
|
|
# ASDF_BIN is now defined by the Golang test code in main_test.go
|
|
|
|
#ASDF_BIN="$(dirname "$BATS_TEST_DIRNAME")/bin"
|
2019-01-21 00:33:52 -07:00
|
|
|
|
2024-06-04 18:03:03 -07:00
|
|
|
ASDF_DATA_DIR="$BASE_DIR/.asdf"
|
|
|
|
export ASDF_DATA_DIR
|
|
|
|
|
2024-03-19 17:55:57 -07:00
|
|
|
# shellcheck disable=SC2031,SC2153
|
2021-07-19 21:21:39 -07:00
|
|
|
PATH="$ASDF_BIN:$ASDF_DIR/shims:$PATH"
|
2016-06-28 20:56:33 -07:00
|
|
|
}
|
|
|
|
|
2017-08-18 21:56:28 -07:00
|
|
|
install_mock_plugin() {
|
|
|
|
local plugin_name=$1
|
2018-09-18 17:21:46 -07:00
|
|
|
local location="${2:-$ASDF_DIR}"
|
|
|
|
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin" "$location/plugins/$plugin_name"
|
2017-08-18 21:56:28 -07:00
|
|
|
}
|
|
|
|
|
2024-01-09 06:06:35 -07:00
|
|
|
install_mock_plugin_no_download() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local location="${2:-$ASDF_DIR}"
|
|
|
|
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin_no_download" "$location/plugins/$plugin_name"
|
|
|
|
}
|
|
|
|
|
2020-03-06 17:13:53 -07:00
|
|
|
install_mock_legacy_plugin() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local location="${2:-$ASDF_DIR}"
|
|
|
|
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_legacy_plugin" "$location/plugins/$plugin_name"
|
|
|
|
}
|
|
|
|
|
2021-05-19 02:51:45 -07:00
|
|
|
install_mock_broken_plugin() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local location="${2:-$ASDF_DIR}"
|
|
|
|
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_broken_plugin" "$location/plugins/$plugin_name"
|
|
|
|
}
|
|
|
|
|
2020-03-21 06:59:33 -07:00
|
|
|
install_mock_plugin_repo() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local location="${BASE_DIR}/repo-${plugin_name}"
|
|
|
|
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugin" "${location}"
|
|
|
|
git -C "${location}" init -q
|
2020-03-21 07:12:01 -07:00
|
|
|
git -C "${location}" config user.name "Test"
|
|
|
|
git -C "${location}" config user.email "test@example.com"
|
2020-03-21 06:59:33 -07:00
|
|
|
git -C "${location}" add -A
|
2021-03-01 23:37:05 -07:00
|
|
|
git -C "${location}" commit -q -m "asdf ${plugin_name} plugin"
|
2020-03-21 06:59:33 -07:00
|
|
|
}
|
|
|
|
|
2017-08-18 21:56:28 -07:00
|
|
|
install_mock_plugin_version() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local plugin_version=$2
|
2018-09-18 17:21:46 -07:00
|
|
|
local location="${3:-$ASDF_DIR}"
|
|
|
|
mkdir -p "$location/installs/$plugin_name/$plugin_version"
|
2017-08-18 21:56:28 -07:00
|
|
|
}
|
|
|
|
|
2016-06-28 20:56:33 -07:00
|
|
|
install_dummy_plugin() {
|
2017-08-18 21:56:28 -07:00
|
|
|
install_mock_plugin "dummy"
|
2016-06-28 20:56:33 -07:00
|
|
|
}
|
|
|
|
|
2024-01-09 06:06:35 -07:00
|
|
|
install_dummy_plugin_no_download() {
|
|
|
|
install_mock_plugin_no_download "dummy-no-download" "$1"
|
|
|
|
}
|
|
|
|
|
2020-03-06 17:13:53 -07:00
|
|
|
install_dummy_legacy_plugin() {
|
|
|
|
install_mock_legacy_plugin "legacy-dummy"
|
|
|
|
}
|
|
|
|
|
2021-05-19 02:51:45 -07:00
|
|
|
install_dummy_broken_plugin() {
|
|
|
|
install_mock_broken_plugin "dummy-broken"
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:15:05 -07:00
|
|
|
install_dummy_version() {
|
2017-08-18 21:56:28 -07:00
|
|
|
install_mock_plugin_version "dummy" "$1"
|
2016-07-23 00:15:05 -07:00
|
|
|
}
|
|
|
|
|
2021-07-06 19:51:19 -07:00
|
|
|
install_dummy_legacy_version() {
|
|
|
|
install_mock_plugin_version "legacy-dummy" "$1"
|
|
|
|
}
|
|
|
|
|
2019-01-05 08:54:02 -07:00
|
|
|
install_dummy_exec_path_script() {
|
|
|
|
local name=$1
|
|
|
|
local exec_path="$ASDF_DIR/plugins/dummy/bin/exec-path"
|
|
|
|
local custom_dir="$ASDF_DIR/installs/dummy/1.0/bin/custom"
|
|
|
|
mkdir "$custom_dir"
|
|
|
|
touch "$custom_dir/$name"
|
|
|
|
chmod +x "$custom_dir/$name"
|
2019-01-20 13:02:22 -07:00
|
|
|
echo "echo 'bin/custom/$name'" >"$exec_path"
|
2019-01-05 08:54:02 -07:00
|
|
|
chmod +x "$exec_path"
|
|
|
|
}
|
|
|
|
|
2016-06-28 20:56:33 -07:00
|
|
|
clean_asdf_dir() {
|
2017-08-31 20:21:09 -07:00
|
|
|
rm -rf "$BASE_DIR"
|
2016-06-28 20:56:33 -07:00
|
|
|
unset ASDF_DIR
|
2018-09-18 17:21:46 -07:00
|
|
|
unset ASDF_DATA_DIR
|
2016-06-28 20:56:33 -07:00
|
|
|
}
|
2017-08-24 19:29:23 -07:00
|
|
|
|
|
|
|
setup_repo() {
|
2017-10-02 06:51:07 -07:00
|
|
|
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugins_repo" "$ASDF_DIR/repository"
|
2017-08-24 19:29:23 -07:00
|
|
|
touch "$(asdf_dir)/tmp/repo-updated"
|
|
|
|
}
|