Merge pull request #162 from jonboulle/fffffffffffffffffff

initialize/env: handle nil substitution maps properly
This commit is contained in:
Jonathan Boulle 2014-06-25 12:10:00 -07:00
commit f85eafb7ca
2 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,9 @@ type Environment struct {
// TODO(jonboulle): this is getting unwieldy, should be able to simplify the interface somehow // 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 { 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 // If certain values are not in the supplied substitution, fall back to retrieving them from the environment
for k, v := range map[string]string{ for k, v := range map[string]string{
"$public_ipv4": os.Getenv("COREOS_PUBLIC_IPV4"), "$public_ipv4": os.Getenv("COREOS_PUBLIC_IPV4"),

View File

@ -41,6 +41,12 @@ ExecStop=/usr/bin/echo $unknown`,
"$private_ipv4\n$public_ipv4", "$private_ipv4\n$public_ipv4",
"5.6.7.8\n1.2.3.4", "5.6.7.8\n1.2.3.4",
}, },
{
// No substitutions
nil,
"$private_ipv4\nfoobar",
"5.6.7.8\nfoobar",
},
} { } {
env := NewEnvironment("./", "./", "./", "", "", tt.subs) env := NewEnvironment("./", "./", "./", "", "", tt.subs)