github.com/sathiyas/terraform@v0.6.9-0.20151210233947-3330da00b997/command/graph_test.go (about) 1 package command 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 8 "github.com/hashicorp/terraform/terraform" 9 "github.com/mitchellh/cli" 10 ) 11 12 func TestGraph(t *testing.T) { 13 ui := new(cli.MockUi) 14 c := &GraphCommand{ 15 Meta: Meta{ 16 ContextOpts: testCtxConfig(testProvider()), 17 Ui: ui, 18 }, 19 } 20 21 args := []string{ 22 testFixturePath("graph"), 23 } 24 if code := c.Run(args); code != 0 { 25 t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) 26 } 27 28 output := ui.OutputWriter.String() 29 if !strings.Contains(output, "provider.test") { 30 t.Fatalf("doesn't look like digraph: %s", output) 31 } 32 } 33 34 func TestGraph_multipleArgs(t *testing.T) { 35 ui := new(cli.MockUi) 36 c := &GraphCommand{ 37 Meta: Meta{ 38 ContextOpts: testCtxConfig(testProvider()), 39 Ui: ui, 40 }, 41 } 42 43 args := []string{ 44 "bad", 45 "bad", 46 } 47 if code := c.Run(args); code != 1 { 48 t.Fatalf("bad: \n%s", ui.OutputWriter.String()) 49 } 50 } 51 52 func TestGraph_noArgs(t *testing.T) { 53 cwd, err := os.Getwd() 54 if err != nil { 55 t.Fatalf("err: %s", err) 56 } 57 if err := os.Chdir(testFixturePath("graph")); err != nil { 58 t.Fatalf("err: %s", err) 59 } 60 defer os.Chdir(cwd) 61 62 ui := new(cli.MockUi) 63 c := &GraphCommand{ 64 Meta: Meta{ 65 ContextOpts: testCtxConfig(testProvider()), 66 Ui: ui, 67 }, 68 } 69 70 args := []string{} 71 if code := c.Run(args); code != 0 { 72 t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) 73 } 74 75 output := ui.OutputWriter.String() 76 if !strings.Contains(output, "provider.test") { 77 t.Fatalf("doesn't look like digraph: %s", output) 78 } 79 } 80 81 func TestGraph_plan(t *testing.T) { 82 planPath := testPlanFile(t, &terraform.Plan{ 83 Module: testModule(t, "graph"), 84 }) 85 86 ui := new(cli.MockUi) 87 c := &GraphCommand{ 88 Meta: Meta{ 89 ContextOpts: testCtxConfig(testProvider()), 90 Ui: ui, 91 }, 92 } 93 94 args := []string{ 95 planPath, 96 } 97 if code := c.Run(args); code != 0 { 98 t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) 99 } 100 101 output := ui.OutputWriter.String() 102 if !strings.Contains(output, "provider.test") { 103 t.Fatalf("doesn't look like digraph: %s", output) 104 } 105 }