2022-11-18 09:57:31 +00:00
|
|
|
package mutator_test
|
|
|
|
|
|
|
|
import (
|
2022-11-28 09:59:43 +00:00
|
|
|
"context"
|
2022-11-18 09:57:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/databricks/cli/bundle/config/mutator"
|
2022-11-18 09:57:31 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-08-17 15:22:32 +00:00
|
|
|
func TestSelectTarget(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2022-11-28 09:59:43 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Workspace: config.Workspace{
|
|
|
|
Host: "foo",
|
|
|
|
},
|
2023-08-17 15:22:32 +00:00
|
|
|
Targets: map[string]*config.Target{
|
2022-11-28 09:59:43 +00:00
|
|
|
"default": {
|
|
|
|
Workspace: &config.Workspace{
|
|
|
|
Host: "bar",
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, mutator.SelectTarget("default"))
|
|
|
|
require.NoError(t, diags.Error())
|
2023-11-15 14:03:36 +00:00
|
|
|
assert.Equal(t, "bar", b.Config.Workspace.Host)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 15:22:32 +00:00
|
|
|
func TestSelectTargetNotFound(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2022-11-28 09:59:43 +00:00
|
|
|
Config: config.Root{
|
2023-08-17 15:22:32 +00:00
|
|
|
Targets: map[string]*config.Target{
|
2022-11-28 09:59:43 +00:00
|
|
|
"default": {},
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, mutator.SelectTarget("doesnt-exist"))
|
|
|
|
require.Error(t, diags.Error(), "no targets defined")
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|