command: compiles, tests don't pass yet

This commit is contained in:
Mitchell Hashimoto 2014-09-24 14:37:24 -07:00
parent 9ba39d93b7
commit 672bf58337
5 changed files with 41 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -80,11 +80,13 @@ 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 {
for _, r := range m.Resources {
if !r.Destroy { if !r.Destroy {
t.Fatalf("bad: %#v", r) t.Fatalf("bad: %#v", r)
} }
} }
}
f, err := os.Open(statePath + DefaultBackupExtention) f, err := os.Open(statePath + DefaultBackupExtention)
if err != nil { if err != nil {

View File

@ -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 {

View File

@ -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() {