mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-12-19 18:05:02 -07:00
778ab34a6f
* Create `plugins.New` function, updating existing code to use it * Add another test for `hook.Run` function * Enable `plugin_add_command.bats` tests for Go implementation of asdf * Add `RunCallback` method to `Plugin` struct * Update `plugins.Add` function to run `post-plugin-add` plugin callback script * Handle Bash expression and scripts properly in `execute` package so `$@` is always set
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package hook
|
|
|
|
import (
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"asdf/config"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRun(t *testing.T) {
|
|
// Set the asdf config file location to the test file
|
|
t.Setenv("ASDF_CONFIG_FILE", "testdata/asdfrc")
|
|
|
|
t.Run("accepts config, hook name, and a slice of string arguments", func(t *testing.T) {
|
|
config, err := config.LoadConfig()
|
|
assert.Nil(t, err)
|
|
|
|
err = Run(config, "pre_asdf_plugin_add_test", []string{})
|
|
assert.Nil(t, err)
|
|
})
|
|
|
|
t.Run("passes argument to command", func(t *testing.T) {
|
|
config, err := config.LoadConfig()
|
|
assert.Nil(t, err)
|
|
|
|
err = Run(config, "pre_asdf_plugin_add_test2", []string{"123"})
|
|
assert.Equal(t, 123, err.(*exec.ExitError).ExitCode())
|
|
})
|
|
|
|
t.Run("passes arguments to command", func(t *testing.T) {
|
|
config, err := config.LoadConfig()
|
|
assert.Nil(t, err)
|
|
|
|
err = Run(config, "pre_asdf_plugin_add_test3", []string{"exit 123"})
|
|
assert.Equal(t, 123, err.(*exec.ExitError).ExitCode())
|
|
})
|
|
|
|
t.Run("does not return error when no such hook is defined in asdfrc", func(t *testing.T) {
|
|
config, err := config.LoadConfig()
|
|
assert.Nil(t, err)
|
|
|
|
err = Run(config, "nonexistant-hook", []string{})
|
|
assert.Nil(t, err)
|
|
})
|
|
}
|