command/output: protect againts blank params

This commit is contained in:
Mitchell Hashimoto 2014-07-13 10:29:31 -07:00
parent 2caff709d6
commit 3f803cb75c
2 changed files with 27 additions and 1 deletions

View File

@ -28,7 +28,7 @@ func (c *OutputCommand) Run(args []string) int {
}
args = cmdFlags.Args()
if len(args) != 1 {
if len(args) != 1 || args[0] == "" {
c.Ui.Error(
"The output command expects exactly one argument with the name\n" +
"of an output variable.\n")

View File

@ -68,6 +68,32 @@ func TestOutput_badVar(t *testing.T) {
}
}
func TestOutput_blank(t *testing.T) {
originalState := &terraform.State{
Outputs: map[string]string{
"foo": "bar",
},
}
statePath := testStateFile(t, originalState)
ui := new(cli.MockUi)
c := &OutputCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
}
args := []string{
"-state", statePath,
"",
}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}
func TestOutput_manyArgs(t *testing.T) {
ui := new(cli.MockUi)
c := &OutputCommand{