mirror of https://github.com/databricks/cli.git
Add error checking in tests and enable errcheck there (#1980)
## Changes Fix all errcheck-found issues in tests and test helpers. Mostly this done by adding require.NoError(t, err), sometimes panic() where t object is not available). Initial change is obtained with aider+claude, then manually reviewed and cleaned up. ## Tests Existing tests.
This commit is contained in:
parent
e0d54f0bb6
commit
1b2be1b2cb
|
@ -2,9 +2,7 @@ linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
- bodyclose
|
||||||
# errcheck and govet are part of default setup and should be included but give too many errors now
|
- errcheck
|
||||||
# once errors are fixed, they should be enabled here:
|
|
||||||
#- errcheck
|
|
||||||
- gosimple
|
- gosimple
|
||||||
#- govet
|
#- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
|
@ -20,3 +18,7 @@ linters-settings:
|
||||||
replacement: 'any'
|
replacement: 'any'
|
||||||
issues:
|
issues:
|
||||||
exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/
|
exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/
|
||||||
|
exclude-rules:
|
||||||
|
- path-except: (_test\.go|internal)
|
||||||
|
linters:
|
||||||
|
- errcheck
|
||||||
|
|
|
@ -110,7 +110,8 @@ func TestInitializeURLs(t *testing.T) {
|
||||||
"dashboard1": "https://mycompany.databricks.com/dashboardsv3/01ef8d56871e1d50ae30ce7375e42478/published?o=123456",
|
"dashboard1": "https://mycompany.databricks.com/dashboardsv3/01ef8d56871e1d50ae30ce7375e42478/published?o=123456",
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
|
err := initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
for _, group := range b.Config.Resources.AllResources() {
|
for _, group := range b.Config.Resources.AllResources() {
|
||||||
for key, r := range group.Resources {
|
for key, r := range group.Resources {
|
||||||
|
@ -133,7 +134,8 @@ func TestInitializeURLsWithoutOrgId(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeForWorkspace(b, "123456", "https://adb-123456.azuredatabricks.net/")
|
err := initializeForWorkspace(b, "123456", "https://adb-123456.azuredatabricks.net/")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
|
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,8 @@ func TestNoLookupIfVariableIsSet(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
b.SetWorkpaceClient(m.WorkspaceClient)
|
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||||
|
|
||||||
b.Config.Variables["my-cluster-id"].Set("random value")
|
err := b.Config.Variables["my-cluster-id"].Set("random value")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
diags := bundle.Apply(context.Background(), b, ResolveResourceReferences())
|
diags := bundle.Apply(context.Background(), b, ResolveResourceReferences())
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
|
|
|
@ -28,7 +28,8 @@ import (
|
||||||
func touchNotebookFile(t *testing.T, path string) {
|
func touchNotebookFile(t *testing.T, path string) {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
f.WriteString("# Databricks notebook source\n")
|
_, err = f.WriteString("# Databricks notebook source\n")
|
||||||
|
require.NoError(t, err)
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ func TestCustomMarshallerIsImplemented(t *testing.T) {
|
||||||
// Eg: resource.Job implements MarshalJSON
|
// Eg: resource.Job implements MarshalJSON
|
||||||
v := reflect.Zero(vt.Elem()).Interface()
|
v := reflect.Zero(vt.Elem()).Interface()
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
json.Marshal(v)
|
_, err := json.Marshal(v)
|
||||||
|
assert.NoError(t, err)
|
||||||
}, "Resource %s does not have a custom marshaller", field.Name)
|
}, "Resource %s does not have a custom marshaller", field.Name)
|
||||||
|
|
||||||
// Unmarshalling a *resourceStruct will panic if the resource does not have a custom unmarshaller
|
// Unmarshalling a *resourceStruct will panic if the resource does not have a custom unmarshaller
|
||||||
|
@ -58,7 +59,8 @@ func TestCustomMarshallerIsImplemented(t *testing.T) {
|
||||||
// Eg: *resource.Job implements UnmarshalJSON
|
// Eg: *resource.Job implements UnmarshalJSON
|
||||||
v = reflect.New(vt.Elem()).Interface()
|
v = reflect.New(vt.Elem()).Interface()
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
json.Unmarshal([]byte("{}"), v)
|
err := json.Unmarshal([]byte("{}"), v)
|
||||||
|
assert.NoError(t, err)
|
||||||
}, "Resource %s does not have a custom unmarshaller", field.Name)
|
}, "Resource %s does not have a custom unmarshaller", field.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ func TestRootMergeTargetOverridesWithMode(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
root.initializeDynamicValue()
|
require.NoError(t, root.initializeDynamicValue())
|
||||||
require.NoError(t, root.MergeTargetOverrides("development"))
|
require.NoError(t, root.MergeTargetOverrides("development"))
|
||||||
assert.Equal(t, Development, root.Bundle.Mode)
|
assert.Equal(t, Development, root.Bundle.Mode)
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
root.initializeDynamicValue()
|
require.NoError(t, root.initializeDynamicValue())
|
||||||
require.NoError(t, root.MergeTargetOverrides("development"))
|
require.NoError(t, root.MergeTargetOverrides("development"))
|
||||||
assert.Equal(t, "bar", root.Variables["foo"].Default)
|
assert.Equal(t, "bar", root.Variables["foo"].Default)
|
||||||
assert.Equal(t, "foo var", root.Variables["foo"].Description)
|
assert.Equal(t, "foo var", root.Variables["foo"].Description)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/databricks/cli/libs/databrickscfg"
|
"github.com/databricks/cli/libs/databrickscfg"
|
||||||
"github.com/databricks/databricks-sdk-go/config"
|
"github.com/databricks/databricks-sdk-go/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupWorkspaceTest(t *testing.T) string {
|
func setupWorkspaceTest(t *testing.T) string {
|
||||||
|
@ -42,11 +43,12 @@ func TestWorkspaceResolveProfileFromHost(t *testing.T) {
|
||||||
setupWorkspaceTest(t)
|
setupWorkspaceTest(t)
|
||||||
|
|
||||||
// This works if there is a config file with a matching profile.
|
// This works if there is a config file with a matching profile.
|
||||||
databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
err := databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
||||||
Profile: "default",
|
Profile: "default",
|
||||||
Host: "https://abc.cloud.databricks.com",
|
Host: "https://abc.cloud.databricks.com",
|
||||||
Token: "123",
|
Token: "123",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
client, err := w.Client()
|
client, err := w.Client()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -57,12 +59,13 @@ func TestWorkspaceResolveProfileFromHost(t *testing.T) {
|
||||||
home := setupWorkspaceTest(t)
|
home := setupWorkspaceTest(t)
|
||||||
|
|
||||||
// This works if there is a config file with a matching profile.
|
// This works if there is a config file with a matching profile.
|
||||||
databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
err := databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
||||||
ConfigFile: filepath.Join(home, "customcfg"),
|
ConfigFile: filepath.Join(home, "customcfg"),
|
||||||
Profile: "custom",
|
Profile: "custom",
|
||||||
Host: "https://abc.cloud.databricks.com",
|
Host: "https://abc.cloud.databricks.com",
|
||||||
Token: "123",
|
Token: "123",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
|
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
|
||||||
client, err := w.Client()
|
client, err := w.Client()
|
||||||
|
@ -90,12 +93,13 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
|
||||||
setupWorkspaceTest(t)
|
setupWorkspaceTest(t)
|
||||||
|
|
||||||
// This works if there is a config file with a matching profile.
|
// This works if there is a config file with a matching profile.
|
||||||
databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
err := databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
||||||
Profile: "abc",
|
Profile: "abc",
|
||||||
Host: "https://abc.cloud.databricks.com",
|
Host: "https://abc.cloud.databricks.com",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err := w.Client()
|
_, err = w.Client()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -103,12 +107,13 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
|
||||||
setupWorkspaceTest(t)
|
setupWorkspaceTest(t)
|
||||||
|
|
||||||
// This works if there is a config file with a matching profile.
|
// This works if there is a config file with a matching profile.
|
||||||
databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
err := databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
||||||
Profile: "abc",
|
Profile: "abc",
|
||||||
Host: "https://def.cloud.databricks.com",
|
Host: "https://def.cloud.databricks.com",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err := w.Client()
|
_, err = w.Client()
|
||||||
assert.ErrorContains(t, err, "config host mismatch")
|
assert.ErrorContains(t, err, "config host mismatch")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -116,14 +121,15 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
|
||||||
home := setupWorkspaceTest(t)
|
home := setupWorkspaceTest(t)
|
||||||
|
|
||||||
// This works if there is a config file with a matching profile.
|
// This works if there is a config file with a matching profile.
|
||||||
databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
err := databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
||||||
ConfigFile: filepath.Join(home, "customcfg"),
|
ConfigFile: filepath.Join(home, "customcfg"),
|
||||||
Profile: "abc",
|
Profile: "abc",
|
||||||
Host: "https://abc.cloud.databricks.com",
|
Host: "https://abc.cloud.databricks.com",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
|
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
|
||||||
_, err := w.Client()
|
_, err = w.Client()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -131,14 +137,15 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
|
||||||
home := setupWorkspaceTest(t)
|
home := setupWorkspaceTest(t)
|
||||||
|
|
||||||
// This works if there is a config file with a matching profile.
|
// This works if there is a config file with a matching profile.
|
||||||
databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
err := databrickscfg.SaveToProfile(context.Background(), &config.Config{
|
||||||
ConfigFile: filepath.Join(home, "customcfg"),
|
ConfigFile: filepath.Join(home, "customcfg"),
|
||||||
Profile: "abc",
|
Profile: "abc",
|
||||||
Host: "https://def.cloud.databricks.com",
|
Host: "https://def.cloud.databricks.com",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
|
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
|
||||||
_, err := w.Client()
|
_, err = w.Client()
|
||||||
assert.ErrorContains(t, err, "config host mismatch")
|
assert.ErrorContains(t, err, "config host mismatch")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// with the path it is loaded from.
|
// with the path it is loaded from.
|
||||||
func SetLocation(b *bundle.Bundle, prefix string, locations []dyn.Location) {
|
func SetLocation(b *bundle.Bundle, prefix string, locations []dyn.Location) {
|
||||||
start := dyn.MustPathFromString(prefix)
|
start := dyn.MustPathFromString(prefix)
|
||||||
b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) {
|
err := b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) {
|
||||||
return dyn.Walk(root, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
return dyn.Walk(root, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
||||||
// If the path has the given prefix, set the location.
|
// If the path has the given prefix, set the location.
|
||||||
if p.HasPrefix(start) {
|
if p.HasPrefix(start) {
|
||||||
|
@ -27,4 +27,7 @@ func SetLocation(b *bundle.Bundle, prefix string, locations []dyn.Location) {
|
||||||
return v, dyn.ErrSkip
|
return v, dyn.ErrSkip
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic("Mutate() failed: " + err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -489,7 +489,8 @@ func TestRenderSummaryTemplate_nilBundle(t *testing.T) {
|
||||||
err := renderSummaryHeaderTemplate(writer, nil)
|
err := renderSummaryHeaderTemplate(writer, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
io.WriteString(writer, buildTrailer(nil))
|
_, err = io.WriteString(writer, buildTrailer(nil))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "Validation OK!\n", writer.String())
|
assert.Equal(t, "Validation OK!\n", writer.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ func TestConvertPythonParams(t *testing.T) {
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
Job: JobOptions{},
|
Job: JobOptions{},
|
||||||
}
|
}
|
||||||
runner.convertPythonParams(opts)
|
err := runner.convertPythonParams(opts)
|
||||||
|
require.NoError(t, err)
|
||||||
require.NotContains(t, opts.Job.notebookParams, "__python_params")
|
require.NotContains(t, opts.Job.notebookParams, "__python_params")
|
||||||
|
|
||||||
opts = &Options{
|
opts = &Options{
|
||||||
|
@ -50,7 +51,8 @@ func TestConvertPythonParams(t *testing.T) {
|
||||||
pythonParams: []string{"param1", "param2", "param3"},
|
pythonParams: []string{"param1", "param2", "param3"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner.convertPythonParams(opts)
|
err = runner.convertPythonParams(opts)
|
||||||
|
require.NoError(t, err)
|
||||||
require.Contains(t, opts.Job.notebookParams, "__python_params")
|
require.Contains(t, opts.Job.notebookParams, "__python_params")
|
||||||
require.Equal(t, opts.Job.notebookParams["__python_params"], `["param1","param2","param3"]`)
|
require.Equal(t, opts.Job.notebookParams["__python_params"], `["param1","param2","param3"]`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ func TestGetWorkspaceAuthStatus(t *testing.T) {
|
||||||
|
|
||||||
cmd.Flags().String("host", "", "")
|
cmd.Flags().String("host", "", "")
|
||||||
cmd.Flags().String("profile", "", "")
|
cmd.Flags().String("profile", "", "")
|
||||||
cmd.Flag("profile").Value.Set("my-profile")
|
err := cmd.Flag("profile").Value.Set("my-profile")
|
||||||
|
require.NoError(t, err)
|
||||||
cmd.Flag("profile").Changed = true
|
cmd.Flag("profile").Changed = true
|
||||||
|
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
|
@ -39,14 +40,16 @@ func TestGetWorkspaceAuthStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
m.WorkspaceClient.Config = cfg
|
m.WorkspaceClient.Config = cfg
|
||||||
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
||||||
config.ConfigAttributes.Configure(cfg)
|
err = config.ConfigAttributes.Configure(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
||||||
config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
err := config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
||||||
"host": "https://test.com",
|
"host": "https://test.com",
|
||||||
"token": "test-token",
|
"token": "test-token",
|
||||||
"auth_type": "azure-cli",
|
"auth_type": "azure-cli",
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
return cfg, false, nil
|
return cfg, false, nil
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -81,7 +84,8 @@ func TestGetWorkspaceAuthStatusError(t *testing.T) {
|
||||||
|
|
||||||
cmd.Flags().String("host", "", "")
|
cmd.Flags().String("host", "", "")
|
||||||
cmd.Flags().String("profile", "", "")
|
cmd.Flags().String("profile", "", "")
|
||||||
cmd.Flag("profile").Value.Set("my-profile")
|
err := cmd.Flag("profile").Value.Set("my-profile")
|
||||||
|
require.NoError(t, err)
|
||||||
cmd.Flag("profile").Changed = true
|
cmd.Flag("profile").Changed = true
|
||||||
|
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
|
@ -89,10 +93,11 @@ func TestGetWorkspaceAuthStatusError(t *testing.T) {
|
||||||
}
|
}
|
||||||
m.WorkspaceClient.Config = cfg
|
m.WorkspaceClient.Config = cfg
|
||||||
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
||||||
config.ConfigAttributes.Configure(cfg)
|
err = config.ConfigAttributes.Configure(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
||||||
config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
err = config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
||||||
"host": "https://test.com",
|
"host": "https://test.com",
|
||||||
"token": "test-token",
|
"token": "test-token",
|
||||||
"auth_type": "azure-cli",
|
"auth_type": "azure-cli",
|
||||||
|
@ -128,7 +133,8 @@ func TestGetWorkspaceAuthStatusSensitive(t *testing.T) {
|
||||||
|
|
||||||
cmd.Flags().String("host", "", "")
|
cmd.Flags().String("host", "", "")
|
||||||
cmd.Flags().String("profile", "", "")
|
cmd.Flags().String("profile", "", "")
|
||||||
cmd.Flag("profile").Value.Set("my-profile")
|
err := cmd.Flag("profile").Value.Set("my-profile")
|
||||||
|
require.NoError(t, err)
|
||||||
cmd.Flag("profile").Changed = true
|
cmd.Flag("profile").Changed = true
|
||||||
|
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
|
@ -136,10 +142,11 @@ func TestGetWorkspaceAuthStatusSensitive(t *testing.T) {
|
||||||
}
|
}
|
||||||
m.WorkspaceClient.Config = cfg
|
m.WorkspaceClient.Config = cfg
|
||||||
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
||||||
config.ConfigAttributes.Configure(cfg)
|
err = config.ConfigAttributes.Configure(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
||||||
config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
err = config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
||||||
"host": "https://test.com",
|
"host": "https://test.com",
|
||||||
"token": "test-token",
|
"token": "test-token",
|
||||||
"auth_type": "azure-cli",
|
"auth_type": "azure-cli",
|
||||||
|
@ -171,7 +178,8 @@ func TestGetAccountAuthStatus(t *testing.T) {
|
||||||
|
|
||||||
cmd.Flags().String("host", "", "")
|
cmd.Flags().String("host", "", "")
|
||||||
cmd.Flags().String("profile", "", "")
|
cmd.Flags().String("profile", "", "")
|
||||||
cmd.Flag("profile").Value.Set("my-profile")
|
err := cmd.Flag("profile").Value.Set("my-profile")
|
||||||
|
require.NoError(t, err)
|
||||||
cmd.Flag("profile").Changed = true
|
cmd.Flag("profile").Changed = true
|
||||||
|
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
|
@ -179,13 +187,14 @@ func TestGetAccountAuthStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
m.AccountClient.Config = cfg
|
m.AccountClient.Config = cfg
|
||||||
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
t.Setenv("DATABRICKS_AUTH_TYPE", "azure-cli")
|
||||||
config.ConfigAttributes.Configure(cfg)
|
err = config.ConfigAttributes.Configure(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
wsApi := m.GetMockWorkspacesAPI()
|
wsApi := m.GetMockWorkspacesAPI()
|
||||||
wsApi.EXPECT().List(mock.Anything).Return(nil, nil)
|
wsApi.EXPECT().List(mock.Anything).Return(nil, nil)
|
||||||
|
|
||||||
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
|
||||||
config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
err = config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
|
||||||
"account_id": "test-account-id",
|
"account_id": "test-account-id",
|
||||||
"username": "test-user",
|
"username": "test-user",
|
||||||
"host": "https://test.com",
|
"host": "https://test.com",
|
||||||
|
|
|
@ -67,9 +67,10 @@ func TestDashboard_ExistingID_Nominal(t *testing.T) {
|
||||||
ctx := bundle.Context(context.Background(), b)
|
ctx := bundle.Context(context.Background(), b)
|
||||||
cmd := NewGenerateDashboardCommand()
|
cmd := NewGenerateDashboardCommand()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
cmd.Flag("existing-id").Value.Set("f00dcafe")
|
err := cmd.Flag("existing-id").Value.Set("f00dcafe")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
err := cmd.RunE(cmd, []string{})
|
err = cmd.RunE(cmd, []string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Assert the contents of the generated configuration
|
// Assert the contents of the generated configuration
|
||||||
|
@ -105,9 +106,10 @@ func TestDashboard_ExistingID_NotFound(t *testing.T) {
|
||||||
ctx := bundle.Context(context.Background(), b)
|
ctx := bundle.Context(context.Background(), b)
|
||||||
cmd := NewGenerateDashboardCommand()
|
cmd := NewGenerateDashboardCommand()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
cmd.Flag("existing-id").Value.Set("f00dcafe")
|
err := cmd.Flag("existing-id").Value.Set("f00dcafe")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
err := cmd.RunE(cmd, []string{})
|
err = cmd.RunE(cmd, []string{})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +139,10 @@ func TestDashboard_ExistingPath_Nominal(t *testing.T) {
|
||||||
ctx := bundle.Context(context.Background(), b)
|
ctx := bundle.Context(context.Background(), b)
|
||||||
cmd := NewGenerateDashboardCommand()
|
cmd := NewGenerateDashboardCommand()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
cmd.Flag("existing-path").Value.Set("/path/to/dashboard")
|
err := cmd.Flag("existing-path").Value.Set("/path/to/dashboard")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
err := cmd.RunE(cmd, []string{})
|
err = cmd.RunE(cmd, []string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Assert the contents of the generated configuration
|
// Assert the contents of the generated configuration
|
||||||
|
@ -175,8 +178,9 @@ func TestDashboard_ExistingPath_NotFound(t *testing.T) {
|
||||||
ctx := bundle.Context(context.Background(), b)
|
ctx := bundle.Context(context.Background(), b)
|
||||||
cmd := NewGenerateDashboardCommand()
|
cmd := NewGenerateDashboardCommand()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
cmd.Flag("existing-path").Value.Set("/path/to/dashboard")
|
err := cmd.Flag("existing-path").Value.Set("/path/to/dashboard")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
err := cmd.RunE(cmd, []string{})
|
err = cmd.RunE(cmd, []string{})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,13 +78,13 @@ func TestGeneratePipelineCommand(t *testing.T) {
|
||||||
workspaceApi.EXPECT().Download(mock.Anything, "/test/file.py", mock.Anything).Return(pyContent, nil)
|
workspaceApi.EXPECT().Download(mock.Anything, "/test/file.py", mock.Anything).Return(pyContent, nil)
|
||||||
|
|
||||||
cmd.SetContext(bundle.Context(context.Background(), b))
|
cmd.SetContext(bundle.Context(context.Background(), b))
|
||||||
cmd.Flag("existing-pipeline-id").Value.Set("test-pipeline")
|
require.NoError(t, cmd.Flag("existing-pipeline-id").Value.Set("test-pipeline"))
|
||||||
|
|
||||||
configDir := filepath.Join(root, "resources")
|
configDir := filepath.Join(root, "resources")
|
||||||
cmd.Flag("config-dir").Value.Set(configDir)
|
require.NoError(t, cmd.Flag("config-dir").Value.Set(configDir))
|
||||||
|
|
||||||
srcDir := filepath.Join(root, "src")
|
srcDir := filepath.Join(root, "src")
|
||||||
cmd.Flag("source-dir").Value.Set(srcDir)
|
require.NoError(t, cmd.Flag("source-dir").Value.Set(srcDir))
|
||||||
|
|
||||||
var key string
|
var key string
|
||||||
cmd.Flags().StringVar(&key, "key", "test_pipeline", "")
|
cmd.Flags().StringVar(&key, "key", "test_pipeline", "")
|
||||||
|
@ -174,13 +174,13 @@ func TestGenerateJobCommand(t *testing.T) {
|
||||||
workspaceApi.EXPECT().Download(mock.Anything, "/test/notebook", mock.Anything).Return(notebookContent, nil)
|
workspaceApi.EXPECT().Download(mock.Anything, "/test/notebook", mock.Anything).Return(notebookContent, nil)
|
||||||
|
|
||||||
cmd.SetContext(bundle.Context(context.Background(), b))
|
cmd.SetContext(bundle.Context(context.Background(), b))
|
||||||
cmd.Flag("existing-job-id").Value.Set("1234")
|
require.NoError(t, cmd.Flag("existing-job-id").Value.Set("1234"))
|
||||||
|
|
||||||
configDir := filepath.Join(root, "resources")
|
configDir := filepath.Join(root, "resources")
|
||||||
cmd.Flag("config-dir").Value.Set(configDir)
|
require.NoError(t, cmd.Flag("config-dir").Value.Set(configDir))
|
||||||
|
|
||||||
srcDir := filepath.Join(root, "src")
|
srcDir := filepath.Join(root, "src")
|
||||||
cmd.Flag("source-dir").Value.Set(srcDir)
|
require.NoError(t, cmd.Flag("source-dir").Value.Set(srcDir))
|
||||||
|
|
||||||
var key string
|
var key string
|
||||||
cmd.Flags().StringVar(&key, "key", "test_job", "")
|
cmd.Flags().StringVar(&key, "key", "test_job", "")
|
||||||
|
@ -279,13 +279,13 @@ func TestGenerateJobCommandOldFileRename(t *testing.T) {
|
||||||
workspaceApi.EXPECT().Download(mock.Anything, "/test/notebook", mock.Anything).Return(notebookContent, nil)
|
workspaceApi.EXPECT().Download(mock.Anything, "/test/notebook", mock.Anything).Return(notebookContent, nil)
|
||||||
|
|
||||||
cmd.SetContext(bundle.Context(context.Background(), b))
|
cmd.SetContext(bundle.Context(context.Background(), b))
|
||||||
cmd.Flag("existing-job-id").Value.Set("1234")
|
require.NoError(t, cmd.Flag("existing-job-id").Value.Set("1234"))
|
||||||
|
|
||||||
configDir := filepath.Join(root, "resources")
|
configDir := filepath.Join(root, "resources")
|
||||||
cmd.Flag("config-dir").Value.Set(configDir)
|
require.NoError(t, cmd.Flag("config-dir").Value.Set(configDir))
|
||||||
|
|
||||||
srcDir := filepath.Join(root, "src")
|
srcDir := filepath.Join(root, "src")
|
||||||
cmd.Flag("source-dir").Value.Set(srcDir)
|
require.NoError(t, cmd.Flag("source-dir").Value.Set(srcDir))
|
||||||
|
|
||||||
var key string
|
var key string
|
||||||
cmd.Flags().StringVar(&key, "key", "test_job", "")
|
cmd.Flags().StringVar(&key, "key", "test_job", "")
|
||||||
|
@ -295,7 +295,7 @@ func TestGenerateJobCommandOldFileRename(t *testing.T) {
|
||||||
touchEmptyFile(t, oldFilename)
|
touchEmptyFile(t, oldFilename)
|
||||||
|
|
||||||
// Having an existing files require --force flag to regenerate them
|
// Having an existing files require --force flag to regenerate them
|
||||||
cmd.Flag("force").Value.Set("true")
|
require.NoError(t, cmd.Flag("force").Value.Set("true"))
|
||||||
|
|
||||||
err := cmd.RunE(cmd, []string{})
|
err := cmd.RunE(cmd, []string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -7,12 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFileFromRef(t *testing.T) {
|
func TestFileFromRef(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/databrickslabs/ucx/main/README.md" {
|
if r.URL.Path == "/databrickslabs/ucx/main/README.md" {
|
||||||
w.Write([]byte(`abc`))
|
_, err := w.Write([]byte(`abc`))
|
||||||
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Logf("Requested: %s", r.URL.Path)
|
t.Logf("Requested: %s", r.URL.Path)
|
||||||
|
@ -31,7 +33,8 @@ func TestFileFromRef(t *testing.T) {
|
||||||
func TestDownloadZipball(t *testing.T) {
|
func TestDownloadZipball(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/repos/databrickslabs/ucx/zipball/main" {
|
if r.URL.Path == "/repos/databrickslabs/ucx/zipball/main" {
|
||||||
w.Write([]byte(`abc`))
|
_, err := w.Write([]byte(`abc`))
|
||||||
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Logf("Requested: %s", r.URL.Path)
|
t.Logf("Requested: %s", r.URL.Path)
|
||||||
|
|
|
@ -7,12 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadsReleasesForCLI(t *testing.T) {
|
func TestLoadsReleasesForCLI(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/repos/databricks/cli/releases" {
|
if r.URL.Path == "/repos/databricks/cli/releases" {
|
||||||
w.Write([]byte(`[{"tag_name": "v1.2.3"}, {"tag_name": "v1.2.2"}]`))
|
_, err := w.Write([]byte(`[{"tag_name": "v1.2.3"}, {"tag_name": "v1.2.2"}]`))
|
||||||
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Logf("Requested: %s", r.URL.Path)
|
t.Logf("Requested: %s", r.URL.Path)
|
||||||
|
|
|
@ -7,12 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepositories(t *testing.T) {
|
func TestRepositories(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/users/databrickslabs/repos" {
|
if r.URL.Path == "/users/databrickslabs/repos" {
|
||||||
w.Write([]byte(`[{"name": "x"}]`))
|
_, err := w.Write([]byte(`[{"name": "x"}]`))
|
||||||
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Logf("Requested: %s", r.URL.Path)
|
t.Logf("Requested: %s", r.URL.Path)
|
||||||
|
|
|
@ -117,10 +117,10 @@ func installerContext(t *testing.T, server *httptest.Server) context.Context {
|
||||||
|
|
||||||
func respondWithJSON(t *testing.T, w http.ResponseWriter, v any) {
|
func respondWithJSON(t *testing.T, w http.ResponseWriter, v any) {
|
||||||
raw, err := json.Marshal(v)
|
raw, err := json.Marshal(v)
|
||||||
if err != nil {
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
|
||||||
w.Write(raw)
|
_, err = w.Write(raw)
|
||||||
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type fileTree struct {
|
type fileTree struct {
|
||||||
|
@ -167,19 +167,17 @@ func TestInstallerWorksForReleases(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/databrickslabs/blueprint/v0.3.15/labs.yml" {
|
if r.URL.Path == "/databrickslabs/blueprint/v0.3.15/labs.yml" {
|
||||||
raw, err := os.ReadFile("testdata/installed-in-home/.databricks/labs/blueprint/lib/labs.yml")
|
raw, err := os.ReadFile("testdata/installed-in-home/.databricks/labs/blueprint/lib/labs.yml")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
_, err = w.Write(raw)
|
||||||
}
|
require.NoError(t, err)
|
||||||
w.Write(raw)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.URL.Path == "/repos/databrickslabs/blueprint/zipball/v0.3.15" {
|
if r.URL.Path == "/repos/databrickslabs/blueprint/zipball/v0.3.15" {
|
||||||
raw, err := zipballFromFolder("testdata/installed-in-home/.databricks/labs/blueprint/lib")
|
raw, err := zipballFromFolder("testdata/installed-in-home/.databricks/labs/blueprint/lib")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
w.Header().Add("Content-Type", "application/octet-stream")
|
w.Header().Add("Content-Type", "application/octet-stream")
|
||||||
w.Write(raw)
|
_, err = w.Write(raw)
|
||||||
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.URL.Path == "/api/2.1/clusters/get" {
|
if r.URL.Path == "/api/2.1/clusters/get" {
|
||||||
|
@ -314,7 +312,10 @@ func TestInstallerWorksForDevelopment(t *testing.T) {
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
defer os.Chdir(wd)
|
defer func() {
|
||||||
|
err := os.Chdir(wd)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
devDir := copyTestdata(t, "testdata/installed-in-home/.databricks/labs/blueprint/lib")
|
devDir := copyTestdata(t, "testdata/installed-in-home/.databricks/labs/blueprint/lib")
|
||||||
err := os.Chdir(devDir)
|
err := os.Chdir(devDir)
|
||||||
|
@ -373,19 +374,17 @@ func TestUpgraderWorksForReleases(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/databrickslabs/blueprint/v0.4.0/labs.yml" {
|
if r.URL.Path == "/databrickslabs/blueprint/v0.4.0/labs.yml" {
|
||||||
raw, err := os.ReadFile("testdata/installed-in-home/.databricks/labs/blueprint/lib/labs.yml")
|
raw, err := os.ReadFile("testdata/installed-in-home/.databricks/labs/blueprint/lib/labs.yml")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
_, err = w.Write(raw)
|
||||||
}
|
require.NoError(t, err)
|
||||||
w.Write(raw)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.URL.Path == "/repos/databrickslabs/blueprint/zipball/v0.4.0" {
|
if r.URL.Path == "/repos/databrickslabs/blueprint/zipball/v0.4.0" {
|
||||||
raw, err := zipballFromFolder("testdata/installed-in-home/.databricks/labs/blueprint/lib")
|
raw, err := zipballFromFolder("testdata/installed-in-home/.databricks/labs/blueprint/lib")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
w.Header().Add("Content-Type", "application/octet-stream")
|
w.Header().Add("Content-Type", "application/octet-stream")
|
||||||
w.Write(raw)
|
_, err = w.Write(raw)
|
||||||
|
require.NoError(t, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.URL.Path == "/api/2.1/clusters/get" {
|
if r.URL.Path == "/api/2.1/clusters/get" {
|
||||||
|
|
|
@ -99,10 +99,11 @@ func TestBundleConfigureWithNonExistentProfileFlag(t *testing.T) {
|
||||||
testutil.CleanupEnvironment(t)
|
testutil.CleanupEnvironment(t)
|
||||||
|
|
||||||
cmd := emptyCommand(t)
|
cmd := emptyCommand(t)
|
||||||
cmd.Flag("profile").Value.Set("NOEXIST")
|
err := cmd.Flag("profile").Value.Set("NOEXIST")
|
||||||
|
require.NoError(t, err)
|
||||||
b := setupWithHost(t, cmd, "https://x.com")
|
b := setupWithHost(t, cmd, "https://x.com")
|
||||||
|
|
||||||
_, err := b.InitializeWorkspaceClient()
|
_, err = b.InitializeWorkspaceClient()
|
||||||
assert.ErrorContains(t, err, "has no NOEXIST profile configured")
|
assert.ErrorContains(t, err, "has no NOEXIST profile configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,10 +111,11 @@ func TestBundleConfigureWithMismatchedProfile(t *testing.T) {
|
||||||
testutil.CleanupEnvironment(t)
|
testutil.CleanupEnvironment(t)
|
||||||
|
|
||||||
cmd := emptyCommand(t)
|
cmd := emptyCommand(t)
|
||||||
cmd.Flag("profile").Value.Set("PROFILE-1")
|
err := cmd.Flag("profile").Value.Set("PROFILE-1")
|
||||||
|
require.NoError(t, err)
|
||||||
b := setupWithHost(t, cmd, "https://x.com")
|
b := setupWithHost(t, cmd, "https://x.com")
|
||||||
|
|
||||||
_, err := b.InitializeWorkspaceClient()
|
_, err = b.InitializeWorkspaceClient()
|
||||||
assert.ErrorContains(t, err, "config host mismatch: profile uses host https://a.com, but CLI configured to use https://x.com")
|
assert.ErrorContains(t, err, "config host mismatch: profile uses host https://a.com, but CLI configured to use https://x.com")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +123,8 @@ func TestBundleConfigureWithCorrectProfile(t *testing.T) {
|
||||||
testutil.CleanupEnvironment(t)
|
testutil.CleanupEnvironment(t)
|
||||||
|
|
||||||
cmd := emptyCommand(t)
|
cmd := emptyCommand(t)
|
||||||
cmd.Flag("profile").Value.Set("PROFILE-1")
|
err := cmd.Flag("profile").Value.Set("PROFILE-1")
|
||||||
|
require.NoError(t, err)
|
||||||
b := setupWithHost(t, cmd, "https://a.com")
|
b := setupWithHost(t, cmd, "https://a.com")
|
||||||
|
|
||||||
client, err := b.InitializeWorkspaceClient()
|
client, err := b.InitializeWorkspaceClient()
|
||||||
|
@ -146,7 +149,8 @@ func TestBundleConfigureWithProfileFlagAndEnvVariable(t *testing.T) {
|
||||||
|
|
||||||
t.Setenv("DATABRICKS_CONFIG_PROFILE", "NOEXIST")
|
t.Setenv("DATABRICKS_CONFIG_PROFILE", "NOEXIST")
|
||||||
cmd := emptyCommand(t)
|
cmd := emptyCommand(t)
|
||||||
cmd.Flag("profile").Value.Set("PROFILE-1")
|
err := cmd.Flag("profile").Value.Set("PROFILE-1")
|
||||||
|
require.NoError(t, err)
|
||||||
b := setupWithHost(t, cmd, "https://a.com")
|
b := setupWithHost(t, cmd, "https://a.com")
|
||||||
|
|
||||||
client, err := b.InitializeWorkspaceClient()
|
client, err := b.InitializeWorkspaceClient()
|
||||||
|
@ -174,7 +178,8 @@ func TestBundleConfigureProfileFlag(t *testing.T) {
|
||||||
|
|
||||||
// The --profile flag takes precedence over the profile in the databricks.yml file
|
// The --profile flag takes precedence over the profile in the databricks.yml file
|
||||||
cmd := emptyCommand(t)
|
cmd := emptyCommand(t)
|
||||||
cmd.Flag("profile").Value.Set("PROFILE-2")
|
err := cmd.Flag("profile").Value.Set("PROFILE-2")
|
||||||
|
require.NoError(t, err)
|
||||||
b := setupWithProfile(t, cmd, "PROFILE-1")
|
b := setupWithProfile(t, cmd, "PROFILE-1")
|
||||||
|
|
||||||
client, err := b.InitializeWorkspaceClient()
|
client, err := b.InitializeWorkspaceClient()
|
||||||
|
@ -205,7 +210,8 @@ func TestBundleConfigureProfileFlagAndEnvVariable(t *testing.T) {
|
||||||
// The --profile flag takes precedence over the DATABRICKS_CONFIG_PROFILE environment variable
|
// The --profile flag takes precedence over the DATABRICKS_CONFIG_PROFILE environment variable
|
||||||
t.Setenv("DATABRICKS_CONFIG_PROFILE", "NOEXIST")
|
t.Setenv("DATABRICKS_CONFIG_PROFILE", "NOEXIST")
|
||||||
cmd := emptyCommand(t)
|
cmd := emptyCommand(t)
|
||||||
cmd.Flag("profile").Value.Set("PROFILE-2")
|
err := cmd.Flag("profile").Value.Set("PROFILE-2")
|
||||||
|
require.NoError(t, err)
|
||||||
b := setupWithProfile(t, cmd, "PROFILE-1")
|
b := setupWithProfile(t, cmd, "PROFILE-1")
|
||||||
|
|
||||||
client, err := b.InitializeWorkspaceClient()
|
client, err := b.InitializeWorkspaceClient()
|
||||||
|
|
|
@ -33,27 +33,27 @@ func initializeProgressLoggerTest(t *testing.T) (
|
||||||
|
|
||||||
func TestInitializeErrorOnIncompatibleConfig(t *testing.T) {
|
func TestInitializeErrorOnIncompatibleConfig(t *testing.T) {
|
||||||
plt, logLevel, logFile, progressFormat := initializeProgressLoggerTest(t)
|
plt, logLevel, logFile, progressFormat := initializeProgressLoggerTest(t)
|
||||||
logLevel.Set("info")
|
require.NoError(t, logLevel.Set("info"))
|
||||||
logFile.Set("stderr")
|
require.NoError(t, logFile.Set("stderr"))
|
||||||
progressFormat.Set("inplace")
|
require.NoError(t, progressFormat.Set("inplace"))
|
||||||
_, err := plt.progressLoggerFlag.initializeContext(context.Background())
|
_, err := plt.progressLoggerFlag.initializeContext(context.Background())
|
||||||
assert.ErrorContains(t, err, "inplace progress logging cannot be used when log-file is stderr")
|
assert.ErrorContains(t, err, "inplace progress logging cannot be used when log-file is stderr")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoErrorOnDisabledLogLevel(t *testing.T) {
|
func TestNoErrorOnDisabledLogLevel(t *testing.T) {
|
||||||
plt, logLevel, logFile, progressFormat := initializeProgressLoggerTest(t)
|
plt, logLevel, logFile, progressFormat := initializeProgressLoggerTest(t)
|
||||||
logLevel.Set("disabled")
|
require.NoError(t, logLevel.Set("disabled"))
|
||||||
logFile.Set("stderr")
|
require.NoError(t, logFile.Set("stderr"))
|
||||||
progressFormat.Set("inplace")
|
require.NoError(t, progressFormat.Set("inplace"))
|
||||||
_, err := plt.progressLoggerFlag.initializeContext(context.Background())
|
_, err := plt.progressLoggerFlag.initializeContext(context.Background())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoErrorOnNonStderrLogFile(t *testing.T) {
|
func TestNoErrorOnNonStderrLogFile(t *testing.T) {
|
||||||
plt, logLevel, logFile, progressFormat := initializeProgressLoggerTest(t)
|
plt, logLevel, logFile, progressFormat := initializeProgressLoggerTest(t)
|
||||||
logLevel.Set("info")
|
require.NoError(t, logLevel.Set("info"))
|
||||||
logFile.Set("stdout")
|
require.NoError(t, logFile.Set("stdout"))
|
||||||
progressFormat.Set("inplace")
|
require.NoError(t, progressFormat.Set("inplace"))
|
||||||
_, err := plt.progressLoggerFlag.initializeContext(context.Background())
|
_, err := plt.progressLoggerFlag.initializeContext(context.Background())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,8 @@ func TestAccAbortBind(t *testing.T) {
|
||||||
jobId := gt.createTestJob(ctx)
|
jobId := gt.createTestJob(ctx)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
gt.destroyJob(ctx, jobId)
|
gt.destroyJob(ctx, jobId)
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Bind should fail because prompting is not possible.
|
// Bind should fail because prompting is not possible.
|
||||||
|
|
|
@ -33,7 +33,8 @@ func setupUcSchemaBundle(t *testing.T, ctx context.Context, w *databricks.Worksp
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Assert the schema is created
|
// Assert the schema is created
|
||||||
|
@ -190,7 +191,8 @@ func TestAccBundlePipelineRecreateWithoutAutoApprove(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Assert the pipeline is created
|
// Assert the pipeline is created
|
||||||
|
@ -258,7 +260,8 @@ func TestAccDeployUcVolume(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Assert the volume is created successfully
|
// Assert the volume is created successfully
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestAccFilesAreSyncedCorrectlyWhenNoSnapshot(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
require.NoError(t, destroyBundle(t, ctx, bundleRoot))
|
||||||
})
|
})
|
||||||
|
|
||||||
remoteRoot := getBundleRemoteRootPath(w, t, uniqueId)
|
remoteRoot := getBundleRemoteRootPath(w, t, uniqueId)
|
||||||
|
|
|
@ -22,7 +22,8 @@ func TestAccPythonWheelTaskWithEnvironmentsDeployAndRun(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
out, err := runResource(t, ctx, bundleRoot, "some_other_job")
|
out, err := runResource(t, ctx, bundleRoot, "some_other_job")
|
||||||
|
|
|
@ -29,7 +29,8 @@ func runPythonWheelTest(t *testing.T, templateName string, sparkVersion string,
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
out, err := runResource(t, ctx, bundleRoot, "some_other_job")
|
out, err := runResource(t, ctx, bundleRoot, "some_other_job")
|
||||||
|
|
|
@ -31,7 +31,8 @@ func runSparkJarTestCommon(t *testing.T, ctx context.Context, sparkVersion strin
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
destroyBundle(t, ctx, bundleRoot)
|
err := destroyBundle(t, ctx, bundleRoot)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
out, err := runResource(t, ctx, bundleRoot, "jar_job")
|
out, err := runResource(t, ctx, bundleRoot, "jar_job")
|
||||||
|
|
|
@ -176,7 +176,10 @@ func (t *cobraTestRunner) SendText(text string) {
|
||||||
if t.stdinW == nil {
|
if t.stdinW == nil {
|
||||||
panic("no standard input configured")
|
panic("no standard input configured")
|
||||||
}
|
}
|
||||||
t.stdinW.Write([]byte(text + "\n"))
|
_, err := t.stdinW.Write([]byte(text + "\n"))
|
||||||
|
if err != nil {
|
||||||
|
panic("Failed to to write to t.stdinW")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *cobraTestRunner) RunBackground() {
|
func (t *cobraTestRunner) RunBackground() {
|
||||||
|
@ -496,9 +499,10 @@ func TemporaryUcVolume(t *testing.T, w *databricks.WorkspaceClient) string {
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
w.Schemas.Delete(ctx, catalog.DeleteSchemaRequest{
|
err := w.Schemas.Delete(ctx, catalog.DeleteSchemaRequest{
|
||||||
FullName: schema.FullName,
|
FullName: schema.FullName,
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create a volume
|
// Create a volume
|
||||||
|
@ -510,9 +514,10 @@ func TemporaryUcVolume(t *testing.T, w *databricks.WorkspaceClient) string {
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
w.Volumes.Delete(ctx, catalog.DeleteVolumeRequest{
|
err := w.Volumes.Delete(ctx, catalog.DeleteVolumeRequest{
|
||||||
Name: volume.FullName,
|
Name: volume.FullName,
|
||||||
})
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
return path.Join("/Volumes", "main", schema.Name, volume.Name)
|
return path.Join("/Volumes", "main", schema.Name, volume.Name)
|
||||||
|
|
|
@ -58,7 +58,8 @@ func TestAccBundleInitOnMlopsStacks(t *testing.T) {
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(initConfig)
|
b, err := json.Marshal(initConfig)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
os.WriteFile(filepath.Join(tmpDir1, "config.json"), b, 0644)
|
err = os.WriteFile(filepath.Join(tmpDir1, "config.json"), b, 0644)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Run bundle init
|
// Run bundle init
|
||||||
assert.NoFileExists(t, filepath.Join(tmpDir2, "repo_name", projectName, "README.md"))
|
assert.NoFileExists(t, filepath.Join(tmpDir2, "repo_name", projectName, "README.md"))
|
||||||
|
|
|
@ -133,7 +133,8 @@ func TestAccLock(t *testing.T) {
|
||||||
|
|
||||||
// assert on active locker content
|
// assert on active locker content
|
||||||
var res map[string]string
|
var res map[string]string
|
||||||
json.Unmarshal(b, &res)
|
err = json.Unmarshal(b, &res)
|
||||||
|
require.NoError(t, err)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "Khan", res["surname"])
|
assert.Equal(t, "Khan", res["surname"])
|
||||||
assert.Equal(t, "Shah Rukh", res["name"])
|
assert.Equal(t, "Shah Rukh", res["name"])
|
||||||
|
|
|
@ -47,7 +47,11 @@ func testTags(t *testing.T, tags map[string]string) error {
|
||||||
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
w.Jobs.DeleteByJobId(ctx, resp.JobId)
|
_ = w.Jobs.DeleteByJobId(ctx, resp.JobId)
|
||||||
|
// Cannot enable errchecking there, tests fail with:
|
||||||
|
// Error: Received unexpected error:
|
||||||
|
// Job 0 does not exist.
|
||||||
|
// require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@ func TestCommandFlagGrouping(t *testing.T) {
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Usage()
|
err := cmd.Usage()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := `Usage:
|
expected := `Usage:
|
||||||
parent test [flags]
|
parent test [flags]
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
"github.com/databricks/cli/libs/dyn"
|
"github.com/databricks/cli/libs/dyn"
|
||||||
assert "github.com/databricks/cli/libs/dyn/dynassert"
|
assert "github.com/databricks/cli/libs/dyn/dynassert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNormalizeStruct(t *testing.T) {
|
func TestNormalizeStruct(t *testing.T) {
|
||||||
|
@ -20,8 +21,8 @@ func TestNormalizeStruct(t *testing.T) {
|
||||||
"bar": dyn.V("baz"),
|
"bar": dyn.V("baz"),
|
||||||
})
|
})
|
||||||
|
|
||||||
vout, err := Normalize(typ, vin)
|
vout, diags := Normalize(typ, vin)
|
||||||
assert.Empty(t, err)
|
assert.Empty(t, diags)
|
||||||
assert.Equal(t, vin, vout)
|
assert.Equal(t, vin, vout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,14 +38,14 @@ func TestNormalizeStructElementDiagnostic(t *testing.T) {
|
||||||
"bar": dyn.V(map[string]dyn.Value{"an": dyn.V("error")}),
|
"bar": dyn.V(map[string]dyn.Value{"an": dyn.V("error")}),
|
||||||
})
|
})
|
||||||
|
|
||||||
vout, err := Normalize(typ, vin)
|
vout, diags := Normalize(typ, vin)
|
||||||
assert.Len(t, err, 1)
|
assert.Len(t, diags, 1)
|
||||||
assert.Equal(t, diag.Diagnostic{
|
assert.Equal(t, diag.Diagnostic{
|
||||||
Severity: diag.Warning,
|
Severity: diag.Warning,
|
||||||
Summary: `expected string, found map`,
|
Summary: `expected string, found map`,
|
||||||
Locations: []dyn.Location{{}},
|
Locations: []dyn.Location{{}},
|
||||||
Paths: []dyn.Path{dyn.NewPath(dyn.Key("bar"))},
|
Paths: []dyn.Path{dyn.NewPath(dyn.Key("bar"))},
|
||||||
}, err[0])
|
}, diags[0])
|
||||||
|
|
||||||
// Elements that encounter an error during normalization are dropped.
|
// Elements that encounter an error during normalization are dropped.
|
||||||
assert.Equal(t, map[string]any{
|
assert.Equal(t, map[string]any{
|
||||||
|
@ -60,17 +61,20 @@ func TestNormalizeStructUnknownField(t *testing.T) {
|
||||||
var typ Tmp
|
var typ Tmp
|
||||||
|
|
||||||
m := dyn.NewMapping()
|
m := dyn.NewMapping()
|
||||||
m.Set(dyn.V("foo"), dyn.V("val-foo"))
|
err := m.Set(dyn.V("foo"), dyn.V("val-foo"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Set the unknown field, with location information.
|
// Set the unknown field, with location information.
|
||||||
m.Set(dyn.NewValue("bar", []dyn.Location{
|
err = m.Set(dyn.NewValue("bar", []dyn.Location{
|
||||||
{File: "hello.yaml", Line: 1, Column: 1},
|
{File: "hello.yaml", Line: 1, Column: 1},
|
||||||
{File: "world.yaml", Line: 2, Column: 2},
|
{File: "world.yaml", Line: 2, Column: 2},
|
||||||
}), dyn.V("var-bar"))
|
}), dyn.V("var-bar"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
vin := dyn.V(m)
|
vin := dyn.V(m)
|
||||||
|
|
||||||
vout, err := Normalize(typ, vin)
|
vout, diags := Normalize(typ, vin)
|
||||||
assert.Len(t, err, 1)
|
assert.Len(t, diags, 1)
|
||||||
assert.Equal(t, diag.Diagnostic{
|
assert.Equal(t, diag.Diagnostic{
|
||||||
Severity: diag.Warning,
|
Severity: diag.Warning,
|
||||||
Summary: `unknown field: bar`,
|
Summary: `unknown field: bar`,
|
||||||
|
@ -80,7 +84,7 @@ func TestNormalizeStructUnknownField(t *testing.T) {
|
||||||
{File: "world.yaml", Line: 2, Column: 2},
|
{File: "world.yaml", Line: 2, Column: 2},
|
||||||
},
|
},
|
||||||
Paths: []dyn.Path{dyn.EmptyPath},
|
Paths: []dyn.Path{dyn.EmptyPath},
|
||||||
}, err[0])
|
}, diags[0])
|
||||||
|
|
||||||
// The field that can be mapped to the struct field is retained.
|
// The field that can be mapped to the struct field is retained.
|
||||||
assert.Equal(t, map[string]any{
|
assert.Equal(t, map[string]any{
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/dyn"
|
"github.com/databricks/cli/libs/dyn"
|
||||||
assert "github.com/databricks/cli/libs/dyn/dynassert"
|
assert "github.com/databricks/cli/libs/dyn/dynassert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMarshal_String(t *testing.T) {
|
func TestMarshal_String(t *testing.T) {
|
||||||
|
@ -44,8 +45,8 @@ func TestMarshal_Time(t *testing.T) {
|
||||||
|
|
||||||
func TestMarshal_Map(t *testing.T) {
|
func TestMarshal_Map(t *testing.T) {
|
||||||
m := dyn.NewMapping()
|
m := dyn.NewMapping()
|
||||||
m.Set(dyn.V("key1"), dyn.V("value1"))
|
require.NoError(t, m.Set(dyn.V("key1"), dyn.V("value1")))
|
||||||
m.Set(dyn.V("key2"), dyn.V("value2"))
|
require.NoError(t, m.Set(dyn.V("key2"), dyn.V("value2")))
|
||||||
|
|
||||||
b, err := Marshal(dyn.V(m))
|
b, err := Marshal(dyn.V(m))
|
||||||
if assert.NoError(t, err) {
|
if assert.NoError(t, err) {
|
||||||
|
@ -66,16 +67,16 @@ func TestMarshal_Sequence(t *testing.T) {
|
||||||
|
|
||||||
func TestMarshal_Complex(t *testing.T) {
|
func TestMarshal_Complex(t *testing.T) {
|
||||||
map1 := dyn.NewMapping()
|
map1 := dyn.NewMapping()
|
||||||
map1.Set(dyn.V("str1"), dyn.V("value1"))
|
require.NoError(t, map1.Set(dyn.V("str1"), dyn.V("value1")))
|
||||||
map1.Set(dyn.V("str2"), dyn.V("value2"))
|
require.NoError(t, map1.Set(dyn.V("str2"), dyn.V("value2")))
|
||||||
|
|
||||||
seq1 := []dyn.Value{}
|
seq1 := []dyn.Value{}
|
||||||
seq1 = append(seq1, dyn.V("value1"))
|
seq1 = append(seq1, dyn.V("value1"))
|
||||||
seq1 = append(seq1, dyn.V("value2"))
|
seq1 = append(seq1, dyn.V("value2"))
|
||||||
|
|
||||||
root := dyn.NewMapping()
|
root := dyn.NewMapping()
|
||||||
root.Set(dyn.V("map1"), dyn.V(map1))
|
require.NoError(t, root.Set(dyn.V("map1"), dyn.V(map1)))
|
||||||
root.Set(dyn.V("seq1"), dyn.V(seq1))
|
require.NoError(t, root.Set(dyn.V("seq1"), dyn.V(seq1)))
|
||||||
|
|
||||||
// Marshal without indent.
|
// Marshal without indent.
|
||||||
b, err := Marshal(dyn.V(root))
|
b, err := Marshal(dyn.V(root))
|
||||||
|
|
|
@ -432,10 +432,12 @@ func TestOverride_PreserveMappingKeys(t *testing.T) {
|
||||||
rightValueLocation := dyn.Location{File: "right.yml", Line: 3, Column: 1}
|
rightValueLocation := dyn.Location{File: "right.yml", Line: 3, Column: 1}
|
||||||
|
|
||||||
left := dyn.NewMapping()
|
left := dyn.NewMapping()
|
||||||
left.Set(dyn.NewValue("a", []dyn.Location{leftKeyLocation}), dyn.NewValue(42, []dyn.Location{leftValueLocation}))
|
err := left.Set(dyn.NewValue("a", []dyn.Location{leftKeyLocation}), dyn.NewValue(42, []dyn.Location{leftValueLocation}))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
right := dyn.NewMapping()
|
right := dyn.NewMapping()
|
||||||
right.Set(dyn.NewValue("a", []dyn.Location{rightKeyLocation}), dyn.NewValue(7, []dyn.Location{rightValueLocation}))
|
err = right.Set(dyn.NewValue("a", []dyn.Location{rightKeyLocation}), dyn.NewValue(7, []dyn.Location{rightValueLocation}))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
state, visitor := createVisitor(visitorOpts{})
|
state, visitor := createVisitor(visitorOpts{})
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExecutorWithSimpleInput(t *testing.T) {
|
func TestExecutorWithSimpleInput(t *testing.T) {
|
||||||
|
@ -86,9 +87,11 @@ func testExecutorWithShell(t *testing.T, shell string) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
t.Setenv("PATH", tmpDir)
|
t.Setenv("PATH", tmpDir)
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
os.Symlink(p, fmt.Sprintf("%s/%s.exe", tmpDir, shell))
|
err = os.Symlink(p, fmt.Sprintf("%s/%s.exe", tmpDir, shell))
|
||||||
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
os.Symlink(p, fmt.Sprintf("%s/%s", tmpDir, shell))
|
err = os.Symlink(p, fmt.Sprintf("%s/%s", tmpDir, shell))
|
||||||
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
executor, err := NewCommandExecutor(".")
|
executor, err := NewCommandExecutor(".")
|
||||||
|
|
|
@ -62,7 +62,8 @@ func TestJsonFlagFile(t *testing.T) {
|
||||||
{
|
{
|
||||||
f, err := os.Create(path.Join(t.TempDir(), "file"))
|
f, err := os.Create(path.Join(t.TempDir(), "file"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
f.Write(payload)
|
_, err = f.Write(payload)
|
||||||
|
require.NoError(t, err)
|
||||||
f.Close()
|
f.Close()
|
||||||
fpath = f.Name()
|
fpath = f.Name()
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,8 @@ func TestFileSetAddsCacheDirToGitIgnore(t *testing.T) {
|
||||||
projectDir := t.TempDir()
|
projectDir := t.TempDir()
|
||||||
fileSet, err := NewFileSetAtRoot(vfs.MustNew(projectDir))
|
fileSet, err := NewFileSetAtRoot(vfs.MustNew(projectDir))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fileSet.EnsureValidGitIgnoreExists()
|
err = fileSet.EnsureValidGitIgnoreExists()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
gitIgnorePath := filepath.Join(projectDir, ".gitignore")
|
gitIgnorePath := filepath.Join(projectDir, ".gitignore")
|
||||||
assert.FileExists(t, gitIgnorePath)
|
assert.FileExists(t, gitIgnorePath)
|
||||||
|
@ -74,7 +75,8 @@ func TestFileSetDoesNotCacheDirToGitIgnoreIfAlreadyPresent(t *testing.T) {
|
||||||
err = os.WriteFile(gitIgnorePath, []byte(".databricks"), 0o644)
|
err = os.WriteFile(gitIgnorePath, []byte(".databricks"), 0o644)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fileSet.EnsureValidGitIgnoreExists()
|
err = fileSet.EnsureValidGitIgnoreExists()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
b, err := os.ReadFile(gitIgnorePath)
|
b, err := os.ReadFile(gitIgnorePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -54,7 +54,8 @@ func TestReferenceLoadingForObjectID(t *testing.T) {
|
||||||
f, err := os.Create(filepath.Join(tmp, "HEAD"))
|
f, err := os.Create(filepath.Join(tmp, "HEAD"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString(strings.Repeat("e", 40) + "\r\n")
|
_, err = f.WriteString(strings.Repeat("e", 40) + "\r\n")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ref, err := LoadReferenceFile(vfs.MustNew(tmp), "HEAD")
|
ref, err := LoadReferenceFile(vfs.MustNew(tmp), "HEAD")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -67,7 +68,8 @@ func TestReferenceLoadingForReference(t *testing.T) {
|
||||||
f, err := os.OpenFile(filepath.Join(tmp, "HEAD"), os.O_CREATE|os.O_WRONLY, os.ModePerm)
|
f, err := os.OpenFile(filepath.Join(tmp, "HEAD"), os.O_CREATE|os.O_WRONLY, os.ModePerm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString("ref: refs/heads/foo\n")
|
_, err = f.WriteString("ref: refs/heads/foo\n")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ref, err := LoadReferenceFile(vfs.MustNew(tmp), "HEAD")
|
ref, err := LoadReferenceFile(vfs.MustNew(tmp), "HEAD")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -80,7 +82,8 @@ func TestReferenceLoadingFailsForInvalidContent(t *testing.T) {
|
||||||
f, err := os.OpenFile(filepath.Join(tmp, "HEAD"), os.O_CREATE|os.O_WRONLY, os.ModePerm)
|
f, err := os.OpenFile(filepath.Join(tmp, "HEAD"), os.O_CREATE|os.O_WRONLY, os.ModePerm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString("abc")
|
_, err = f.WriteString("abc")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = LoadReferenceFile(vfs.MustNew(tmp), "HEAD")
|
_, err = LoadReferenceFile(vfs.MustNew(tmp), "HEAD")
|
||||||
assert.ErrorContains(t, err, "unknown format for git HEAD")
|
assert.ErrorContains(t, err, "unknown format for git HEAD")
|
||||||
|
|
|
@ -27,7 +27,7 @@ func newTestRepository(t *testing.T) *testRepository {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer f1.Close()
|
defer f1.Close()
|
||||||
|
|
||||||
f1.WriteString(
|
_, err = f1.WriteString(
|
||||||
`[core]
|
`[core]
|
||||||
repositoryformatversion = 0
|
repositoryformatversion = 0
|
||||||
filemode = true
|
filemode = true
|
||||||
|
@ -36,6 +36,7 @@ func newTestRepository(t *testing.T) *testRepository {
|
||||||
ignorecase = true
|
ignorecase = true
|
||||||
precomposeunicode = true
|
precomposeunicode = true
|
||||||
`)
|
`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
f2, err := os.Create(filepath.Join(tmp, ".git", "HEAD"))
|
f2, err := os.Create(filepath.Join(tmp, ".git", "HEAD"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -403,7 +403,8 @@ func TestFromTypeError(t *testing.T) {
|
||||||
// Maps with non-string keys should panic.
|
// Maps with non-string keys should panic.
|
||||||
type mapOfInts map[int]int
|
type mapOfInts map[int]int
|
||||||
assert.PanicsWithValue(t, "found map with non-string key: int", func() {
|
assert.PanicsWithValue(t, "found map with non-string key: int", func() {
|
||||||
FromType(reflect.TypeOf(mapOfInts{}), nil)
|
_, err := FromType(reflect.TypeOf(mapOfInts{}), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Unsupported types should return an error.
|
// Unsupported types should return an error.
|
||||||
|
|
|
@ -43,8 +43,14 @@ func TestStubCallback(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx, stub := process.WithStub(ctx)
|
ctx, stub := process.WithStub(ctx)
|
||||||
stub.WithCallback(func(cmd *exec.Cmd) error {
|
stub.WithCallback(func(cmd *exec.Cmd) error {
|
||||||
cmd.Stderr.Write([]byte("something..."))
|
_, err := cmd.Stderr.Write([]byte("something..."))
|
||||||
cmd.Stdout.Write([]byte("else..."))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = cmd.Stdout.Write([]byte("else..."))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return fmt.Errorf("yep")
|
return fmt.Errorf("yep")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ func TestFilteringInterpreters(t *testing.T) {
|
||||||
rogueBin := filepath.Join(t.TempDir(), "rogue-bin")
|
rogueBin := filepath.Join(t.TempDir(), "rogue-bin")
|
||||||
err := os.Mkdir(rogueBin, 0o777)
|
err := os.Mkdir(rogueBin, 0o777)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
os.Chmod(rogueBin, 0o777)
|
err = os.Chmod(rogueBin, 0o777)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
raw, err := os.ReadFile("testdata/world-writeable/python8.4")
|
raw, err := os.ReadFile("testdata/world-writeable/python8.4")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue