Skip to content

Commit

Permalink
helper/resource: Fixes for golangci-lint issues
Browse files Browse the repository at this point in the history
Previously:

```
func testStepNewImportState(ctx context.Context, t testing.T, c TestCase, helper *plugintest.Helper, wd *plugintest.WorkingDir, step TestStep, cfg string, providers *providerFactories) error {
                                                              ^
helper/resource/plugin.go:163:47: SA5011: possible nil pointer dereference (staticcheck)
	for providerName, factory := range factories.legacy {
	                                             ^
helper/resource/plugin.go:118:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
	if factories == nil {
	   ^
```
  • Loading branch information
bflad committed May 26, 2022
1 parent 83ac96b commit a8e255a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions helper/resource/plugin.go
Expand Up @@ -116,8 +116,9 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl

// This should not happen, but prevent panics just in case.
if factories == nil {
logging.HelperResourceError(ctx, "Provider factories are missing to run Terraform command. Please report this bug in the testing framework.")
t.Fatalf("Provider factories are missing to run Terraform command. Please report this bug in the testing framework.")
err := fmt.Errorf("Provider factories are missing to run Terraform command. Please report this bug in the testing framework.")
logging.HelperResourceError(ctx, err.Error())
return err
}

// Run the providers in the same process as the test runner using the
Expand Down
2 changes: 1 addition & 1 deletion helper/resource/testing_new.go
Expand Up @@ -193,7 +193,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
if step.ImportState {
logging.HelperResourceTrace(ctx, "TestStep is ImportState mode")

err := testStepNewImportState(ctx, t, c, helper, wd, step, appliedCfg, providers)
err := testStepNewImportState(ctx, t, helper, wd, step, appliedCfg, providers)
if step.ExpectError != nil {
logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError")
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion helper/resource/testing_new_import_state.go
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func testStepNewImportState(ctx context.Context, t testing.T, c TestCase, helper *plugintest.Helper, wd *plugintest.WorkingDir, step TestStep, cfg string, providers *providerFactories) error {
func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest.Helper, wd *plugintest.WorkingDir, step TestStep, cfg string, providers *providerFactories) error {
t.Helper()

spewConf := spew.NewDefaultConfig()
Expand Down

0 comments on commit a8e255a

Please sign in to comment.