Skip to content

Commit

Permalink
Backport #550
Browse files Browse the repository at this point in the history
Fixed import state testing to be able to return an error that
TestStep.ExpectError can handle.
  • Loading branch information
paddycarver committed Sep 3, 2020
1 parent 44c4e42 commit a6e7904
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions helper/resource/testing_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,17 @@ func RunNewTest(t *testing.T, c TestCase, providers map[string]terraform.Resourc
if step.ImportState {
step.providers = providers
err := testStepNewImportState(t, c, wd, step, appliedCfg)
if err != nil {
t.Fatal(err)
if step.ExpectError != nil {
if err == nil {
t.Fatalf("Step %d/%d error running import: expected an error but got none", i+1, len(c.Steps))
}
if !step.ExpectError.MatchString(err.Error()) {
t.Fatalf("Step %d/%d error running import, expected an error with pattern (%s), no match on: %s", i+1, len(c.Steps), step.ExpectError.String(), err)
}
} else {
if err != nil {
t.Fatalf("Step %d/%d error running import: %s", i+1, len(c.Steps), err)
}
}
continue
}
Expand Down
2 changes: 1 addition & 1 deletion helper/resource/testing_new_import_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func testStepNewImportState(t *testing.T, c TestCase, wd *tftest.WorkingDir, ste
return importWd.Import(step.ResourceName, importId)
}, wd, c.ProviderFactories)
if err != nil {
return fmt.Errorf("Error running import: %v", err)
return err
}

var importState *terraform.State
Expand Down

0 comments on commit a6e7904

Please sign in to comment.