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

View File

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

View File

@ -401,6 +401,6 @@ const testTerraformDiffComputedStr = `
aws_instance.bar
foo: "" => "<computed>"
aws_instance.foo
id: "" => "<computed>"
id: "" => "<computed>"
num: "" => "2"
`