From 1be5a650fc60fe30e2c09fd6948492e1619b1c16 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 12 Aug 2016 15:01:25 -0400 Subject: [PATCH] Add test for showing an empty state Make sure we don't panic if there's no state to print --- command/state_show_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/command/state_show_test.go b/command/state_show_test.go index 1e2dba08c..cbcfb46d8 100644 --- a/command/state_show_test.go +++ b/command/state_show_test.go @@ -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 = ` id = bar bar = value