2020-09-26 21:10:26 -07:00
#!/usr/bin/env bats
load test_helpers
setup() {
2021-03-01 23:37:05 -07:00
setup_asdf_dir
install_mock_plugin_repo "dummy"
2021-07-29 15:49:01 -07:00
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
2020-09-26 21:10:26 -07:00
}
teardown() {
clean_asdf_dir
}
2024-12-16 06:04:17 -07:00
@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin" {
run asdf plugin update dummy
2021-03-01 23:37:05 -07:00
repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
2024-12-16 06:04:17 -07:00
[[ "$output" =~ "updated dummy to ref refs/heads/master"* ]]
2021-03-01 23:37:05 -07:00
[ "$repo_head" = "master" ]
}
2024-12-16 06:04:17 -07:00
#@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if default branch changes" {
# install_mock_plugin_repo "dummy-remote"
# remote_dir="$BASE_DIR/repo-dummy-remote"
# # set HEAD to refs/head/main in dummy-remote
# git -C "${remote_dir}" checkout -b main
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote remove origin
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote add origin "$remote_dir"
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" fetch origin
# run asdf plugin update dummy
# repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
# [ "$status" -eq 0 ]
# [[ "$output" =~ "Updating dummy to main"* ]]
# [ "$repo_head" = "main" ]
#}
#@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if the default branch contains a forward slash" {
# install_mock_plugin_repo "dummy-remote"
# remote_dir="$BASE_DIR/repo-dummy-remote"
# # set HEAD to refs/head/my/default in dummy-remote
# git -C "${remote_dir}" checkout -b my/default
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote remove origin
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote add origin "$remote_dir"
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" fetch origin
# run asdf plugin update dummy
# repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
# [ "$status" -eq 0 ]
# [[ "$output" =~ "Updating dummy to my/default"* ]]
# [ "$repo_head" = "my/default" ]
#}
#@test "asdf plugin update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if already set to specific ref" {
# # set plugin to specific sha
# current_sha="$(git --git-dir "${BASE_DIR}/repo-dummy/.git" --work-tree "$BASE_DIR/repo-dummy" rev-parse HEAD)"
# run asdf plugin update dummy "${current_sha}"
# # setup mock plugin remote
# install_mock_plugin_repo "dummy-remote"
# remote_dir="$BASE_DIR/repo-dummy-remote"
# # set HEAD to refs/head/main in dummy-remote
# git -C "${remote_dir}" checkout -b main
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote remove origin
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote add origin "$remote_dir"
# git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" fetch origin
# # update plugin to the default branch
# run asdf plugin update dummy
# repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
# [ "$status" -eq 0 ]
# [[ "$output" =~ "Updating dummy to main"* ]]
# [ "$repo_head" = "main" ]
#}
@test "asdf plugin update should not remove plugin versions" {
2020-09-26 21:10:26 -07:00
run asdf install dummy 1.1
[ "$status" -eq 0 ]
[ "$(cat "$ASDF_DIR/installs/dummy/1.1/version")" = "1.1" ]
2024-12-16 06:04:17 -07:00
run asdf plugin update dummy
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/installs/dummy/1.1/version" ]
2024-12-16 06:04:17 -07:00
run asdf plugin update --all
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/installs/dummy/1.1/version" ]
}
2024-12-16 06:04:17 -07:00
@test "asdf plugin update should not remove plugins" {
2020-09-26 21:10:26 -07:00
# dummy plugin is already installed
2024-12-16 06:04:17 -07:00
run asdf plugin update dummy
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
[ -d "$ASDF_DIR/plugins/dummy" ]
2024-12-16 06:04:17 -07:00
run asdf plugin update --all
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
[ -d "$ASDF_DIR/plugins/dummy" ]
}
2024-12-16 06:04:17 -07:00
@test "asdf plugin update should not remove shims" {
2020-09-26 21:10:26 -07:00
run asdf install dummy 1.1
[ -f "$ASDF_DIR/shims/dummy" ]
2024-12-16 06:04:17 -07:00
run asdf plugin update dummy
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/shims/dummy" ]
2024-12-16 06:04:17 -07:00
run asdf plugin update --all
2020-09-26 21:10:26 -07:00
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/shims/dummy" ]
}
2021-09-14 06:44:53 -07:00
2024-12-16 06:04:17 -07:00
# TODO: Get these tests passing
#@test "asdf plugin update done for all plugins" {
# local command="asdf plugin update --all"
# # Count the number of update processes remaining after the update command is completed.
# run bash -c "${command} >/dev/null && ps -o 'ppid,args' | awk '{if(\$1==1 && \$0 ~ /${command}/ ) print}' | wc -l"
# [[ 0 -eq "$output" ]]
#}
#@test "asdf plugin update executes post-plugin update script" {
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# run asdf plugin update dummy
# new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
# [[ "$output" = *"${expected_output}" ]]
#}
#@test "asdf plugin update executes post-plugin update script if git-ref updated" {
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# # setup mock plugin remote
# install_mock_plugin_repo "dummy-remote"
# remote_dir="$BASE_DIR/repo-dummy-remote"
# # set HEAD to refs/head/main in dummy-remote
# git -C "${remote_dir}" checkout -b main
# # track & fetch remote repo (dummy-remote) in plugin (dummy)
# git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" remote remove origin
# git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" remote add origin "$remote_dir"
# git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" fetch origin
# # update plugin to the default branch
# run asdf plugin update dummy
# new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
# [[ "$output" = *"${expected_output}" ]]
#}
#@test "asdf plugin update executes configured pre hook (generic)" {
# cat >"$HOME/.asdfrc" <<-'EOM'
#pre_asdf_plugin_update = echo UPDATE ${@}
#EOM
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# run asdf plugin update dummy
# new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
# [[ "$output" = *"UPDATE dummy"*"${expected_output}" ]]
#}
#@test "asdf plugin update executes configured pre hook (specific)" {
# cat >"$HOME/.asdfrc" <<-'EOM'
#pre_asdf_plugin_update_dummy = echo UPDATE
#EOM
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# run asdf plugin update dummy
# new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
# [[ "$output" = *"UPDATE"*"${expected_output}" ]]
#}
#@test "asdf plugin update executes configured post hook (generic)" {
# cat >"$HOME/.asdfrc" <<-'EOM'
#post_asdf_plugin_update = echo UPDATE ${@}
#EOM
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# run asdf plugin update dummy
# new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}
#UPDATE dummy"
# [[ "$output" = *"${expected_output}" ]]
#}
#@test "asdf plugin update executes configured post hook (specific)" {
# cat >"$HOME/.asdfrc" <<-'EOM'
#post_asdf_plugin_update_dummy = echo UPDATE
#EOM
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# run asdf plugin update dummy
# new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}
#UPDATE
#updated dummy to ref refs/heads/master"
# [[ "$output" = *"${expected_output}" ]]
#}
# No longer supported
#@test "asdf plugin update prints the location of plugin (specific)" {
# local plugin_path
# plugin_path="$(get_plugin_path dummy)"
# run asdf plugin update dummy
# local expected_output="Location of dummy plugin: $plugin_path"
# [[ "$output" == *"$expected_output"* ]]
#}