command/graph: no args means pwd
This commit is contained in:
parent
8f7244695f
commit
235a253848
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
|
@ -26,14 +27,21 @@ func (c *GraphCommand) Run(args []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
var path string
|
||||
args = cmdFlags.Args()
|
||||
if len(args) != 1 {
|
||||
if len(args) > 1 {
|
||||
c.Ui.Error("The graph command expects one argument.\n")
|
||||
cmdFlags.Usage()
|
||||
return 1
|
||||
} else if len(args) == 1 {
|
||||
path = args[0]
|
||||
} else {
|
||||
var err error
|
||||
path, err = os.Getwd()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error getting pwd: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
path := args[0]
|
||||
|
||||
conf, err := config.LoadDir(path)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -27,19 +28,6 @@ func TestGraph(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGraph_noArgs(t *testing.T) {
|
||||
ui := new(cli.MockUi)
|
||||
c := &ApplyCommand{
|
||||
ContextOpts: testCtxConfig(testProvider()),
|
||||
Ui: ui,
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
if code := c.Run(args); code != 1 {
|
||||
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraph_multipleArgs(t *testing.T) {
|
||||
ui := new(cli.MockUi)
|
||||
c := &ApplyCommand{
|
||||
|
@ -55,3 +43,30 @@ func TestGraph_multipleArgs(t *testing.T) {
|
|||
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraph_noArgs(t *testing.T) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if err := os.Chdir(testFixturePath("graph")); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Chdir(cwd)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &GraphCommand{
|
||||
ContextOpts: testCtxConfig(testProvider()),
|
||||
Ui: ui,
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue