From db3ea65e8b122c0bbb76b613faa7f42704c8c74d Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sun, 30 Sep 2018 08:20:32 -0700 Subject: [PATCH] command: Fix TestApply_destroy for new provider and state types --- command/apply_destroy_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/command/apply_destroy_test.go b/command/apply_destroy_test.go index dad38a63b8..c17540fe00 100644 --- a/command/apply_destroy_test.go +++ b/command/apply_destroy_test.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/states" + "github.com/hashicorp/terraform/states/statefile" "github.com/hashicorp/terraform/terraform" ) @@ -32,7 +33,16 @@ func TestApply_destroy(t *testing.T) { statePath := testStateFile(t, originalState) p := testProvider() - p.GetSchemaReturn = applyFixtureSchema() + p.GetSchemaReturn = &terraform.ProviderSchema{ + ResourceTypes: map[string]*configschema.Block{ + "test_instance": { + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, + }, + }, + } ui := new(cli.MockUi) c := &ApplyCommand{ @@ -65,15 +75,15 @@ func TestApply_destroy(t *testing.T) { } defer f.Close() - state, err := terraform.ReadState(f) + stateFile, err := statefile.Read(f) if err != nil { t.Fatalf("err: %s", err) } - if state == nil { + if stateFile.State == nil { t.Fatal("state should not be nil") } - actualStr := strings.TrimSpace(state.String()) + actualStr := strings.TrimSpace(stateFile.State.String()) expectedStr := strings.TrimSpace(testApplyDestroyStr) if actualStr != expectedStr { t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr) @@ -85,13 +95,13 @@ func TestApply_destroy(t *testing.T) { t.Fatalf("err: %s", err) } - backupState, err := terraform.ReadState(f) + backupStateFile, err := statefile.Read(f) f.Close() if err != nil { t.Fatalf("err: %s", err) } - actualStr = strings.TrimSpace(backupState.String()) + actualStr = strings.TrimSpace(backupStateFile.State.String()) expectedStr = strings.TrimSpace(originalState.String()) if actualStr != expectedStr { t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)