Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,18 @@ func pluginTestCommand(l *log.Logger, args []string, toolVersion, ref string) {
failTest(l, "list-all did not return any version")
}

// grab first version returned by list-all callback if no version provided as
// a CLI argument
// Resolve version: if empty use first from list-all; if "latest" or
// "latest:<query>" resolve via the plugin's latest-stable callback.
if toolVersion == "" {
toolVersion = allVersions[0]
} else if toolVersion == "latest" || strings.HasPrefix(toolVersion, "latest:") {
query := strings.TrimPrefix(toolVersion, "latest")
query = strings.TrimPrefix(query, ":")
resolved, err := versions.Latest(plugin, query)
if err != nil || resolved == "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This || resolved == "" check should not be needed.

failTest(l, "could not get latest version")
}
toolVersion = resolved
}

err = versions.InstallOneVersion(conf, plugin, toolVersion, false, os.Stdout, os.Stderr)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/dummy_plugin/bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# We want certain versions to fail installation for various reasons in the tests
check_dummy_versions() {
local bad_versions=" other-dummy "
local bad_versions=" other-dummy latest "
if [[ "$bad_versions" == *" $ASDF_INSTALL_VERSION "* ]]; then
echo "Dummy couldn't install version: $ASDF_INSTALL_VERSION (on purpose)"
exit 1
Expand Down
5 changes: 5 additions & 0 deletions test/plugin_test_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ teardown() {
run asdf plugin test dummy "${BASE_DIR}/repo-dummy" --asdf-tool-version 1.0.0 --asdf-plugin-gitref master
[ "$status" -eq 0 ]
}

@test "plugin_test_command resolves latest version when --asdf-tool-version latest is provided" {
run asdf plugin test dummy "${BASE_DIR}/repo-dummy" --asdf-tool-version latest
[ "$status" -eq 0 ]
}