diff --git a/command/state_list_test.go b/command/state_list_test.go index 0edb97d69..86c4f7194 100644 --- a/command/state_list_test.go +++ b/command/state_list_test.go @@ -1,9 +1,11 @@ package command import ( + "os" "strings" "testing" + "github.com/hashicorp/terraform/helper/copy" "github.com/mitchellh/cli" ) @@ -35,6 +37,35 @@ func TestStateList(t *testing.T) { } } +func TestStateList_backendState(t *testing.T) { + // Create a temporary working directory that is empty + td := tempDir(t) + copy.CopyDir(testFixturePath("state-list-backend"), td) + defer os.RemoveAll(td) + defer testChdir(t, td)() + + p := testProvider() + ui := new(cli.MockUi) + c := &StateListCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(p), + Ui: ui, + }, + } + + args := []string{} + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + // Test that outputs were displayed + expected := "null_resource.a\n" + actual := ui.OutputWriter.String() + if actual != expected { + t.Fatalf("Expected:\n%q\n\nTo equal: %q", actual, expected) + } +} + func TestStateList_noState(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) diff --git a/command/test-fixtures/state-list-backend/.terraform/terraform.tfstate b/command/test-fixtures/state-list-backend/.terraform/terraform.tfstate new file mode 100644 index 000000000..073bd7a82 --- /dev/null +++ b/command/test-fixtures/state-list-backend/.terraform/terraform.tfstate @@ -0,0 +1,22 @@ +{ + "version": 3, + "serial": 0, + "lineage": "666f9301-7e65-4b19-ae23-71184bb19b03", + "backend": { + "type": "local", + "config": { + "path": "local-state.tfstate" + }, + "hash": 9073424445967744180 + }, + "modules": [ + { + "path": [ + "root" + ], + "outputs": {}, + "resources": {}, + "depends_on": [] + } + ] +} diff --git a/command/test-fixtures/state-list-backend/local-state.tfstate b/command/test-fixtures/state-list-backend/local-state.tfstate new file mode 100644 index 000000000..fc10b3cc7 --- /dev/null +++ b/command/test-fixtures/state-list-backend/local-state.tfstate @@ -0,0 +1,31 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "configuredUnchanged", + "modules": [ + { + "path": [ + "root" + ], + "outputs": {}, + "resources": { + "null_resource.a": { + "type": "null_resource", + "depends_on": [], + "primary": { + "id": "5416263284413907707", + "attributes": { + "id": "5416263284413907707" + }, + "meta": {}, + "tainted": false + }, + "deposed": [], + "provider": "" + } + }, + "depends_on": [] + } + ] +} diff --git a/command/test-fixtures/state-list-backend/main.tf b/command/test-fixtures/state-list-backend/main.tf new file mode 100644 index 000000000..ca1bd3921 --- /dev/null +++ b/command/test-fixtures/state-list-backend/main.tf @@ -0,0 +1,5 @@ +terraform { + backend "local" { + path = "local-state.tfstate" + } +}