mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 15:40:07 -06:00
terraform: Diff.Empty
This commit is contained in:
parent
23c8350ba4
commit
1449d8a510
@ -69,6 +69,21 @@ func (d *Diff) init() {
|
||||
})
|
||||
}
|
||||
|
||||
// Empty returns true if the diff has no changes.
|
||||
func (d *Diff) Empty() bool {
|
||||
if len(d.Resources) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, rd := range d.Resources {
|
||||
if len(rd.Attributes) > 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// String outputs the diff in a long but command-line friendly output
|
||||
// format that users can read to quickly inspect a diff.
|
||||
func (d *Diff) String() string {
|
||||
|
@ -7,6 +7,32 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDiff_Empty(t *testing.T) {
|
||||
diff := new(Diff)
|
||||
if !diff.Empty() {
|
||||
t.Fatal("should be empty")
|
||||
}
|
||||
|
||||
diff.Resources = map[string]*ResourceDiff{
|
||||
"nodeA": &ResourceDiff{},
|
||||
}
|
||||
|
||||
if !diff.Empty() {
|
||||
t.Fatal("should be empty")
|
||||
}
|
||||
|
||||
diff.Resources["nodeA"].Attributes = map[string]*ResourceAttrDiff{
|
||||
"foo": &ResourceAttrDiff{
|
||||
Old: "foo",
|
||||
New: "bar",
|
||||
},
|
||||
}
|
||||
|
||||
if diff.Empty() {
|
||||
t.Fatal("should not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiff_String(t *testing.T) {
|
||||
diff := &Diff{
|
||||
Resources: map[string]*ResourceDiff{
|
||||
|
Loading…
Reference in New Issue
Block a user