Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions helper/resource/testing_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
var statePreDestroy *terraform.State
var err error
err = runProviderCommand(ctx, t, func() error {
statePreDestroy, err = getState(ctx, t, wd)
_, statePreDestroy, err = getState(ctx, t, wd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtle difference to keep track of, good thing the IDE helps

if err != nil {
return err
}
Expand Down Expand Up @@ -447,18 +447,18 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
}
}

func getState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir) (*terraform.State, error) {
func getState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir) (*tfjson.State, *terraform.State, error) {
t.Helper()

jsonState, err := wd.State(ctx)
if err != nil {
return nil, err
return nil, nil, err
}
state, err := shimStateFromJson(jsonState)
if err != nil {
t.Fatal(err)
}
return state, nil
return jsonState, state, nil
}

func stateIsEmpty(state *terraform.State) bool {
Expand Down Expand Up @@ -573,7 +573,7 @@ func testIDRefresh(ctx context.Context, t testing.T, c TestCase, wd *plugintest.
if err != nil {
t.Fatalf("Error running terraform refresh: %s", err)
}
state, err = getState(ctx, t, wd)
_, state, err = getState(ctx, t, wd)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions helper/resource/testing_new_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
}

err = runProviderCommand(ctx, t, func() error {
stateBeforeApplication, err = getState(ctx, t, wd)
_, stateBeforeApplication, err = getState(ctx, t, wd)
if err != nil {
return err
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
var state *terraform.State

err := runProviderCommand(ctx, t, func() error {
state, err = getState(ctx, t, wd)
_, state, err = getState(ctx, t, wd)
if err != nil {
return err
}
Expand Down Expand Up @@ -384,7 +384,7 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
var state *terraform.State

err = runProviderCommand(ctx, t, func() error {
state, err = getState(ctx, t, wd)
_, state, err = getState(ctx, t, wd)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions helper/resource/testing_new_import_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest

// get state from check sequence
var state *terraform.State
var stateJSON *tfjson.State
var err error

err = runProviderCommand(ctx, t, func() error {
state, err = getState(ctx, t, wd)
stateJSON, state, err = getState(ctx, t, wd)
if err != nil {
return err
}
Expand All @@ -71,6 +72,9 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
t.Fatalf("Error getting state: %s", err)
}

// TODO: this statement is a placeholder -- it simply prevents stateJSON from being unused
logging.HelperResourceTrace(ctx, fmt.Sprintf("State before import: values %v", stateJSON.Values != nil))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should also use placeholders more


// Determine the ID to import
var importId string
switch {
Expand Down Expand Up @@ -230,7 +234,7 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest

var importState *terraform.State
err = runProviderCommand(ctx, t, func() error {
importState, err = getState(ctx, t, importWd)
_, importState, err = getState(ctx, t, importWd)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions helper/resource/testing_new_refresh_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func testStepNewRefreshState(ctx context.Context, t testing.T, wd *plugintest.Wo
var err error
// Explicitly ensure prior state exists before refresh.
err = runProviderCommand(ctx, t, func() error {
_, err = getState(ctx, t, wd)
_, _, err = getState(ctx, t, wd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of funny to look at

if err != nil {
return err
}
Expand All @@ -41,7 +41,7 @@ func testStepNewRefreshState(ctx context.Context, t testing.T, wd *plugintest.Wo

var refreshState *terraform.State
err = runProviderCommand(ctx, t, func() error {
refreshState, err = getState(ctx, t, wd)
_, refreshState, err = getState(ctx, t, wd)
if err != nil {
return err
}
Expand Down
Loading