2023-09-14 10:14:13 +00:00
|
|
|
package scripts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
2023-12-21 15:45:23 +00:00
|
|
|
"github.com/databricks/cli/libs/exec"
|
2023-09-14 10:14:13 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExecutesHook(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Experimental: &config.Experimental{
|
|
|
|
Scripts: map[config.ScriptHook]config.Command{
|
|
|
|
config.ScriptPreBuild: "echo 'Hello'",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-12-21 15:45:23 +00:00
|
|
|
|
|
|
|
executor, err := exec.NewCommandExecutor(b.Config.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, out, err := executeHook(context.Background(), executor, b, config.ScriptPreBuild)
|
2023-09-14 10:14:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
reader := bufio.NewReader(out)
|
|
|
|
line, err := reader.ReadString('\n')
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "Hello", strings.TrimSpace(line))
|
|
|
|
}
|
2024-02-26 10:08:03 +00:00
|
|
|
|
|
|
|
func TestExecuteMutator(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Experimental: &config.Experimental{
|
|
|
|
Scripts: map[config.ScriptHook]config.Command{
|
|
|
|
config.ScriptPreBuild: "echo 'Hello'",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := bundle.Apply(context.Background(), b, Execute(config.ScriptPreInit))
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|