mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-12-19 18:05:02 -07:00
Merge pull request #59 from asdf-vm/tb/install-cmd-bats-tests
feat(golang-rewrite): more work to get `install_command.bats` test passing
This commit is contained in:
commit
241485016d
@ -184,7 +184,8 @@ func pluginRemoveCommand(_ *cli.Context, logger *log.Logger, pluginName string)
|
|||||||
|
|
||||||
err = plugins.Remove(conf, pluginName)
|
err = plugins.Remove(conf, pluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Printf("error removing plugin: %s", err)
|
// Needed to match output of old version
|
||||||
|
logger.Printf("%s", err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -348,7 +349,7 @@ func latestCommand(logger *log.Logger, all bool, toolName, pattern string) (err
|
|||||||
|
|
||||||
plugins, err := plugins.List(conf, false, false)
|
plugins, err := plugins.List(conf, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Printf("error loading plugin list: %s", err, false)
|
logger.Printf("error loading plugin list: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ type Settings struct {
|
|||||||
AlwaysKeepDownload bool
|
AlwaysKeepDownload bool
|
||||||
PluginRepositoryLastCheckDuration PluginRepoCheckDuration
|
PluginRepositoryLastCheckDuration PluginRepoCheckDuration
|
||||||
DisablePluginShortNameRepository bool
|
DisablePluginShortNameRepository bool
|
||||||
|
Concurrency string
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultConfig(dataDir, configFile string) *Config {
|
func defaultConfig(dataDir, configFile string) *Config {
|
||||||
@ -154,6 +155,16 @@ func (c *Config) DisablePluginShortNameRepository() (bool, error) {
|
|||||||
return c.Settings.DisablePluginShortNameRepository, nil
|
return c.Settings.DisablePluginShortNameRepository, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Concurrency returns concurrency setting from asdfrc file
|
||||||
|
func (c *Config) Concurrency() (string, error) {
|
||||||
|
err := c.loadSettings()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Settings.Concurrency, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetHook returns a hook command from config if it is there
|
// GetHook returns a hook command from config if it is there
|
||||||
func (c *Config) GetHook(hook string) (string, error) {
|
func (c *Config) GetHook(hook string) (string, error) {
|
||||||
err := c.loadSettings()
|
err := c.loadSettings()
|
||||||
@ -227,6 +238,7 @@ func loadSettings(asdfrcPath string) (Settings, error) {
|
|||||||
boolOverride(&settings.LegacyVersionFile, mainConf, "legacy_version_file")
|
boolOverride(&settings.LegacyVersionFile, mainConf, "legacy_version_file")
|
||||||
boolOverride(&settings.AlwaysKeepDownload, mainConf, "always_keep_download")
|
boolOverride(&settings.AlwaysKeepDownload, mainConf, "always_keep_download")
|
||||||
boolOverride(&settings.DisablePluginShortNameRepository, mainConf, "disable_plugin_short_name_repository")
|
boolOverride(&settings.DisablePluginShortNameRepository, mainConf, "disable_plugin_short_name_repository")
|
||||||
|
settings.Concurrency = strings.ToLower(mainConf.Key("concurrency").String())
|
||||||
|
|
||||||
return *settings, nil
|
return *settings, nil
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,27 @@ const (
|
|||||||
noLatestVersionErrMsg = "no latest version found"
|
noLatestVersionErrMsg = "no latest version found"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UninstallableVersion is an error returned if someone tries to install the
|
// UninstallableVersionError is an error returned if someone tries to install the
|
||||||
// system version.
|
// system version.
|
||||||
type UninstallableVersion struct{}
|
type UninstallableVersionError struct{}
|
||||||
|
|
||||||
func (e UninstallableVersion) Error() string {
|
func (e UninstallableVersionError) Error() string {
|
||||||
return fmt.Sprint(uninstallableVersionMsg)
|
return fmt.Sprint(uninstallableVersionMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoVersionSetError is returned whenever an operation that requires a version
|
||||||
|
// is not able to resolve one.
|
||||||
|
type NoVersionSetError struct {
|
||||||
|
toolName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e NoVersionSetError) Error() string {
|
||||||
|
// Eventually switch this to a more friendly error message, BATS tests fail
|
||||||
|
// with this improvement
|
||||||
|
// return fmt.Sprintf("no version set for plugin %s", e.toolName)
|
||||||
|
return "no version set"
|
||||||
|
}
|
||||||
|
|
||||||
// InstallAll installs all specified versions of every tool for the current
|
// InstallAll installs all specified versions of every tool for the current
|
||||||
// directory. Typically this will just be a single version, if not already
|
// directory. Typically this will just be a single version, if not already
|
||||||
// installed, but it may be multiple versions if multiple versions for the tool
|
// installed, but it may be multiple versions if multiple versions for the tool
|
||||||
@ -74,7 +87,7 @@ func Install(conf config.Config, plugin plugins.Plugin, dir string, stdOut io.Wr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !found || len(versions.Versions) == 0 {
|
if !found || len(versions.Versions) == 0 {
|
||||||
return errors.New("no version set")
|
return NoVersionSetError{toolName: plugin.Name}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, version := range versions.Versions {
|
for _, version := range versions.Versions {
|
||||||
@ -114,7 +127,7 @@ func InstallOneVersion(conf config.Config, plugin plugins.Plugin, version string
|
|||||||
}
|
}
|
||||||
|
|
||||||
if version == systemVersion {
|
if version == systemVersion {
|
||||||
return UninstallableVersion{}
|
return UninstallableVersionError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadDir := downloadPath(conf, plugin, version)
|
downloadDir := downloadPath(conf, plugin, version)
|
||||||
@ -130,6 +143,7 @@ func InstallOneVersion(conf config.Config, plugin plugins.Plugin, version string
|
|||||||
"ASDF_INSTALL_VERSION": version,
|
"ASDF_INSTALL_VERSION": version,
|
||||||
"ASDF_INSTALL_PATH": installDir,
|
"ASDF_INSTALL_PATH": installDir,
|
||||||
"ASDF_DOWNLOAD_PATH": downloadDir,
|
"ASDF_DOWNLOAD_PATH": downloadDir,
|
||||||
|
"ASDF_CONCURRENCY": asdfConcurrency(conf),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(downloadDir, 0o777)
|
err = os.MkdirAll(downloadDir, 0o777)
|
||||||
@ -169,6 +183,21 @@ func InstallOneVersion(conf config.Config, plugin plugins.Plugin, version string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func asdfConcurrency(conf config.Config) string {
|
||||||
|
val, ok := os.LookupEnv("ASDF_CONCURRENCY")
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
val, err := conf.Concurrency()
|
||||||
|
if err != nil {
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
// Installed checks if a specific version of a tool is installed
|
// Installed checks if a specific version of a tool is installed
|
||||||
func Installed(conf config.Config, plugin plugins.Plugin, version string) bool {
|
func Installed(conf config.Config, plugin plugins.Plugin, version string) bool {
|
||||||
installDir := installPath(conf, plugin, version)
|
installDir := installPath(conf, plugin, version)
|
||||||
|
@ -168,7 +168,7 @@ func TestInstallOneVersion(t *testing.T) {
|
|||||||
conf, plugin := generateConfig(t)
|
conf, plugin := generateConfig(t)
|
||||||
stdout, stderr := buildOutputs()
|
stdout, stderr := buildOutputs()
|
||||||
err := InstallOneVersion(conf, plugin, "system", &stdout, &stderr)
|
err := InstallOneVersion(conf, plugin, "system", &stdout, &stderr)
|
||||||
assert.IsType(t, UninstallableVersion{}, err)
|
assert.IsType(t, UninstallableVersionError{}, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns error when version doesn't exist", func(t *testing.T) {
|
t.Run("returns error when version doesn't exist", func(t *testing.T) {
|
||||||
|
@ -55,9 +55,9 @@ func TestBatsTests(t *testing.T) {
|
|||||||
// runBatsFile(t, dir, "plugin_list_all_command.bats")
|
// runBatsFile(t, dir, "plugin_list_all_command.bats")
|
||||||
//})
|
//})
|
||||||
|
|
||||||
//t.Run("plugin_remove_command", func(t *testing.T) {
|
t.Run("plugin_remove_command", func(t *testing.T) {
|
||||||
// runBatsFile(t, dir, "plugin_remove_command.bats")
|
runBatsFile(t, dir, "plugin_remove_command.bats")
|
||||||
//})
|
})
|
||||||
|
|
||||||
//t.Run("plugin_test_command", func(t *testing.T) {
|
//t.Run("plugin_test_command", func(t *testing.T) {
|
||||||
// runBatsFile(t, dir, "plugin_test_command.bats")
|
// runBatsFile(t, dir, "plugin_test_command.bats")
|
||||||
|
@ -305,7 +305,7 @@ func Remove(config config.Config, pluginName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return fmt.Errorf("no such plugin: %s", pluginName)
|
return fmt.Errorf("No such plugin: %s", pluginName)
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginDir := PluginDirectory(config.DataDir, pluginName)
|
pluginDir := PluginDirectory(config.DataDir, pluginName)
|
||||||
|
@ -182,7 +182,7 @@ func TestRemove(t *testing.T) {
|
|||||||
t.Run("returns error when plugin with name does not exist", func(t *testing.T) {
|
t.Run("returns error when plugin with name does not exist", func(t *testing.T) {
|
||||||
err := Remove(conf, "nonexistant")
|
err := Remove(conf, "nonexistant")
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
assert.ErrorContains(t, err, "no such plugin")
|
assert.ErrorContains(t, err, "No such plugin")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns error when invalid plugin name is given", func(t *testing.T) {
|
t.Run("returns error when invalid plugin name is given", func(t *testing.T) {
|
||||||
|
@ -16,13 +16,13 @@ teardown() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ -d "$ASDF_DIR/downloads/dummy" ]
|
[ -d "$ASDF_DIR/downloads/dummy" ]
|
||||||
|
|
||||||
run asdf plugin-remove "dummy"
|
run asdf plugin remove "dummy"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ ! -d "$ASDF_DIR/downloads/dummy" ]
|
[ ! -d "$ASDF_DIR/downloads/dummy" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "plugin_remove command fails if the plugin doesn't exist" {
|
@test "plugin_remove command fails if the plugin doesn't exist" {
|
||||||
run asdf plugin-remove "does-not-exist"
|
run asdf plugin remove "does-not-exist"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
echo "$output" | grep "No such plugin: does-not-exist"
|
echo "$output" | grep "No such plugin: does-not-exist"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user