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 TestDefaultTarget(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{}
|
2023-11-15 14:19:18 +00:00
|
|
|
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultTarget())
|
2022-11-18 09:57:31 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-15 14:03:36 +00:00
|
|
|
env, ok := b.Config.Targets["default"]
|
2022-11-18 09:57:31 +00:00
|
|
|
assert.True(t, ok)
|
2023-08-17 15:22:32 +00:00
|
|
|
assert.Equal(t, &config.Target{}, env)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 15:22:32 +00:00
|
|
|
func TestDefaultTargetAlreadySpecified(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
|
|
|
"development": {},
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
2023-11-15 14:19:18 +00:00
|
|
|
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultTarget())
|
2022-11-18 09:57:31 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-15 14:03:36 +00:00
|
|
|
_, ok := b.Config.Targets["default"]
|
2022-11-18 09:57:31 +00:00
|
|
|
assert.False(t, ok)
|
|
|
|
}
|