command/graph: can graph plans

This commit is contained in:
Mitchell Hashimoto 2014-07-12 19:25:50 -07:00
parent 4dea4c325b
commit 8e100869a4
2 changed files with 29 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import (
"os"
"strings"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/digraph"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
@ -43,16 +42,13 @@ func (c *GraphCommand) Run(args []string) int {
}
}
conf, err := config.LoadDir(path)
ctx, err := ContextArg(path, "", c.ContextOpts)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error loading config: %s", err))
c.Ui.Error(fmt.Sprintf("Error loading Terraform: %s", err))
return 1
}
g, err := terraform.Graph(&terraform.GraphOpts{
Config: conf,
Providers: c.ContextOpts.Providers,
})
g, err := ctx.Graph()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error creating graph: %s", err))
return 1

View File

@ -5,6 +5,8 @@ import (
"strings"
"testing"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
)
@ -70,3 +72,27 @@ func TestGraph_noArgs(t *testing.T) {
t.Fatalf("doesn't look like digraph: %s", output)
}
}
func TestGraph_plan(t *testing.T) {
planPath := testPlanFile(t, &terraform.Plan{
Config: new(config.Config),
})
ui := new(cli.MockUi)
c := &GraphCommand{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
}
args := []string{
planPath,
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
output := ui.OutputWriter.String()
if !strings.Contains(output, "digraph {") {
t.Fatalf("doesn't look like digraph: %s", output)
}
}