Add test for showing an empty state

Make sure we don't panic if there's no state to print
This commit is contained in:
James Bardin 2016-08-12 15:01:25 -04:00
parent 191d7c1007
commit 1be5a650fc
1 changed files with 23 additions and 0 deletions

View File

@ -126,6 +126,29 @@ func TestStateShow_noState(t *testing.T) {
} }
} }
func TestStateShow_emptyState(t *testing.T) {
state := &terraform.State{}
statePath := testStateFile(t, state)
p := testProvider()
ui := new(cli.MockUi)
c := &StateShowCommand{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
args := []string{
"-state", statePath,
"test_instance.foo",
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
}
const testStateShowOutput = ` const testStateShowOutput = `
id = bar id = bar
bar = value bar = value