From 5b541057e5e051992c8bb50e8642cb5ade1b16aa Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 8 Jun 2023 16:37:48 +0200 Subject: [PATCH] Check for nil environment before accessing it --- bundle/config/root.go | 3 +++ bundle/tests/environment_empty/bundle.yml | 5 +++++ bundle/tests/environment_empty_test.go | 12 ++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 bundle/tests/environment_empty/bundle.yml create mode 100644 bundle/tests/environment_empty_test.go diff --git a/bundle/config/root.go b/bundle/config/root.go index b92d85bbf1..28333e988a 100644 --- a/bundle/config/root.go +++ b/bundle/config/root.go @@ -78,6 +78,9 @@ func (r *Root) SetConfigFilePath(path string) { r.Resources.SetConfigFilePath(path) if r.Environments != nil { for _, env := range r.Environments { + if env == nil { + continue + } if env.Resources != nil { env.Resources.SetConfigFilePath(path) } diff --git a/bundle/tests/environment_empty/bundle.yml b/bundle/tests/environment_empty/bundle.yml new file mode 100644 index 0000000000..17c03c8dcb --- /dev/null +++ b/bundle/tests/environment_empty/bundle.yml @@ -0,0 +1,5 @@ +bundle: + name: environment_empty + +environments: + development: diff --git a/bundle/tests/environment_empty_test.go b/bundle/tests/environment_empty_test.go new file mode 100644 index 0000000000..fb2e334166 --- /dev/null +++ b/bundle/tests/environment_empty_test.go @@ -0,0 +1,12 @@ +package config_tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestEnvironmentEmpty(t *testing.T) { + b := loadEnvironment(t, "./environment_empty", "development") + assert.Equal(t, "development", b.Config.Bundle.Environment) +}