From f0dba2294ed5617b9b4b7d9e57422bdf9a0a672c Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Wed, 25 Jun 2014 12:07:48 -0700 Subject: [PATCH] initialize/env: handle nil substitution maps properly --- initialize/env.go | 3 +++ initialize/env_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/initialize/env.go b/initialize/env.go index 4161898..2019c3e 100644 --- a/initialize/env.go +++ b/initialize/env.go @@ -19,6 +19,9 @@ type Environment struct { // TODO(jonboulle): this is getting unwieldy, should be able to simplify the interface somehow func NewEnvironment(root, configRoot, workspace, netconfType, sshKeyName string, substitutions map[string]string) *Environment { + if substitutions == nil { + substitutions = make(map[string]string) + } // If certain values are not in the supplied substitution, fall back to retrieving them from the environment for k, v := range map[string]string{ "$public_ipv4": os.Getenv("COREOS_PUBLIC_IPV4"), diff --git a/initialize/env_test.go b/initialize/env_test.go index 756c957..b48ae21 100644 --- a/initialize/env_test.go +++ b/initialize/env_test.go @@ -41,6 +41,12 @@ ExecStop=/usr/bin/echo $unknown`, "$private_ipv4\n$public_ipv4", "5.6.7.8\n1.2.3.4", }, + { + // No substitutions + nil, + "$private_ipv4\nfoobar", + "5.6.7.8\nfoobar", + }, } { env := NewEnvironment("./", "./", "./", "", "", tt.subs)