mirror of https://github.com/databricks/cli.git
Handle nil environment (#154)
This commit is contained in:
parent
198eefcf39
commit
61ef0ba8c6
|
@ -33,8 +33,8 @@ func (m *selectDefaultEnvironment) Apply(_ context.Context, b *bundle.Bundle) ([
|
||||||
|
|
||||||
// Multiple environments means we look for the `default` flag.
|
// Multiple environments means we look for the `default` flag.
|
||||||
var defaults []string
|
var defaults []string
|
||||||
for _, name := range names {
|
for name, env := range b.Config.Environments {
|
||||||
if b.Config.Environments[name].Default {
|
if env != nil && env.Default {
|
||||||
defaults = append(defaults, name)
|
defaults = append(defaults, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,19 @@ func TestSelectDefaultEnvironmentNoDefaults(t *testing.T) {
|
||||||
assert.ErrorContains(t, err, "please specify environment")
|
assert.ErrorContains(t, err, "please specify environment")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSelectDefaultEnvironmentNoDefaultsWithNil(t *testing.T) {
|
||||||
|
bundle := &bundle.Bundle{
|
||||||
|
Config: config.Root{
|
||||||
|
Environments: map[string]*config.Environment{
|
||||||
|
"foo": nil,
|
||||||
|
"bar": nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := mutator.SelectDefaultEnvironment().Apply(context.Background(), bundle)
|
||||||
|
assert.ErrorContains(t, err, "please specify environment")
|
||||||
|
}
|
||||||
|
|
||||||
func TestSelectDefaultEnvironmentMultipleDefaults(t *testing.T) {
|
func TestSelectDefaultEnvironmentMultipleDefaults(t *testing.T) {
|
||||||
bundle := &bundle.Bundle{
|
bundle := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
|
|
|
@ -87,6 +87,11 @@ func (r *Root) Merge(other *Root) error {
|
||||||
func (r *Root) MergeEnvironment(env *Environment) error {
|
func (r *Root) MergeEnvironment(env *Environment) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// Environment may be nil if it's empty.
|
||||||
|
if env == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if env.Bundle != nil {
|
if env.Bundle != nil {
|
||||||
err = mergo.MergeWithOverwrite(&r.Bundle, env.Bundle)
|
err = mergo.MergeWithOverwrite(&r.Bundle, env.Bundle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue