mirror of https://github.com/databricks/cli.git
Compare commits
2 Commits
dd506e2372
...
26afab2ccb
Author | SHA1 | Date |
---|---|---|
|
26afab2ccb | |
|
edff68c763 |
|
@ -163,7 +163,7 @@ func (t *translateContext) translateNoOp(literal, localFullPath, localRelPath, r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, localRelPath, remotePath string) (string, error) {
|
func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, localRelPath, remotePath string) (string, error) {
|
||||||
info, err := t.b.SyncRoot.Stat(localRelPath)
|
info, err := t.b.SyncRoot.Stat(filepath.ToSlash(localRelPath))
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return "", fmt.Errorf("file %s not found", literal)
|
return "", fmt.Errorf("file %s not found", literal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package mutator_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/databricks/cli/bundle"
|
||||||
|
"github.com/databricks/cli/bundle/config"
|
||||||
|
"github.com/databricks/cli/bundle/config/mutator"
|
||||||
|
"github.com/databricks/cli/bundle/config/resources"
|
||||||
|
"github.com/databricks/cli/bundle/internal/bundletest"
|
||||||
|
"github.com/databricks/cli/libs/dyn"
|
||||||
|
"github.com/databricks/cli/libs/vfs"
|
||||||
|
"github.com/databricks/databricks-sdk-go/service/dashboards"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTranslatePathsDashboards_FilePathRelativeSubDirectory(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
touchEmptyFile(t, filepath.Join(dir, "src", "my_dashboard.lvdash.json"))
|
||||||
|
|
||||||
|
b := &bundle.Bundle{
|
||||||
|
SyncRootPath: dir,
|
||||||
|
SyncRoot: vfs.MustNew(dir),
|
||||||
|
Config: config.Root{
|
||||||
|
Resources: config.Resources{
|
||||||
|
Dashboards: map[string]*resources.Dashboard{
|
||||||
|
"dashboard": {
|
||||||
|
CreateDashboardRequest: &dashboards.CreateDashboardRequest{
|
||||||
|
DisplayName: "My Dashboard",
|
||||||
|
},
|
||||||
|
FilePath: "../src/my_dashboard.lvdash.json",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
bundletest.SetLocation(b, "resources.dashboards", []dyn.Location{{
|
||||||
|
File: filepath.Join(dir, "resources/dashboard.yml"),
|
||||||
|
}})
|
||||||
|
|
||||||
|
diags := bundle.Apply(context.Background(), b, mutator.TranslatePaths())
|
||||||
|
require.NoError(t, diags.Error())
|
||||||
|
|
||||||
|
// Assert that the file path for the dashboard has been converted to its local absolute path.
|
||||||
|
assert.Equal(
|
||||||
|
t,
|
||||||
|
filepath.Join(dir, "src", "my_dashboard.lvdash.json"),
|
||||||
|
b.Config.Resources.Dashboards["dashboard"].FilePath,
|
||||||
|
)
|
||||||
|
}
|
|
@ -35,17 +35,23 @@ func promptRunArgument(ctx context.Context, b *bundle.Bundle) (string, error) {
|
||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, error) {
|
// resolveRunArgument resolves the resource key to run.
|
||||||
|
// It returns the remaining arguments to pass to the runner, if applicable.
|
||||||
|
func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, []string, error) {
|
||||||
// If no arguments are specified, prompt the user to select something to run.
|
// If no arguments are specified, prompt the user to select something to run.
|
||||||
if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
|
if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
|
||||||
return promptRunArgument(ctx, b)
|
key, err := promptRunArgument(ctx, b)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
return key, args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return "", fmt.Errorf("expected a KEY of the resource to run")
|
return "", nil, fmt.Errorf("expected a KEY of the resource to run")
|
||||||
}
|
}
|
||||||
|
|
||||||
return args[0], nil
|
return args[0], args[1:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
|
func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
|
||||||
|
@ -109,7 +115,7 @@ task or a Python wheel task, the second example applies.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
arg, err := resolveRunArgument(ctx, b, args)
|
key, args, err := resolveRunArgument(ctx, b, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -124,13 +130,13 @@ task or a Python wheel task, the second example applies.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
runner, err := keyToRunner(b, arg)
|
runner, err := keyToRunner(b, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse additional positional arguments.
|
// Parse additional positional arguments.
|
||||||
err = runner.ParseArgs(args[1:], &runOptions)
|
err = runner.ParseArgs(args, &runOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue