Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph should not panic with no config #15588

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions command/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (c *GraphCommand) Run(args []string) int {
return 1
}

// Building a graph may require config module to be present, even if it's
// empty.
if mod == nil && plan == nil {
mod = module.NewEmptyTree()
}

// Build the operation
opReq := c.Operation()
opReq.Module = mod
Expand Down
22 changes: 22 additions & 0 deletions command/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ func TestGraph_noArgs(t *testing.T) {
}
}

func TestGraph_noConfig(t *testing.T) {
td := tempDir(t)
os.MkdirAll(td, 0755)
defer os.RemoveAll(td)
defer testChdir(t, td)()

ui := new(cli.MockUi)
c := &GraphCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
},
}

// Running the graph command without a config should not panic,
// but this may be an error at some point in the future.
args := []string{"-type", "apply"}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}

func TestGraph_plan(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
Expand Down