Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit 6e764ad

Browse files
committed
Instantiate empty config map in GetConfig() if necessary
This is for convenience so that callers modifying a manifest's config do not need to check if it is nil before doing so
1 parent 2406a71 commit 6e764ad

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/pods/manifest.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ func (manifest *manifest) SetLaunchables(launchableStanzas map[string]Launchable
125125
}
126126

127127
func (manifest *manifest) GetConfig() map[interface{}]interface{} {
128+
if manifest.Config == nil {
129+
return make(map[interface{}]interface{})
130+
}
128131
return manifest.Config
129132
}
130133

pkg/pods/manifest_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,10 @@ config:
223223
builtManifest := builder.GetManifest()
224224
Assert(t).AreEqual(builtManifest.ID(), "thepod", "Expected manifest ID to be preserved when converted to ManifestBuilder and back")
225225
}
226+
227+
func TestGetConfigInitializesIfEmpty(t *testing.T) {
228+
builder := NewManifestBuilder()
229+
manifest := builder.GetManifest()
230+
config := manifest.GetConfig()
231+
Assert(t).IsNotNil(config, "Expected returned config to be instantiated by GetConfig() if not set")
232+
}

0 commit comments

Comments
 (0)