terraform: match key lengths up in a diff

This commit is contained in:
Mitchell Hashimoto 2014-06-10 11:30:54 -07:00
parent 36a99b5920
commit fac68b0c09
3 changed files with 15 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"sort" "sort"
"strings"
"sync" "sync"
) )
@ -37,9 +38,13 @@ func (d *Diff) String() string {
buf.WriteString(name + "\n") buf.WriteString(name + "\n")
keyLen := 0
keys := make([]string, 0, len(rdiff.Attributes)) keys := make([]string, 0, len(rdiff.Attributes))
for key, _ := range rdiff.Attributes { for key, _ := range rdiff.Attributes {
keys = append(keys, key) keys = append(keys, key)
if len(key) > keyLen {
keyLen = len(key)
}
} }
sort.Strings(keys) sort.Strings(keys)
@ -52,8 +57,9 @@ func (d *Diff) String() string {
} }
buf.WriteString(fmt.Sprintf( buf.WriteString(fmt.Sprintf(
" %s: %#v => %#v\n", " %s:%s %#v => %#v\n",
attrK, attrK,
strings.Repeat(" ", keyLen-len(attrK)),
attrDiff.Old, attrDiff.Old,
v)) v))
} }

View File

@ -18,6 +18,10 @@ func TestDiff_String(t *testing.T) {
Old: "foo", Old: "foo",
NewComputed: true, NewComputed: true,
}, },
"longfoo": &ResourceAttrDiff{
Old: "foo",
New: "bar",
},
}, },
}, },
}, },
@ -34,4 +38,5 @@ const diffStrBasic = `
nodeA nodeA
bar: "foo" => "<computed>" bar: "foo" => "<computed>"
foo: "foo" => "bar" foo: "foo" => "bar"
longfoo: "foo" => "bar"
` `