terraform: match key lengths up in a diff
This commit is contained in:
parent
36a99b5920
commit
fac68b0c09
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ func TestDiff_String(t *testing.T) {
|
|||
Old: "foo",
|
||||
NewComputed: true,
|
||||
},
|
||||
"longfoo": &ResourceAttrDiff{
|
||||
Old: "foo",
|
||||
New: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -34,4 +38,5 @@ const diffStrBasic = `
|
|||
nodeA
|
||||
bar: "foo" => "<computed>"
|
||||
foo: "foo" => "bar"
|
||||
longfoo: "foo" => "bar"
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue