command: compiles, tests don't pass yet
This commit is contained in:
parent
9ba39d93b7
commit
672bf58337
|
@ -27,15 +27,15 @@ func FormatPlan(p *terraform.Plan, c *colorstring.Colorize) string {
|
||||||
|
|
||||||
// We want to output the resources in sorted order to make things
|
// We want to output the resources in sorted order to make things
|
||||||
// easier to scan through, so get all the resource names and sort them.
|
// easier to scan through, so get all the resource names and sort them.
|
||||||
names := make([]string, 0, len(p.Diff.Resources))
|
names := make([]string, 0, len(p.Diff.RootModule().Resources))
|
||||||
for name, _ := range p.Diff.Resources {
|
for name, _ := range p.Diff.RootModule().Resources {
|
||||||
names = append(names, name)
|
names = append(names, name)
|
||||||
}
|
}
|
||||||
sort.Strings(names)
|
sort.Strings(names)
|
||||||
|
|
||||||
// Go through each sorted name and start building the output
|
// Go through each sorted name and start building the output
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
rdiff := p.Diff.Resources[name]
|
rdiff := p.Diff.RootModule().Resources[name]
|
||||||
|
|
||||||
// Determine the color for the text (green for adding, yellow
|
// Determine the color for the text (green for adding, yellow
|
||||||
// for change, red for delete), and symbol, and output the
|
// for change, red for delete), and symbol, and output the
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (m *Meta) Context(copts contextOpts) (*terraform.Context, bool, error) {
|
||||||
return nil, false, fmt.Errorf("Error downloading modules: %s", err)
|
return nil, false, fmt.Errorf("Error downloading modules: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Config = mod.Config()
|
opts.Module = mod
|
||||||
opts.State = state
|
opts.State = state
|
||||||
ctx := terraform.NewContext(opts)
|
ctx := terraform.NewContext(opts)
|
||||||
return ctx, false, nil
|
return ctx, false, nil
|
||||||
|
|
|
@ -80,9 +80,11 @@ func TestPlan_destroy(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
plan := testReadPlan(t, outPath)
|
plan := testReadPlan(t, outPath)
|
||||||
for _, r := range plan.Diff.Resources {
|
for _, m := range plan.Diff.Modules {
|
||||||
if !r.Destroy {
|
for _, r := range m.Resources {
|
||||||
t.Fatalf("bad: %#v", r)
|
if !r.Destroy {
|
||||||
|
t.Fatalf("bad: %#v", r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,17 @@ func (d *Diff) RootModule() *ModuleDiff {
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty returns true if the diff has no changes.
|
||||||
|
func (d *Diff) Empty() bool {
|
||||||
|
for _, m := range d.Modules {
|
||||||
|
if !m.Empty() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Diff) String() string {
|
func (d *Diff) String() string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
for _, m := range d.Modules {
|
for _, m := range d.Modules {
|
||||||
|
|
|
@ -5,6 +5,27 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestDiffEmpty(t *testing.T) {
|
||||||
|
diff := new(Diff)
|
||||||
|
if !diff.Empty() {
|
||||||
|
t.Fatal("should be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
mod := diff.AddModule(rootModulePath)
|
||||||
|
mod.Resources["nodeA"] = &InstanceDiff{
|
||||||
|
Attributes: map[string]*ResourceAttrDiff{
|
||||||
|
"foo": &ResourceAttrDiff{
|
||||||
|
Old: "foo",
|
||||||
|
New: "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff.Empty() {
|
||||||
|
t.Fatal("should not be empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestModuleDiff_Empty(t *testing.T) {
|
func TestModuleDiff_Empty(t *testing.T) {
|
||||||
diff := new(ModuleDiff)
|
diff := new(ModuleDiff)
|
||||||
if !diff.Empty() {
|
if !diff.Empty() {
|
||||||
|
|
Loading…
Reference in New Issue