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.
|
||||
var defaults []string
|
||||
for _, name := range names {
|
||||
if b.Config.Environments[name].Default {
|
||||
for name, env := range b.Config.Environments {
|
||||
if env != nil && env.Default {
|
||||
defaults = append(defaults, name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,19 @@ func TestSelectDefaultEnvironmentNoDefaults(t *testing.T) {
|
|||
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) {
|
||||
bundle := &bundle.Bundle{
|
||||
Config: config.Root{
|
||||
|
|
|
@ -87,6 +87,11 @@ func (r *Root) Merge(other *Root) error {
|
|||
func (r *Root) MergeEnvironment(env *Environment) error {
|
||||
var err error
|
||||
|
||||
// Environment may be nil if it's empty.
|
||||
if env == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if env.Bundle != nil {
|
||||
err = mergo.MergeWithOverwrite(&r.Bundle, env.Bundle)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue