config: DefaultsMap should return nil if nil

This commit is contained in:
Mitchell Hashimoto 2014-07-22 08:10:06 -07:00
parent c9a20c3c58
commit fe2285898a
2 changed files with 9 additions and 1 deletions

View File

@ -283,8 +283,11 @@ func (r *Resource) mergerMerge(m merger) merger {
// DefaultsMap returns a map of default values for this variable. // DefaultsMap returns a map of default values for this variable.
func (v *Variable) DefaultsMap() map[string]string { func (v *Variable) DefaultsMap() map[string]string {
n := fmt.Sprintf("var.%s", v.Name) if v.Default == nil {
return nil
}
n := fmt.Sprintf("var.%s", v.Name)
switch v.Type() { switch v.Type() {
case VariableTypeString: case VariableTypeString:
return map[string]string{n: v.Default.(string)} return map[string]string{n: v.Default.(string)}

View File

@ -102,6 +102,11 @@ func TestVariableDefaultsMap(t *testing.T) {
Default interface{} Default interface{}
Output map[string]string Output map[string]string
}{ }{
{
nil,
nil,
},
{ {
"foo", "foo",
map[string]string{"var.foo": "foo"}, map[string]string{"var.foo": "foo"},